Skip to content
Permalink
Browse files
Fixed instantiation of the home variables
Resolves https://issues.jenkins-ci.org/browse/JENKINS-18815

Signed-off-by: Oleg Nenashev <nenashev@synopsys.com>
  • Loading branch information
oleg-nenashev committed Jul 18, 2013
1 parent f8a4616 commit 194b4e72684d4aebab0e06eb258fb93f052662d5
@@ -58,6 +58,8 @@
*/
private final String exportedPaths;

private transient String correctedHome;

@DataBoundConstructor
public CustomTool(String name, String home, List properties,
String exportedPaths) {
@@ -68,8 +70,15 @@ public CustomTool(String name, String home, List properties,
public String getExportedPaths() {
return exportedPaths;
}

@Override
public String getHome() {
return (correctedHome != null) ? correctedHome : super.getHome();
}


public void correctHome(PathsList pathList) {
correctedHome = pathList.getHomeDir();
}

@Override
public CustomTool forEnvironment(EnvVars environment) {
@@ -159,6 +168,10 @@ public PathsList invoke(File f, VirtualChannel channel)
String[] res = new String[items.length];
int i=0;
for (String item : items) {
if (item.isEmpty()) {
continue;
}

File file = new File(item);
if (!file.isAbsolute()) {
file = new File (getHome(), item);
@@ -171,20 +184,13 @@ public PathsList invoke(File f, VirtualChannel channel)
res[i]=file.getAbsolutePath();
i++;
}
return new PathsList(res);

/**
* Previous implementation:
* FileSet fs = Util.createFileSet(new File(getHome()),exportedPaths);
* DirectoryScanner ds = fs.getDirectoryScanner();
-- added: ds.scan();
*/
// resolve home dir
File homeDir = new File(getHome());
return new PathsList(res, homeDir.getAbsolutePath());
};
});

// be extra greedy in case they added "./. or . or ./"
pathsFound.add(getHome());

return pathsFound;
}

@@ -145,10 +145,12 @@ public Launcher decorateLauncher(AbstractBuild build, final Launcher launcher,
throw new AbortException(ex.getMessage());
}

// Get infromation about pathes from target executor
paths.add(installed.getPaths(Computer.currentComputer().getNode()));
installed.correctHome(paths);
listener.getLogger().println("[CustomTools] - "+tool.getName()+" is installed at "+ installed.getHome());

homes.put(tool.getName()+"_HOME", installed.getHome());
paths.add(installed.getPaths(Computer.currentComputer().getNode()));
}


@@ -27,45 +27,58 @@
*/
public class PathsList implements Serializable {
public List<String> paths;
/*Restored home dir*/
public String homeDir;
public String pathSeparator;
public String separator;

public static final PathsList EMPTY = new PathsList(new String[0]);
public static final PathsList EMPTY = new PathsList(new String[0], null);

/**
* Constructor. Sets system's default separator and pathSeparator
* @param paths List of paths to be returned
*/
public PathsList(String[] paths) {
this(paths, File.pathSeparator, File.separator);
public PathsList(String[] paths, String homeDir) {
this(paths, File.pathSeparator, File.separator, homeDir);
}

/**
* Empty constructor. doesn't set pathSeparator and separator
*/
public PathsList() {
this.paths = new ArrayList<String>();
this.pathSeparator = null;
this.separator = null;
this(new String[0], null, null, null);
}

public PathsList(String[] paths, String pathSeparator, String separator) {
public PathsList(String[] paths, String pathSeparator, String separator, String homeDir) {
this.paths = new ArrayList<String>(Arrays.asList(paths));
this.pathSeparator = pathSeparator;
this.separator = separator;
this.homeDir = homeDir;
}


public String getHomeDir() {
return homeDir;
}

public boolean add(String path) {
return paths.add(path);
}

/**
* Adds PathsList and overrides null variables.
* @param pathsList PathsList to be added
* @return True if
*/
public boolean add(PathsList pathsList) {
if (pathSeparator == null) {
pathSeparator = pathsList.pathSeparator;
}
if (separator == null) {
separator = pathsList.separator;
}
if (homeDir == null) {
homeDir = pathsList.homeDir;
}
return this.paths.addAll(pathsList.paths);
}

0 comments on commit 194b4e7

Please sign in to comment.