提交 6b3f19be 编写于 作者: H huybrechts

Merge branch 'HUDSON-2557'

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@16843 71c3de6d-444a-0410-be80-ed276b4c234a
上级 f4302f54
package hudson.model;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.DataBoundConstructor;
import net.sf.json.JSONObject;
import hudson.Extension;
/**
* @author huybrechts
*/
public class BooleanParameterDefinition extends ParameterDefinition {
private final boolean defaultValue;
@DataBoundConstructor
public BooleanParameterDefinition(String name, boolean defaultValue, String description) {
super(name, description);
this.defaultValue = defaultValue;
}
public boolean isDefaultValue() {
return defaultValue;
}
@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
BooleanParameterValue value = req.bindJSON(BooleanParameterValue.class, jo);
value.setDescription(getDescription());
return value;
}
@Override
public ParameterValue createValue(StaplerRequest req) {
String[] value = req.getParameterValues(getName());
if (value == null) {
return getDefaultParameterValue();
} else if (value.length != 1) {
throw new IllegalArgumentException("Illegal number of parameter values for " + getName() + ": " + value.length);
} else {
boolean booleanValue = Boolean.parseBoolean(value[0]);
return new BooleanParameterValue(getName(), booleanValue, getDescription());
}
}
@Extension
public static class DescriptorImpl extends ParameterDescriptor {
@Override
public String getDisplayName() {
return "Boolean Value";
}
@Override
public String getHelpFile() {
return "/help/parameter/boolean.html";
}
}
}
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Luca Domenico Milanesio, Tom Huybrechts
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.model;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.export.Exported;
import java.util.Map;
import hudson.util.VariableResolver;
/**
* {@link hudson.model.ParameterValue} created from {@link hudson.model.StringParameterDefinition}.
*/
public class BooleanParameterValue extends ParameterValue {
@Exported(visibility=3)
public final boolean value;
@DataBoundConstructor
public BooleanParameterValue(String name, boolean value) {
this(name, value, null);
}
public BooleanParameterValue(String name, boolean value, String description) {
super(name, description);
this.value = value;
}
/**
* Exposes the name/value as an environment variable.
*/
@Override
public void buildEnvVars(AbstractBuild<?,?> build, Map<String,String> env) {
env.put(name.toUpperCase(),Boolean.toString(value));
}
@Override
public VariableResolver<String> createVariableResolver(AbstractBuild<?, ?> build) {
return new VariableResolver<String>() {
public String resolve(String name) {
return BooleanParameterValue.this.name.equals(name) ? Boolean.toString(value) : null;
}
};
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
BooleanParameterValue that = (BooleanParameterValue) o;
if (value != that.value) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (value ? 1 : 0);
return result;
}
@Override
public String toString() {
return "(BooleanParameterValue) " + getName() + "='" + value + "'";
}
}
\ No newline at end of file
package hudson.model;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.DataBoundConstructor;
import org.apache.commons.lang.StringUtils;
import net.sf.json.JSONObject;
import hudson.Extension;
import java.util.List;
import java.util.Arrays;
/**
* @author huybrechts
*/
public class ChoiceParameterDefinition extends ParameterDefinition {
private final List<String> choices;
@DataBoundConstructor
public ChoiceParameterDefinition(String name, String choices, String description) {
super(name, description);
this.choices = Arrays.asList(choices.split("\\r?\\n"));
if (choices.isEmpty()) {
throw new IllegalArgumentException("No choices found");
}
}
public List<String> getChoices() {
return choices;
}
public String getChoicesText() {
return StringUtils.join(choices, "\n");
}
@Override
public StringParameterValue getDefaultParameterValue() {
return new StringParameterValue(getName(), choices.get(0), getDescription());
}
private void checkValue(StringParameterValue value) {
if (!choices.contains(value.value)) {
throw new IllegalArgumentException("Illegal choice: " + value.value);
}
}
@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
StringParameterValue value = req.bindJSON(StringParameterValue.class, jo);
value.setDescription(getDescription());
checkValue(value);
return value;
}
@Override
public ParameterValue createValue(StaplerRequest req) {
StringParameterValue result;
String[] value = req.getParameterValues(getName());
if (value == null) {
result = getDefaultParameterValue();
} else if (value.length != 1) {
throw new IllegalArgumentException("Illegal number of parameter values for " + getName() + ": " + value.length);
} else {
result = new StringParameterValue(getName(), value[0], getDescription());
}
checkValue(result);
return result;
}
@Extension
public static class DescriptorImpl extends ParameterDescriptor {
@Override
public String getDisplayName() {
return "Choice";
}
@Override
public String getHelpFile() {
return "/help/parameter/choice.html";
}
}
}
\ No newline at end of file
......@@ -38,13 +38,14 @@ import hudson.Extension;
*/
public class FileParameterDefinition extends ParameterDefinition {
@DataBoundConstructor
public FileParameterDefinition(String name) {
super(name);
public FileParameterDefinition(String name, String description) {
super(name, description);
}
public FileParameterValue createValue(StaplerRequest req, JSONObject jo) {
FileParameterValue p = req.bindJSON(FileParameterValue.class, jo);
p.setLocation(getName());
p.setDescription(getDescription());
return p;
}
......
......@@ -49,7 +49,10 @@ public class FileParameterValue extends ParameterValue {
@DataBoundConstructor
public FileParameterValue(String name, FileItem file) {
super(name);
this(name, file, null);
}
public FileParameterValue(String name, FileItem file, String description) {
super(name, description);
assert file!=null;
this.file = file;
}
......
......@@ -91,14 +91,23 @@ public abstract class ParameterDefinition implements
Describable<ParameterDefinition>, ExtensionPoint {
private final String name;
private final String description;
public ParameterDefinition(String name) {
this(name, null);
}
public ParameterDefinition(String name, String description) {
this.name = name;
this.description = description;
}
public String getName() {
return name;
}
public ParameterDefinition(String name) {
super();
this.name = name;
public String getDescription() {
return description;
}
/**
......
......@@ -64,8 +64,23 @@ import net.sf.json.JSONObject;
public abstract class ParameterValue {
protected final String name;
protected ParameterValue(String name) {
private String description;
protected ParameterValue(String name, String description) {
this.name = name;
this.description = description;
}
protected ParameterValue(String name) {
this(name, null);
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
/**
......
......@@ -99,7 +99,8 @@ public class ParametersDefinitionProperty extends JobProperty<AbstractProject<?,
ParameterDefinition d = getParameterDefinition(name);
if(d==null)
throw new IllegalArgumentException("No such parameter definition: " + name);
values.add(d.createValue(req, jo));
ParameterValue parameterValue = d.createValue(req, jo);
values.add(parameterValue);
}
Hudson.getInstance().getQueue().add(
......
......@@ -1286,6 +1286,23 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
return env;
}
public String getExternalizableId() {
return project.getName() + "#" + getNumber();
}
public static Run<?,?> fromExternalizableId(String id) {
int hash = id.lastIndexOf('#');
if (hash <= 0) {
throw new IllegalArgumentException("Invalid id");
}
String jobName = id.substring(0, hash);
int number = Integer.parseInt(id.substring(hash + 1));
Job<?,?> job = (Job<?,?>) Hudson.getInstance().getItem(jobName);
return job.getBuildByNumber(number);
}
public static final XStream XSTREAM = new XStream2();
static {
XSTREAM.alias("build",FreeStyleBuild.class);
......
......@@ -27,35 +27,67 @@ import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import hudson.Extension;
public class RunParameterDefinition extends ParameterDefinition {
private final String projectName;
@DataBoundConstructor
public RunParameterDefinition(String name) {
super(name);
public RunParameterDefinition(String name, String projectName, String description) {
super(name, description);
this.projectName = projectName;
}
public String getProjectName() {
return projectName;
}
// @Extension --- not live yet
public Job getProject() {
return (Job) Hudson.getInstance().getItem(projectName);
}
@Extension
public static class DescriptorImpl extends ParameterDescriptor {
@Override
public String getDisplayName() {
return "Run Parameter";
}
@Override
public String getHelpFile() {
return "/help/parameter/run.html";
}
@Override
public ParameterDefinition newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return req.bindJSON(RunParameterDefinition.class, formData);
}
}
@Override
public ParameterValue getDefaultParameterValue() {
return new RunParameterValue(getName(), getProject().getLastBuild().getExternalizableId(), getDescription());
}
@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
return req.bindJSON(RunParameterValue.class, jo);
RunParameterValue value = req.bindJSON(RunParameterValue.class, jo);
value.setDescription(getDescription());
return value;
}
@Override
public ParameterValue createValue(StaplerRequest req) {
throw new UnsupportedOperationException();
String[] value = req.getParameterValues(getName());
if (value == null) {
return getDefaultParameterValue();
} else if (value.length != 1) {
throw new IllegalArgumentException("Illegal number of parameter values for " + getName() + ": " + value.length);
} else {
return new RunParameterValue(getName(), value[0], getDescription());
}
}
}
......@@ -27,14 +27,34 @@ import org.kohsuke.stapler.DataBoundConstructor;
import java.util.Map;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import hudson.util.Secret;
public class RunParameterValue extends ParameterValue {
public final Run run;
private final String runId;
@DataBoundConstructor
public RunParameterValue(String name, Run run) {
super(name);
this.run = run;
public RunParameterValue(String name, String runId, String description) {
super(name, description);
this.runId = runId;
}
public RunParameterValue(String name, String runId) {
super(name, null);
this.runId = runId;
}
public Run getRun() {
return Run.fromExternalizableId(runId);
}
public String getRunId() {
return runId;
}
/**
......@@ -42,7 +62,7 @@ public class RunParameterValue extends ParameterValue {
*/
@Override
public void buildEnvVars(AbstractBuild<?,?> build, Map<String,String> env) {
// TODO: check with Tom if this is really what he had in mind
env.put(name.toUpperCase(),run.toString());
env.put(name.toUpperCase(), Hudson.getInstance().getRootUrl() + getRun().getUrl());
}
}
......@@ -37,11 +37,15 @@ public class StringParameterDefinition extends ParameterDefinition {
private String defaultValue;
@DataBoundConstructor
public StringParameterDefinition(String name, String defaultValue) {
super(name);
public StringParameterDefinition(String name, String defaultValue, String description) {
super(name, description);
this.defaultValue = defaultValue;
}
public StringParameterDefinition(String name, String defaultValue) {
this(name, defaultValue, null);
}
public String getDefaultValue() {
return defaultValue;
}
......@@ -51,7 +55,8 @@ public class StringParameterDefinition extends ParameterDefinition {
}
public StringParameterValue getDefaultParameterValue() {
return new StringParameterValue(getName(), defaultValue);
StringParameterValue v = new StringParameterValue(getName(), defaultValue, getDescription());
return v;
}
@Extension
......@@ -69,7 +74,9 @@ public class StringParameterDefinition extends ParameterDefinition {
@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
return req.bindJSON(StringParameterValue.class, jo);
StringParameterValue value = req.bindJSON(StringParameterValue.class, jo);
value.setDescription(getDescription());
return value;
}
@Override
......@@ -80,7 +87,7 @@ public class StringParameterDefinition extends ParameterDefinition {
} else if (value.length != 1) {
throw new IllegalArgumentException("Illegal number of parameter values for " + getName() + ": " + value.length);
} else
return new StringParameterValue(getName(), value[0]);
return new StringParameterValue(getName(), value[0], getDescription());
}
}
......@@ -39,7 +39,11 @@ public class StringParameterValue extends ParameterValue {
@DataBoundConstructor
public StringParameterValue(String name, String value) {
super(name);
this(name, value, null);
}
public StringParameterValue(String name, String value, String description) {
super(name, description);
this.value = value;
}
......
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe, Tom Huybrechts
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${%Name}" help="/help/parameter/name.html">
<f:textbox name="parameter.name" value="${instance.name}" />
</f:entry>
<f:entry title="${%Default Value}" help="/help/parameter/boolean-default.html">
<f:checkbox name="parameter.defaultValue" checked="${instance.defaultValue}" />
</f:entry>
<f:entry title="${%Description}" help="/help/parameter/description.html">
<f:textarea name="parameter.description" value="${instance.description}" />
</f:entry>
</j:jelly>
\ No newline at end of file
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${it.name}" description="${it.description}">
<div name="parameter" description="${it.description}">
<input type="hidden" name="name" value="${it.name}" />
<f:checkbox name="value" checked="${it.defaultValue}" />
</div>
</f:entry>
</j:jelly>
\ No newline at end of file
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${it.name}" description="${it.description}">
<f:checkbox name="value" checked="${it.value}" readonly="true" />
</f:entry>
</j:jelly>
\ No newline at end of file
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe, Tom Huybrechts
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${%Name}" help="/help/parameter/name.html">
<f:textbox name="parameter.name" value="${instance.name}" />
</f:entry>
<f:entry title="Choices" help="/help/parameter/choice-choices.html">
<f:textarea name="parameter.choices" value="${instance.choicesText}" />
</f:entry>
<f:entry title="${%Description}" help="/help/parameter/description.html">
<f:textarea name="parameter.description" value="${instance.description}" />
</f:entry>
</j:jelly>
\ No newline at end of file
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${it.name}" description="${it.description}">
<div name="parameter" description="${it.description}">
<input type="hidden" name="name" value="${it.name}" />
<select name="value">
<j:forEach var="value" items="${it.choices}">
<f:option selected="${it.value==value}">${value}</f:option>
</j:forEach>
</select>
</div>
</f:entry>
</j:jelly>
\ No newline at end of file
......@@ -31,4 +31,7 @@ THE SOFTWARE.
<!--f:entry title="Optional">
<f:checkbox name="parameter.optional" value="${instance.optional}" />
</f:entry-->
<f:entry title="${%Description}" help="/help/parameter/TODO.html">
<f:textarea name="parameter.description" value="${instance.description}" />
</f:entry>
</j:jelly>
\ No newline at end of file
......@@ -25,7 +25,7 @@ THE SOFTWARE.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${it.name}">
<f:entry title="${it.name}" description="${it.description}">
<div name="parameter">
<input type="hidden" name="name" value="${it.name}" />
<input name="file" type="file" jsonAware="true" />
......
......@@ -38,7 +38,7 @@ THE SOFTWARE.
<l:main-panel>
<h1>${it.owner.pronoun} ${it.owner.displayName}</h1>
<p>${%description}</p>
<f:form method="post" action="build">
<f:form method="post" action="build" name="parameters">
<j:forEach var="parameterDefinition" items="${it.parameterDefinitions}">
<st:include it="${parameterDefinition}"
page="${parameterDefinition.descriptor.valuePage}" />
......
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe, Tom Huybrechts
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${%Name}" help="/help/parameter/name.html">
<f:textbox name="parameter.name" value="${instance.name}" />
</f:entry>
<f:entry title="Project" help="/help/parameter/run-project.html">
<select name="parameter.projectName">
<j:forEach var="project" items="${app.items}">
<f:option selected="${it.project==project}">${project.displayName}</f:option>
</j:forEach>
</select>
</f:entry>
<f:entry title="${%Description}" help="/help/parameter/description.html">
<f:textarea name="parameter.description" value="${instance.description}" />
</f:entry>
</j:jelly>
\ No newline at end of file
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${it.name}" description="${it.description}">
<div name="parameter" description="${it.description}">
<input type="hidden" name="name" value="${it.name}" />
<select name="runId">
<j:forEach var="run" items="${it.project.builds}">
<option value="${run.externalizableId}">${run}</option>
</j:forEach>
</select>
</div>
</f:entry>
</j:jelly>
\ No newline at end of file
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${it.name}" description="${it.description}">
<a href="${rootUrl}/${it.run.url}">${it.run}</a>
</f:entry>
</j:jelly>
\ No newline at end of file
......@@ -25,10 +25,13 @@ THE SOFTWARE.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${%Name}">
<f:entry title="${%Name}" help="/help/parameter/name.html">
<f:textbox name="parameter.name" value="${instance.name}" />
</f:entry>
<f:entry title="${%Default Value}" help="/help/parameter/string-default.html">
<f:textbox name="parameter.defaultValue" value="${instance.defaultValue}" />
</f:entry>
<f:entry title="${%Description}" help="/help/parameter/description.html">
<f:textarea name="parameter.description" value="${instance.description}" />
</f:entry>
</j:jelly>
\ No newline at end of file
......@@ -25,8 +25,8 @@ THE SOFTWARE.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${it.name}">
<div name="parameter">
<f:entry title="${it.name}" description="${it.description}">
<div name="parameter" description="${it.description}">
<input type="hidden" name="name" value="${it.name}" />
<f:textbox name="value" value="${it.defaultValue}" />
</div>
......
......@@ -25,7 +25,7 @@ THE SOFTWARE.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${it.name}">
<f:entry title="${it.name}" description="${it.description}">
<f:textbox name="value" value="${it.value}" readonly="true" />
</f:entry>
</j:jelly>
\ No newline at end of file
package hudson.model;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.CaptureEnvironmentBuilder;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
/**
* @author huybrechts
*/
public class ParametersTest extends HudsonTestCase {
public void testStringParameter() throws Exception {
FreeStyleProject otherProject = createFreeStyleProject();
otherProject.scheduleBuild2(0).get();
FreeStyleProject project = createFreeStyleProject();
ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(
new StringParameterDefinition("string", "defaultValue", "string description"),
new BooleanParameterDefinition("boolean", true, "boolean description"),
new ChoiceParameterDefinition("choice", "Choice 1\nChoice 2", "choice description"),
new RunParameterDefinition("run", otherProject.getName(), "run description"));
project.addProperty(pdp);
CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
project.getBuildersList().add(builder);
WebClient wc = new WebClient();
wc.setThrowExceptionOnFailingStatusCode(false);
HtmlPage page= wc.goTo("/job/" + project.getName() + "/build?delay=0sec");
HtmlForm form = page.getFormByName("parameters");
HtmlElement element = (HtmlElement) form.selectSingleNode("//tr[td/div/input/@value='string']");
assertNotNull(element);
assertEquals("string description", ((HtmlElement) element.selectSingleNode("td/div")).getAttribute("description"));
HtmlTextInput stringParameterInput = (HtmlTextInput) element.selectSingleNode(".//input[@name='value']");
assertEquals("defaultValue", stringParameterInput.getAttribute("value"));
assertEquals("string", ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());
stringParameterInput.setAttribute("value", "newValue");
element = (HtmlElement) form.selectSingleNode("//tr[td/div/input/@value='boolean']");
assertNotNull(element);
assertEquals("boolean description", ((HtmlElement) element.selectSingleNode("td/div")).getAttribute("description"));
Object o = element.selectSingleNode(".//input[@name='value']");
System.out.println(o);
HtmlCheckBoxInput booleanParameterInput = (HtmlCheckBoxInput) o;
assertEquals(true, booleanParameterInput.isChecked());
assertEquals("boolean", ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());
element = (HtmlElement) form.selectSingleNode(".//tr[td/div/input/@value='choice']");
assertNotNull(element);
assertEquals("choice description", ((HtmlElement) element.selectSingleNode("td/div")).getAttribute("description"));
// HtmlCheckBoxInput booleanParameterInput = (HtmlCheckBoxInput) element.selectSingleNode("//input[@name='value']");
// assertEquals(true, booleanParameterInput.isChecked());
assertEquals("choice", ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());
element = (HtmlElement) form.selectSingleNode(".//tr[td/div/input/@value='run']");
assertNotNull(element);
assertEquals("run description", ((HtmlElement) element.selectSingleNode("td/div")).getAttribute("description"));
assertEquals("run", ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());
submit(form);
Thread.sleep(1000);
assertEquals("newValue", builder.getEnvVars().get("STRING"));
assertEquals("true", builder.getEnvVars().get("BOOLEAN"));
assertEquals("Choice 1", builder.getEnvVars().get("CHOICE"));
assertEquals(hudson.getRootUrl() + otherProject.getLastBuild().getUrl(), builder.getEnvVars().get("RUN"));
}
}
<div>
Specifies the default value of the field.
</div>
\ No newline at end of file
<div>
Defines a simple boolean parameter, which you can use during a build, either as an environment variable, or
through variable substitution in some other parts of the configuration. The string value will be 'true' or 'false'.
</div>
\ No newline at end of file
<div>
The potential choices, one per line. The value on the first line will be the default.
</div>
\ No newline at end of file
<div>
Defines a simple string parameter, which can be selected from a list.
You can use it during a build, either as an environment variable, or
through variable substitution in some other parts of the configuration..
</div>
\ No newline at end of file
<div>
A description that will be showed to the user later.
</div>
\ No newline at end of file
<div>
The name of the parameter
<p>
Note that when this field is exposed as an environment variable, the name
will be always in upper case (e.g., the parameter "foo" would be exposed
as "FOO"). In Ant for example you access it by typing in ${env.FOO}
</div>
\ No newline at end of file
<div>
Defines the job from which the user can pick runs. The last run will be the default.
</div>
\ No newline at end of file
<div>
Defines a run parameter, where users can pick a single run of a certain project. The absolute url
of this run will be exposed as an environment variable, or
through variable substitution in some other parts of the configuration. In the build this can be used
to query Hudson for further information.
</div>
\ No newline at end of file
......@@ -2,9 +2,4 @@
Defines a simple text parameter, where users can enter a string value,
which you can use during a build, either as an environment variable, or
through variable substitution in some other parts of the configuration.
<p>
Note that when this field is exposed as an environment variable, it
will be always in the upper case (e.g., the parameter "foo" would be exposed
as "FOO"). In Ant for example you access it by typing in ${env.FOO}
</div>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册