提交 75348fae 编写于 作者: K kohsuke

simplified a bit

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15750 71c3de6d-444a-0410-be80-ed276b4c234a
上级 8899d864
......@@ -101,12 +101,7 @@ public final class JDK extends ToolInstallation implements NodeSpecific<JDK> {
}
public JDK forNode(Node node) {
String newHome = ToolLocationNodeProperty.getToolHome(node, this);
if (newHome != null) {
return new JDK(getName(), newHome);
} else {
return this;
}
return new JDK(getName(),ToolLocationNodeProperty.getToolHome(node, this));
}
/**
......
......@@ -402,12 +402,7 @@ public class Ant extends Builder {
}
public AntInstallation forNode(Node node) {
String newHome = ToolLocationNodeProperty.getToolHome(node, this);
if (newHome != null) {
return new AntInstallation(getName(), newHome);
} else {
return this;
}
return new AntInstallation(getName(),ToolLocationNodeProperty.getToolHome(node, this));
}
@Extension
......
......@@ -429,12 +429,7 @@ public class Maven extends Builder {
}
public MavenInstallation forNode(Node node) {
String newHome = ToolLocationNodeProperty.getToolHome(Computer.currentComputer().getNode(), this);
if (newHome != null) {
return new MavenInstallation(getName(), newHome);
} else {
return this;
}
return new MavenInstallation(getName(),ToolLocationNodeProperty.getToolHome(node,this));
}
@Extension
......
......@@ -27,9 +27,11 @@ package hudson.tools;
import hudson.DescriptorExtensionList;
import hudson.Extension;
import hudson.ExtensionPoint;
import hudson.EnvVars;
import hudson.model.Describable;
import hudson.model.EnvironmentSpecific;
import hudson.model.Hudson;
import hudson.model.Node;
import hudson.slaves.NodeSpecific;
import java.io.Serializable;
......@@ -52,7 +54,9 @@ import java.io.Serializable;
* </ul>
*
* <p>
* Implementation of this class should consider implementing {@link NodeSpecific} and {@link EnvironmentSpecific}.
* Implementations of this class are strongly encouraged to also implement {@link NodeSpecific}
* (by using {@link ToolLocationNodeProperty#getToolHome(Node, ToolInstallation)}) and
* {@link EnvironmentSpecific} (by using {@link EnvVars#expand(String)}.)
*
* <p>
* To contribute an extension point, put {@link Extension} on your {@link ToolDescriptor} class.
......
......@@ -31,6 +31,7 @@ import hudson.model.Hudson;
import hudson.model.Node;
import hudson.slaves.NodeProperty;
import hudson.slaves.NodePropertyDescriptor;
import hudson.slaves.NodeSpecific;
import org.kohsuke.stapler.DataBoundConstructor;
import java.util.Arrays;
......@@ -71,12 +72,22 @@ public class ToolLocationNodeProperty extends NodeProperty<Node> {
return null;
}
/**
* Checks if the location of the tool is overridden for the given node, and if so,
* return the node-specific home directory. Otherwise return {@code installation.getHome()}
*
* <p>
* This is the core logic behind {@link NodeSpecific#forNode(Node)} for {@link ToolInstallation}.
*
* @return
* never null.
*/
public static String getToolHome(Node node, ToolInstallation installation) {
ToolLocationNodeProperty property = node.getNodeProperties().get(ToolLocationNodeProperty.class);
if (property != null) {
return property.getHome(installation);
}
return null;
return installation.getHome();
}
@Extension
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册