Skip to content

Commit

Permalink
[FIXED JENKINS-34464] Enable DescribableModel binding for Result
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed May 22, 2017
1 parent 95e4f3c commit 1c8a50c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
Expand Up @@ -9,6 +9,7 @@
import hudson.model.ParameterDefinition;
import hudson.model.ParameterValue;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Result;
import hudson.util.ReflectionUtils;
import jenkins.model.Jenkins;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -382,6 +383,8 @@ private Object coerce(String context, Type type, Object o) throws Exception {
return Enum.valueOf(erased.asSubclass(Enum.class), (String) o);
} else if (o instanceof String && erased == URL.class) {
return new URL((String) o);
} else if (o instanceof String && erased == Result.class) {
return Result.fromString((String)o);
} else if (o instanceof String && (erased == char.class || erased == Character.class) && ((String) o).length() == 1) {
return ((String) o).charAt(0);
} else if (o instanceof List && erased.isArray()) {
Expand Down
Expand Up @@ -2,6 +2,7 @@

import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Result;
import org.jvnet.tiger_types.Types;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
Expand Down Expand Up @@ -172,6 +173,8 @@ private Object uncoerce(Object o, Type type) {
return ((Enum) o).name();
} else if (type == URL.class && o instanceof URL) {
return o.toString();
} else if (type == Result.class && o instanceof Result) {
return o.toString();
} else if ((type == Character.class || type == char.class) && o instanceof Character) {
return o.toString();
} else if (o instanceof Object[]) {
Expand Down
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.structs.describable;

import com.google.common.primitives.Primitives;
import hudson.model.Result;
import org.jvnet.tiger_types.Types;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -54,6 +55,9 @@ static ParameterType of(Type type) {
if (c == URL.class) {
return new AtomicType(String.class);
}
if (c == Result.class) {
return new AtomicType(String.class);
}
if (c.isArray()) {
return new ArrayType(c);
}
Expand Down
Expand Up @@ -30,6 +30,7 @@
import hudson.model.Descriptor;
import hudson.model.ParameterValue;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Result;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.UserMergeOptions;
import hudson.plugins.git.extensions.impl.CleanBeforeCheckout;
Expand Down Expand Up @@ -368,6 +369,19 @@ public static final class UsesURL {
}
}

@Test public void result() throws Exception {
roundTrip(UsesResult.class, map("r", "SUCCESS"));
schema(UsesResult.class, "UsesResult(r?: String)");
}

public static final class UsesResult {
@DataBoundConstructor public UsesResult() {}
@DataBoundSetter public Result r;
@Override public String toString() {
return "UsesResult[" + r + "]";
}
}

@Test public void chars() throws Exception {
roundTrip(UsesCharacter.class, map("c", "!"));
schema(UsesCharacter.class, "UsesCharacter(c?: char)");
Expand Down

0 comments on commit 1c8a50c

Please sign in to comment.