Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED JENKINS-34464] Enable DescribableModel binding for Result #19

Merged
merged 1 commit into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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