File tree 3 files changed +40
-16
lines changed
cloudbees/jenkins/plugins/customtools
synopsys/arc/jenkinsci/plugins/customtools
test/java/com/cloudbees/jenkins/plugins/customtools
3 files changed +40
-16
lines changed Original file line number Diff line number Diff line change @@ -214,19 +214,27 @@ public Proc launch(ProcStarter starter) throws IOException {
214
214
vars = new EnvVars ();
215
215
}
216
216
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
221
224
vars .putAll (homes );
222
225
vars .putAll (versions );
223
-
224
- // Inject additional variables
225
226
for (EnvVariablesInjector injector : additionalVarInjectors ) {
226
227
injector .Inject (vars );
227
228
}
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
+ }
228
236
229
- return getInner ().launch (starter .envs (Util . mapToEnv ( vars ) ));
237
+ return getInner ().launch (starter .envs (vars ));
230
238
}
231
239
232
240
private EnvVars toEnvVars (String [] envs ) {
Original file line number Diff line number Diff line change @@ -68,32 +68,38 @@ public boolean add(String path) {
68
68
/**
69
69
* Adds PathsList and overrides null variables.
70
70
* @param pathsList PathsList to be added
71
- * @return True if
71
+ * @return True if the paths list has been modified after the tool installation
72
72
*/
73
+ //TODO: Is it a bug?
73
74
public boolean add (PathsList pathsList ) {
74
75
if (pathSeparator == null ) {
75
76
pathSeparator = pathsList .pathSeparator ;
76
77
}
77
78
if (separator == null ) {
78
79
separator = pathsList .separator ;
79
80
}
81
+ // Add homeDir as well (legacy behavior)
80
82
if (pathsList .homeDir != null ) {
81
83
this .paths .add (pathsList .homeDir );
82
84
}
83
85
84
86
return this .paths .addAll (pathsList .paths );
85
87
}
86
88
89
+ /**
90
+ * Gets the list of installed tools
91
+ * @return A list with valid delimiters or null if paths is empty
92
+ */
87
93
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
+ }
93
97
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
+ }
97
103
return builder .toString ();
98
104
}
99
105
}
Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ public void testNestedWrapperReverse() throws Exception {
58
58
nestedWrapperTestImpl (wrappers , true );
59
59
}
60
60
61
+
62
+
61
63
/**
62
64
* Tests custom tools with wrapper, which calls wrapper without
63
65
* specifying of envs.
@@ -71,6 +73,14 @@ public void testNestedLauncherCalls() throws Exception {
71
73
nestedWrapperTestImpl (wrappers , false );
72
74
}
73
75
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
+
74
84
/**
75
85
* Implements tests for nested wrappers.
76
86
* The test checks that environment variables have been set correctly.
You can’t perform that action at this time.
0 commit comments