mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-09 01:56:03 +00:00
Namespace tools installation by tool name.
This prevents naming conflicts if someone names 2 tools installations of different tools with the same name.
This commit is contained in:
1 parent
c37adad305
commit
fc962ca9cb
1 file changed
+8
-3
@@ -32,6 +32,8 @@ import jenkins.model.Jenkins;
|
||||
import hudson.model.Label;
|
||||
import hudson.model.Node;
|
||||
import hudson.model.TaskListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
@@ -102,7 +104,7 @@ public abstract class ToolInstaller implements Describable<ToolInstaller>, Exten
|
||||
* @param tool the tool being installed
|
||||
* @param node the computer on which to install the tool
|
||||
* @return {@link ToolInstallation#getHome} if specified, else a path within the local
|
||||
* Hudson work area named according to {@link ToolInstallation#getName}
|
||||
* Jenkins work area named according to {@link ToolInstallation#getName}
|
||||
* @since 1.310
|
||||
*/
|
||||
protected final FilePath preferredLocation(ToolInstallation tool, Node node) {
|
||||
@@ -111,8 +113,7 @@ public abstract class ToolInstaller implements Describable<ToolInstaller>, Exten
|
||||
}
|
||||
String home = Util.fixEmptyAndTrim(tool.getHome());
|
||||
if (home == null) {
|
||||
// XXX should this somehow uniquify paths among ToolInstallation.all()?
|
||||
home = tool.getName().replaceAll("[^A-Za-z0-9_.-]+", "_");
|
||||
home = sanitize(tool.getDescriptor().getDisplayName()) + File.separatorChar + sanitize(tool.getName());
|
||||
}
|
||||
FilePath root = node.getRootPath();
|
||||
if (root == null) {
|
||||
@@ -121,6 +122,10 @@ public abstract class ToolInstaller implements Describable<ToolInstaller>, Exten
|
||||
return root.child("tools").child(home);
|
||||
}
|
||||
|
||||
private String sanitize(String s) {
|
||||
return s != null ? s.replaceAll("[^A-Za-z0-9_.-]+", "_") : null;
|
||||
}
|
||||
|
||||
public ToolInstallerDescriptor<?> getDescriptor() {
|
||||
return (ToolInstallerDescriptor) Jenkins.getInstance().getDescriptorOrDie(getClass());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user