Skip to content

Commit 6c81ebb

Browse files
committedNov 25, 2013
Merge pull request #13 from synopsys-arc-oss/JENKINS_20560_FIX
[FIXED JENKINS-20560] - Custom-tools should not override global paths in...
2 parents 5d9a150 + 84cac80 commit 6c81ebb

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed
 

‎src/main/java/com/cloudbees/jenkins/plugins/customtools/CustomToolInstallWrapper.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,27 @@ public Proc launch(ProcStarter starter) throws IOException {
214214
vars = new EnvVars();
215215
}
216216

217-
// HACK: Avoids issue with invalid separators in EnvVars::override in case of different master/slave
218-
String overridenPaths = vars.get("PATH");
219-
overridenPaths += paths.toListString();
220-
vars.override("PATH", overridenPaths);
217+
// Inject paths
218+
final String injectedPaths = paths.toListString();
219+
if (injectedPaths != null) {
220+
vars.override("PATH+", injectedPaths);
221+
}
222+
223+
// Inject additional variables
221224
vars.putAll(homes);
222225
vars.putAll(versions);
223-
224-
// Inject additional variables
225226
for (EnvVariablesInjector injector : additionalVarInjectors) {
226227
injector.Inject(vars);
227228
}
229+
230+
// Override paths to prevent JENKINS-20560
231+
if (vars.containsKey("PATH")) {
232+
final String overallPaths=vars.get("PATH");
233+
vars.remove("PATH");
234+
vars.put("PATH+", overallPaths);
235+
}
228236

229-
return getInner().launch(starter.envs(Util.mapToEnv(vars)));
237+
return getInner().launch(starter.envs(vars));
230238
}
231239

232240
private EnvVars toEnvVars(String[] envs) {

‎src/main/java/com/synopsys/arc/jenkinsci/plugins/customtools/PathsList.java

+15-9
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,38 @@ public boolean add(String path) {
6868
/**
6969
* Adds PathsList and overrides null variables.
7070
* @param pathsList PathsList to be added
71-
* @return True if
71+
* @return True if the paths list has been modified after the tool installation
7272
*/
73+
//TODO: Is it a bug?
7374
public boolean add(PathsList pathsList) {
7475
if (pathSeparator == null) {
7576
pathSeparator = pathsList.pathSeparator;
7677
}
7778
if (separator == null) {
7879
separator = pathsList.separator;
7980
}
81+
// Add homeDir as well (legacy behavior)
8082
if (pathsList.homeDir != null) {
8183
this.paths.add(pathsList.homeDir);
8284
}
8385

8486
return this.paths.addAll(pathsList.paths);
8587
}
8688

89+
/**
90+
* Gets the list of installed tools
91+
* @return A list with valid delimiters or null if paths is empty
92+
*/
8793
public String toListString() {
88-
StringBuilder builder = new StringBuilder(paths.size()*2);
89-
for ( String path : paths) {
90-
builder.append(pathSeparator);
91-
builder.append(path);
92-
}
94+
if (paths.isEmpty()) {
95+
return null;
96+
}
9397

94-
// Add homeDir as well (legacy behavior)
95-
builder.append(pathSeparator);
96-
98+
StringBuilder builder = new StringBuilder();
99+
for ( String path : paths) {
100+
builder.append(path);
101+
builder.append(pathSeparator);
102+
}
97103
return builder.toString();
98104
}
99105
}

‎src/test/java/com/cloudbees/jenkins/plugins/customtools/CustomToolInstallWrapperTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public void testNestedWrapperReverse() throws Exception {
5858
nestedWrapperTestImpl(wrappers, true);
5959
}
6060

61+
62+
6163
/**
6264
* Tests custom tools with wrapper, which calls wrapper without
6365
* specifying of envs.
@@ -71,6 +73,14 @@ public void testNestedLauncherCalls() throws Exception {
7173
nestedWrapperTestImpl(wrappers, false);
7274
}
7375

76+
//@Bug(20560)
77+
public void testEmptyToolsList() throws Exception {
78+
List<BuildWrapper> wrappers = new ArrayList<BuildWrapper>(0);
79+
wrappers.add(new CommandCallerInstaller());
80+
wrappers.add(new CustomToolInstallWrapper(null, MulticonfigWrapperOptions.DEFAULT, false));
81+
nestedWrapperTestImpl(wrappers, false);
82+
}
83+
7484
/**
7585
* Implements tests for nested wrappers.
7686
* The test checks that environment variables have been set correctly.

0 commit comments

Comments
 (0)
Please sign in to comment.