Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
JENKINS-26535 can be worked around using a collection of raw types.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Oct 26, 2015
1 parent f61ed78 commit b5302eb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Expand Up @@ -41,15 +41,16 @@
/**
* Resets the properties of the current job.
*/
@SuppressWarnings("rawtypes") // TODO JENKINS-26535: cannot bind List<JobProperty<?>>
public class JobPropertyStep extends AbstractStepImpl {

private final List<JobProperty<?>> properties;
private final List<JobProperty> properties;

@DataBoundConstructor public JobPropertyStep(List<JobProperty<?>> properties) {
@DataBoundConstructor public JobPropertyStep(List<JobProperty> properties) {
this.properties = properties;
}

public List<JobProperty<?>> getProperties() {
public List<JobProperty> getProperties() {
return properties;
}

Expand All @@ -58,7 +59,7 @@ public static class Execution extends AbstractSynchronousStepExecution<Void> {
@Inject transient JobPropertyStep step;
@StepContextParameter Run<?,?> build;

@SuppressWarnings({"unchecked", "rawtypes"}) // untypable
@SuppressWarnings("unchecked") // untypable
@Override protected Void run() throws Exception {
Job<?,?> job = build.getParent();
for (JobProperty prop : step.properties) {
Expand Down
Expand Up @@ -54,12 +54,13 @@ public class JobPropertyStepTest {
@Rule public JenkinsRule r = new JenkinsRule();
@Rule public GitSampleRepoRule sampleRepo = new GitSampleRepoRule();

@SuppressWarnings("rawtypes")
@Issue("JENKINS-30519")
@Test public void configRoundTrip() throws Exception {
StepConfigTester tester = new StepConfigTester(r);
// TODO fails (returns null)
assertEquals(Collections.emptyList(), tester.configRoundTrip(new JobPropertyStep(Collections.<JobProperty<?>>emptyList())).getProperties());
List<JobProperty<?>> properties = tester.configRoundTrip(new JobPropertyStep(Collections.<JobProperty<?>>singletonList(new ParametersDefinitionProperty(new BooleanParameterDefinition("flag", true, null))))).getProperties();
assertEquals(Collections.emptyList(), tester.configRoundTrip(new JobPropertyStep(Collections.<JobProperty>emptyList())).getProperties());
List<JobProperty> properties = tester.configRoundTrip(new JobPropertyStep(Collections.<JobProperty>singletonList(new ParametersDefinitionProperty(new BooleanParameterDefinition("flag", true, null))))).getProperties();
assertEquals(1, properties.size());
assertEquals(ParametersDefinitionProperty.class, properties.get(0));
ParametersDefinitionProperty pdp = (ParametersDefinitionProperty) properties.get(0);
Expand Down Expand Up @@ -87,7 +88,6 @@ public class JobPropertyStepTest {
r.waitUntilNoActivity();
WorkflowRun b1 = p.getLastBuild();
assertEquals(1, b1.getNumber());
// TODO fails due to JENKINS-28510
r.assertLogContains("received default value", b1);
WorkflowRun b2 = r.assertBuildStatusSuccess(p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("myparam", "special value"))));
assertEquals(2, b2.getNumber());
Expand Down
Expand Up @@ -219,7 +219,7 @@ private static Object coerce(String context, Type type, @Nonnull Object o) throw
Jenkins j = Jenkins.getInstance();
ClassLoader loader = j != null ? j.getPluginManager().uberClassLoader : DescribableHelper.class.getClassLoader();
clazz = loader.loadClass(clazzS);
} else {
} else if (type instanceof Class) {
clazz = null;
for (Class<?> c : findSubtypes((Class<?>) type)) {
if (c.getSimpleName().equals(clazzS)) {
Expand All @@ -232,6 +232,8 @@ private static Object coerce(String context, Type type, @Nonnull Object o) throw
if (clazz == null) {
throw new UnsupportedOperationException("no known implementation of " + type + " is named " + clazzS);
}
} else {
throw new UnsupportedOperationException("JENKINS-26535: do not know how to handle " + type);
}
return instantiate(clazz.asSubclass((Class<?>) type), m);
} else if (o instanceof String && type instanceof Class && ((Class) type).isEnum()) {
Expand Down

0 comments on commit b5302eb

Please sign in to comment.