@@ -140,43 +140,29 @@ public String getDefaultSauceConnectLogDirectory() {
140140 private static final String SAUCE_CONNECT_PREFIX = "sauce-connect-" ;
141141 public static final String SAUCE_CONNECT = SAUCE_CONNECT_PREFIX + CURRENT_SC_VERSION ;
142142
143- private static final int DEFAULT_API_PORT = 9000 ;
144- private int apiPort ;
145-
146143 /** Constructs a new instance with quiet mode disabled. */
147144 public SauceConnectManager () {
148145 this (false );
149146 }
150147
151- /**
152- * Constructs a new instance with quiet mode disabled.
153- *
154- * @param runner System which runs SauceConnect, this info is added to '--metadata runner=' argument
155- */
156- public SauceConnectManager (String runner ) {
157- this (false , runner , DEFAULT_API_PORT );
158- }
159-
160148 /**
161149 * Constructs a new instance.
162150 *
163151 * @param quietMode indicates whether Sauce Connect output should be suppressed
164152 */
165153 public SauceConnectManager (boolean quietMode ) {
166- this (quietMode , "jenkins" , DEFAULT_API_PORT );
154+ this (quietMode , "jenkins" );
167155 }
168156
169157 /**
170158 * Constructs a new instance.
171159 *
172160 * @param quietMode indicates whether Sauce Connect output should be suppressed
173161 * @param runner System which runs SauceConnect, this info is added to '--metadata runner=' argument
174- * @param apiPort Port the Sauce Connect process will listen on
175162 */
176- public SauceConnectManager (boolean quietMode , String runner , int apiPort ) {
163+ public SauceConnectManager (boolean quietMode , String runner ) {
177164 super (quietMode );
178165 this .runner = runner ;
179- this .apiPort = apiPort ;
180166 }
181167
182168 /**
@@ -241,17 +227,13 @@ protected Process prepAndCreateProcess(
241227 }
242228 }
243229
244- if ( apiPort != 0 ) {
245- this .apiPort = apiPort ;
246- }
247-
248230 // although we are setting the working directory, we need to specify the full path to the exe
249231 String [] args = {sauceConnectBinary .getPath ()};
250232 if (legacy ) {
251- args = generateSauceConnectArgsLegacy (args , username , accessKey , options );
233+ args = generateSauceConnectArgsLegacy (args , username , accessKey , options , apiPort );
252234 args = addExtraInfoLegacy (args );
253235 } else {
254- args = generateSauceConnectArgs (args , username , accessKey , options );
236+ args = generateSauceConnectArgs (args , username , accessKey , options , apiPort );
255237 args = addExtraInfo (args );
256238 }
257239
@@ -343,12 +325,13 @@ public static String getLatestSauceConnectVersion() {
343325 * @param username name of the user which launched Sauce Connect
344326 * @param accessKey the access key for the Sauce user
345327 * @param options command line args specified by the user
328+ * @param apiPort specify the port the Sauce Connect API will listen on
346329 * @return String array representing the command line args to be used to launch Sauce Connect
347330 */
348331 protected String [] generateSauceConnectArgs (
349- String [] args , String username , String accessKey , String options ) {
332+ String [] args , String username , String accessKey , String options , int apiPort ) {
350333 String [] result =
351- joinArgs (args , "run" , "--username" , username .trim (), "--access-key" , accessKey .trim (), "--api-address" , ":" + String .valueOf (this . apiPort ));
334+ joinArgs (args , "run" , "--username" , username .trim (), "--access-key" , accessKey .trim (), "--api-address" , ":" + String .valueOf (apiPort ));
352335 result = addElement (result , options );
353336 return result ;
354337 }
@@ -367,10 +350,10 @@ protected String[] addExtraInfo(String[] args) {
367350 */
368351 @ Deprecated
369352 protected String [] generateSauceConnectArgsLegacy (
370- String [] args , String username , String accessKey , String options ) {
353+ String [] args , String username , String accessKey , String options , int apiPort ) {
371354 String [] result ;
372355
373- result = joinArgs (args , "legacy" , "--user" , username .trim (), "--api-key" , accessKey .trim (), "--status-address" , "0.0.0.0:" + String .valueOf (this . apiPort ));
356+ result = joinArgs (args , "legacy" , "--user" , username .trim (), "--api-key" , accessKey .trim (), "--status-address" , "0.0.0.0:" + String .valueOf (apiPort ));
374357 result = addElement (result , options );
375358 return result ;
376359 }
0 commit comments