提交 22e8e1f2 编写于 作者: K Kohsuke Kawaguchi

Added ToolInstallation.buildEnvVars()

This provides generic consumer of ToolInstallation to expose
ToolInstallation to the build.
上级 dc0bec17
......@@ -23,6 +23,8 @@
*/
package hudson.model;
import com.infradna.tool.bridge_method_injector.BridgeMethodsAdded;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import hudson.util.StreamTaskListener;
import hudson.util.NullStream;
import hudson.util.FormValidation;
......@@ -100,14 +102,22 @@ public final class JDK extends ToolInstallation implements NodeSpecific<JDK>, En
}
/**
* Sets PATH and JAVA_HOME from this JDK.
* @deprecated as of 1.460. Use {@link #buildEnvVars(EnvVars)}
*/
public void buildEnvVars(Map<String,String> env) {
// see EnvVars javadoc for why this adss PATH.
// see EnvVars javadoc for why this adds PATH.
env.put("PATH+JDK",getHome()+"/bin");
env.put("JAVA_HOME",getHome());
}
/**
* Sets PATH and JAVA_HOME from this JDK.
*/
@Override
public void buildEnvVars(EnvVars env) {
buildEnvVars((Map)env);
}
public JDK forNode(Node node, TaskListener log) throws IOException, InterruptedException {
return new JDK(getName(), translateFor(node, log));
}
......
......@@ -294,8 +294,7 @@ public class Maven extends Builder {
// The other solution would be to set M2_HOME if we are calling Maven2
// and MAVEN_HOME for Maven1 (only of use for strange people that
// are calling Maven2 from Maven1)
env.put("M2_HOME",mi.getHome());
env.put("MAVEN_HOME",mi.getHome());
mi.buildEnvVars(env);
}
// just as a precaution
// see http://maven.apache.org/continuum/faqs.html#how-does-continuum-detect-a-successful-build
......@@ -401,6 +400,14 @@ public class Maven extends Builder {
return new File(getHome());
}
@Override
public void buildEnvVars(EnvVars env) {
String home = getHome();
env.put("M2_HOME", home);
env.put("MAVEN_HOME", home);
env.put("PATH+MAVEN", home + "/bin");
}
/**
* Compares the version of this Maven installation to the minimum required version specified.
*
......
......@@ -126,6 +126,18 @@ public abstract class ToolInstallation extends AbstractDescribableImpl<ToolInsta
return home;
}
/**
* Expose any environment variables that this tool installation wants the build to see.
*
* <p>
* To add entry to PATH, do {@code envVars.put("PATH+XYZ",path)} where 'XYZ' is something unique.
* Variable names of the form 'A+B' is interpreted as adding the value to the existing PATH.
*
* @since 1.460
*/
public void buildEnvVars(EnvVars env) {
}
public DescribableList<ToolProperty<?>,ToolPropertyDescriptor> getProperties() {
assert properties!=null;
return properties;
......
......@@ -215,8 +215,7 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
if (mvn == null)
throw new hudson.AbortException(Messages.MavenModuleSetBuild_NoMavenConfigured());
mvn = mvn.forEnvironment(envs).forNode(Computer.currentComputer().getNode(), log);
envs.put("M2_HOME", mvn.getHome());
envs.put("PATH+MAVEN", mvn.getHome() + "/bin");
mvn.buildEnvVars(envs);
return envs;
}
......
......@@ -169,9 +169,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
Node node = computer.getNode();
if (node != null) {
mvn = mvn.forNode(node, log);
envs.put("M2_HOME", mvn.getHome());
envs.put("PATH+MAVEN", mvn.getHome() + "/bin");
mvn.buildEnvVars(envs);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册