@Override public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue) { if (defaultValue instanceof StringParameterValue) { StringParameterValue value = (StringParameterValue) defaultValue; return new ChoiceParameterDefinition(getName(), choices, value.value, getDescription()); } else { return this; } }
public StringParameterValue createValue(String value) { return checkValue(new StringParameterValue(getName(), value, getDescription())); }
/** * Checks if parameterized build choices are valid. */ public FormValidation doCheckChoices(@QueryParameter String value) { if (ChoiceParameterDefinition.areValidChoices(value)) { return FormValidation.ok(); } else { return FormValidation.error(Messages.ChoiceParameterDefinition_MissingChoices()); } } }
@Override public StringParameterValue getDefaultParameterValue() { return new StringParameterValue(getName(), defaultValue == null ? choices.get(0) : defaultValue, getDescription()); }
@Override public ParameterValue createValue(StaplerRequest req, JSONObject jo) { StringParameterValue value = req.bindJSON(StringParameterValue.class, jo); value.setDescription(getDescription()); return checkValue(value); }
@Override public boolean equals(Object o) { return super.equals(o) && new EqualsBuilder() .append(getChoices(), ((ChoiceParameterDefinition) o).getChoices()) .isEquals(); }
@Override /* * We need this for JENKINS-26143 -- reflective creation cannot handle setChoices(Object). See that method for context. */ public ParameterDefinition newInstance(@Nullable StaplerRequest req, @Nonnull JSONObject formData) throws FormException { String name = formData.getString("name"); String desc = formData.getString("description"); String choiceText = formData.getString("choices"); return new ChoiceParameterDefinition(name, choiceText, desc); }
private StringParameterValue checkValue(StringParameterValue value) { if (!choices.contains(value.value)) throw new IllegalArgumentException("Illegal choice for parameter " + getName() + ": " + value.value); return value; }
public ChoiceParameterDefinition(String name, String choices, String description) { super(name, description); setChoicesText(choices); defaultValue = null; }
@Override public ParameterValue createValue(StaplerRequest req, JSONObject jo) { StringParameterValue value = req.bindJSON(StringParameterValue.class, jo); value.setDescription(getDescription()); return checkValue(value); }
@Override public StringParameterValue getDefaultParameterValue() { return new StringParameterValue(getName(), defaultValue == null ? choices.get(0) : defaultValue, getDescription()); }
@Override public boolean equals(Object o) { return super.equals(o) && new EqualsBuilder() .append(getChoices(), ((ChoiceParameterDefinition) o).getChoices()) .isEquals(); }
@Issue("JENKINS-26143") @Test public void testChoiceParameterSnippetizer() throws Exception { //new SnippetizerTester(r).assertGenerateSnippet(); new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(Arrays.asList(new ParametersDefinitionProperty(new ChoiceParameterDefinition("paramName", new String[] { "foo", "bar", "baz" }, "")))), "properties([parameters([choice(choices: ['foo', 'bar', 'baz'], description: '', name: 'paramName')])])"); }
private StringParameterValue checkValue(StringParameterValue value) { if (!choices.contains(value.value)) throw new IllegalArgumentException("Illegal choice for parameter " + getName() + ": " + value.value); return value; }
public void setChoices(Object choices) { if (choices instanceof String) { setChoicesText((String) choices); return;
public StringParameterValue createValue(String value) { return checkValue(new StringParameterValue(getName(), value, getDescription())); }
@Override public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue) { if (defaultValue instanceof StringParameterValue) { StringParameterValue value = (StringParameterValue) defaultValue; return new ChoiceParameterDefinition(getName(), choices, value.value, getDescription()); } else { return this; } }
@Override public ParameterValue createValue(StaplerRequest req, JSONObject jo) { StringParameterValue value = req.bindJSON(StringParameterValue.class, jo); value.setDescription(getDescription()); return checkValue(value); }
@Override public StringParameterValue getDefaultParameterValue() { return new StringParameterValue(getName(), choices.get(0), getDescription()); }
@Override public boolean equals(Object o) { return super.equals(o) && new EqualsBuilder() .append(getChoices(), ((ChoiceParameterDefinition) o).getChoices()) .isEquals(); }