88import java .util .List ;
99import java .util .Map ;
1010import java .util .Set ;
11+ import java .io .File ;
12+ import java .io .FileReader ;
13+ import java .io .FileWriter ;
1114
1215class Local {
1316
1417 Process BrowserStackLocal = null ;
1518 List <String > command ;
19+ String logFilePath ;
1620 HashMap <String , String > parameters ;
1721
1822 void start (HashMap <String ,String > options ) throws Exception {
19- LocalBinary lb = new LocalBinary ();
2023 command = new ArrayList <String >();
21- command .add (lb .binary_path );
22- command .add (options .get ("key" ));
24+
25+ if (options .get ("binarypath" ) != null ){
26+ command .add (options .get ("binarypath" ));
27+ }
28+ else {
29+ LocalBinary lb = new LocalBinary ();
30+ command .add (lb .binary_path );
31+ }
32+
33+ logFilePath = options .get ("logfile" ) == null ? (System .getProperty ("user.dir" ) + "/local.log" ) : options .get ("logfile" );
34+ command .add ("-logFile" );
35+ command .add (logFilePath );
2336
37+ command .add (options .get ("key" ));
2438 makeCommand (options );
2539
2640 if (BrowserStackLocal == null ){
2741 ProcessBuilder processBuilder = new ProcessBuilder (command );
2842
29- System .out .println ("Setting up Local Testing connection..." );
43+ if ((new File (logFilePath )).exists ()){
44+ FileWriter f = new FileWriter (logFilePath );
45+ f .write ("" );
46+ f .close ();
47+ }
48+
3049 BrowserStackLocal = processBuilder .start ();
31- BufferedReader reader = new BufferedReader (new InputStreamReader (BrowserStackLocal .getInputStream ()));
50+ FileReader f = new FileReader (logFilePath );
51+ BufferedReader reader = new BufferedReader (f );
3252 String string ;
3353 int j = 0 ;
34- while ((string = reader .readLine ()) != null ) {
54+ while (true ) {
55+ string = reader .readLine ();
56+ if (string == null ) continue ;
57+
3558 if (string .equalsIgnoreCase ("Press Ctrl-C to exit" )) {
36- System . out . println ( "Local Testing connection has been established." );
59+ f . close ( );
3760 break ;
3861 }
3962
4063 if (string .contains ("*** Error" )){
64+ f .close ();
4165 throw new BrowserStackLocalException (string );
4266 }
43- if (j ++ > 20 ) {
44- throw new BrowserStackLocalException ("Could not start BrowserStackLocal" );
45- }
4667 }
4768
4869 }
@@ -51,7 +72,6 @@ void start(HashMap<String,String> options) throws Exception {
5172 void stop (){
5273 if (BrowserStackLocal != null ) {
5374 BrowserStackLocal .destroy ();
54- System .out .println ("Disconnected successfully" );
5575 }
5676 }
5777
@@ -80,7 +100,6 @@ void init(){
80100 parameters .put ("proxyUser" , "-proxyUser" );
81101 parameters .put ("proxyPass" , "-proxyPass" );
82102 parameters .put ("hosts" , "-hosts" );
83- parameters .put ("logfile" , "-logfile" );
84103 }
85104
86105 Local () throws Exception {
0 commit comments