@@ -24,9 +24,13 @@ class LocalBinary {
2424 System .getProperty ("java.io.tmpdir" )
2525 };
2626
27- LocalBinary () throws LocalException {
27+ LocalBinary (String path ) throws LocalException {
2828 initialize ();
29- getBinary ();
29+ if (path != "" ) {
30+ getBinaryOnPath (path );
31+ } else {
32+ getBinary ();
33+ }
3034 checkBinary ();
3135 }
3236
@@ -111,6 +115,14 @@ private boolean validateBinary() throws LocalException{
111115 }
112116 }
113117
118+ private void getBinaryOnPath (String path ) throws LocalException {
119+ binaryPath = path ;
120+
121+ if (!new File (binaryPath ).exists ()) {
122+ downloadBinary (binaryPath , true );
123+ }
124+ }
125+
114126 private void getBinary () throws LocalException {
115127 String destParentDir = getAvailableDirectory ();
116128 binaryPath = destParentDir + "/BrowserStackLocal" ;
@@ -120,7 +132,7 @@ private void getBinary() throws LocalException {
120132 }
121133
122134 if (!new File (binaryPath ).exists ()) {
123- downloadBinary (destParentDir );
135+ downloadBinary (destParentDir , false );
124136 }
125137 }
126138
@@ -147,23 +159,26 @@ private boolean makePath(String path) {
147159 }
148160 }
149161
150- private void downloadBinary (String destParentDir ) throws LocalException {
162+ private void downloadBinary (String destParentDir , Boolean custom ) throws LocalException {
151163 try {
152- if (!new File (destParentDir ).exists ())
153- new File (destParentDir ).mkdirs ();
154-
155- URL url = new URL (httpPath );
156- String source = destParentDir + "/BrowserStackLocal" ;
157- if (isOSWindows ) {
158- source += ".exe" ;
164+ String source = destParentDir ;
165+ if (!custom ) {
166+ if (!new File (destParentDir ).exists ())
167+ new File (destParentDir ).mkdirs ();
168+
169+ source = destParentDir + "/BrowserStackLocal" ;
170+ if (isOSWindows ) {
171+ source += ".exe" ;
172+ }
159173 }
174+ URL url = new URL (httpPath );
160175
161176 File f = new File (source );
162177 FileUtils .copyURLToFile (url , f );
163178
164179 changePermissions (binaryPath );
165180 } catch (Exception e ) {
166- throw new LocalException ("Error trying to download BrowserStackLocal binary" );
181+ throw new LocalException ("Error trying to download BrowserStackLocal binary: " + e . getMessage () );
167182 }
168183 }
169184
0 commit comments