10
10
import org .apache .commons .lang3 .concurrent .LazyInitializer ;
11
11
import org .apache .commons .lang3 .concurrent .LazyInitializer .Builder ;
12
12
import org .json .JSONObject ;
13
+ import org .slf4j .Logger ;
13
14
14
- import java .io .BufferedInputStream ;
15
- import java .io .File ;
16
- import java .io .IOException ;
17
- import java .io .InputStream ;
18
- import java .io .PrintStream ;
15
+ import java .io .*;
19
16
import java .net .URI ;
17
+ import java .net .URL ;
20
18
import java .net .http .HttpClient ;
21
19
import java .net .http .HttpRequest ;
22
20
import java .net .http .HttpResponse ;
23
21
import java .nio .file .Files ;
24
22
import java .nio .file .Path ;
25
- import java .text .MessageFormat ;
26
23
import java .util .ArrayList ;
27
24
import java .util .Arrays ;
28
25
import java .util .HashMap ;
29
- import java .util .List ;
30
-
31
- import java .net .URL ;
32
26
33
27
/**
34
28
* Handles launching Sauce Connect (binary executable).
35
29
*
36
30
* @author Ross Rowe
37
31
*/
38
- public class SauceConnectManager extends AbstractSauceTunnelManager
39
- implements SauceTunnelManager {
32
+ public class SauceConnectManager extends AbstractSauceTunnelManager implements SauceTunnelManager {
40
33
private boolean useLatestSauceConnect = false ;
41
34
42
35
/** Remove all created files and directories on exit */
@@ -183,7 +176,7 @@ public SauceConnectManager(boolean quietMode) {
183
176
public SauceConnectManager (boolean quietMode , String runner , int apiPort ) {
184
177
super (quietMode );
185
178
this .runner = runner ;
186
- this .apiPort = DEFAULT_API_PORT ;
179
+ this .apiPort = apiPort ;
187
180
}
188
181
189
182
/**
@@ -192,7 +185,7 @@ public SauceConnectManager(boolean quietMode, String runner, int apiPort) {
192
185
* @param sauceConnectJar File which contains the Sauce Connect executables (typically the CI
193
186
* plugin Jar file)
194
187
* @param options the command line options used to launch Sauce Connect
195
- * @param printStream the output stream to send log messages
188
+ * @param logger used for logging
196
189
* @param sauceConnectPath if defined, Sauce Connect will be launched from the specified path and
197
190
* won't be extracted from the jar file
198
191
* @return new ProcessBuilder instance which will launch Sauce Connect
@@ -206,7 +199,7 @@ protected Process prepAndCreateProcess(
206
199
int apiPort ,
207
200
File sauceConnectJar ,
208
201
String options ,
209
- PrintStream printStream ,
202
+ Logger logger ,
210
203
String sauceConnectPath ,
211
204
boolean legacy )
212
205
throws SauceConnectException {
@@ -234,11 +227,11 @@ protected Process prepAndCreateProcess(
234
227
if (!sauceConnectBinary .exists ()) {
235
228
synchronized (this ) {
236
229
if (!sauceConnectBinary .exists ()) {
237
- extractZipFile (workingDirectory , operatingSystem );
230
+ extractZipFile (workingDirectory , operatingSystem , logger );
238
231
}
239
232
}
240
233
} else {
241
- logMessage ( printStream , sauceConnectBinary + " already exists, so not extracting" );
234
+ logger . info ( "File {} already exists, so not extracting", sauceConnectBinary );
242
235
}
243
236
} else {
244
237
sauceConnectBinary = new File (sauceConnectPath );
@@ -262,7 +255,7 @@ protected Process prepAndCreateProcess(
262
255
args = addExtraInfo (args );
263
256
}
264
257
265
- LOGGER .info ("Launching Sauce Connect {} {}" , getCurrentVersion (), hideSauceConnectCommandlineSecrets (args ));
258
+ logger .info ("Launching Sauce Connect {} {}" , getCurrentVersion (), hideSauceConnectCommandlineSecrets (args ));
266
259
return createProcess (args , sauceConnectBinary .getParentFile ());
267
260
} catch (IOException e ) {
268
261
throw new SauceConnectException (e );
@@ -400,7 +393,7 @@ protected String[] addExtraInfoLegacy(String[] args) {
400
393
* @return the directory containing the extracted files
401
394
* @throws IOException thrown if an error occurs extracting the files
402
395
*/
403
- public File extractZipFile (File workingDirectory , OperatingSystem operatingSystem ) throws IOException {
396
+ public File extractZipFile (File workingDirectory , OperatingSystem operatingSystem , Logger logger ) throws IOException {
404
397
String archiveFileName = operatingSystem .getFileName (useLatestSauceConnect );
405
398
File unzipDir = getUnzipDir (workingDirectory , operatingSystem );
406
399
unzipDir .mkdirs ();
@@ -417,8 +410,7 @@ public File extractZipFile(File workingDirectory, OperatingSystem operatingSyste
417
410
418
411
File sauceConnectBinary = new File (unzipDir , operatingSystem .getExecutable ());
419
412
if (!sauceConnectBinary .canExecute () && !sauceConnectBinary .setExecutable (true )) {
420
- LOGGER .warn ("Unable to set the execute permission for SauceConnect binary file located at {}" ,
421
- sauceConnectBinary );
413
+ logger .warn ("Unable to set the execute permission for SauceConnect binary file located at {}" , sauceConnectBinary );
422
414
}
423
415
return unzipDir ;
424
416
}
0 commit comments