提交 1f11a933 编写于 作者: K kohsuke

code simplification. Parameterized build is in the core, so we should make...

code simplification. Parameterized build is in the core, so we should make AbstractBuild aware of it.

See http://www.nabble.com/TFS-build-by-label--td21859630.html where Eric mentioned his confusion about how his plugin can get parameters.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15091 71c3de6d-444a-0410-be80-ed276b4c234a
上级 6ee24ace
......@@ -98,8 +98,10 @@ public class MatrixRun extends Build<MatrixConfiguration,MatrixRun> {
@Override
public Map<String,String> getBuildVariables() {
Map<String,String> r = super.getBuildVariables();
// pick up user axes
return new HashMap<String,String>(getParent().getCombination());
r.putAll(getParent().getCombination());
return r;
}
/**
......
......@@ -45,6 +45,7 @@ import hudson.tasks.test.AbstractTestResultAction;
import hudson.util.AdaptedIterator;
import hudson.util.Iterators;
import hudson.util.VariableResolver;
import hudson.util.VariableResolver.ByMap;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
......@@ -451,10 +452,24 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
* {@link Builder}s to decide whether it wants to recognize the values
* or how to use them.
*
* ugly ugly hack.
* <p>
* This also includes build parameters if a build is parameterized.
*
* @return
* The returned map is mutable so that subtypes can put more values.
*/
public Map<String,String> getBuildVariables() {
return Collections.emptyMap();
Map<String,String> r = new HashMap<String, String>();
ParametersAction parameters = getAction(ParametersAction.class);
if(parameters!=null) {
// this is a rather round about way of doing this...
for (ParameterValue p : parameters) {
String v = p.createVariableResolver(this).resolve(p.getName());
if(v!=null) r.put(p.getName(),v);
}
}
return r;
}
/**
......
......@@ -25,6 +25,7 @@ package hudson.model;
import hudson.Util;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildStep;
import hudson.util.VariableResolver;
import java.util.Collection;
......@@ -70,6 +71,9 @@ public class ParametersAction implements Action, Iterable<ParameterValue> {
/**
* Creates an {@link VariableResolver} that aggregates all the parameters.
*
* <p>
* If you are a {@link BuildStep}, most likely you should call {@link AbstractBuild#getBuildVariableResolver()}.
*/
public VariableResolver<String> createVariableResolver(AbstractBuild<?,?> build) {
VariableResolver[] resolvers = new VariableResolver[parameters.size()+1];
......
......@@ -167,10 +167,7 @@ public class Ant extends Builder {
args.addKeyValuePairs("-D",build.getBuildVariables());
VariableResolver<String> vr = build.getBuildVariableResolver();
ParametersAction parameters = build.getAction(ParametersAction.class);
if(parameters!=null)
vr = parameters.createVariableResolver(build);
args.addKeyValuePairsFromPropertyString("-D",properties,vr);
args.addTokenized(Util.replaceMacro(targets,vr).replaceAll("[\t\r\n]+"," "));
......
......@@ -177,9 +177,6 @@ public class Maven extends Builder {
AbstractProject proj = build.getProject();
VariableResolver<String> vr = build.getBuildVariableResolver();
ParametersAction parameters = build.getAction(ParametersAction.class);
if(parameters!=null)
vr = parameters.createVariableResolver(build);
String targets = Util.replaceMacro(this.targets,vr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册