@@ -24,9 +24,13 @@ class LocalBinary {
24
24
System .getProperty ("java.io.tmpdir" )
25
25
};
26
26
27
- LocalBinary () throws LocalException {
27
+ LocalBinary (String path ) throws LocalException {
28
28
initialize ();
29
- getBinary ();
29
+ if (path != "" ) {
30
+ getBinaryOnPath (path );
31
+ } else {
32
+ getBinary ();
33
+ }
30
34
checkBinary ();
31
35
}
32
36
@@ -111,6 +115,14 @@ private boolean validateBinary() throws LocalException{
111
115
}
112
116
}
113
117
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
+
114
126
private void getBinary () throws LocalException {
115
127
String destParentDir = getAvailableDirectory ();
116
128
binaryPath = destParentDir + "/BrowserStackLocal" ;
@@ -120,7 +132,7 @@ private void getBinary() throws LocalException {
120
132
}
121
133
122
134
if (!new File (binaryPath ).exists ()) {
123
- downloadBinary (destParentDir );
135
+ downloadBinary (destParentDir , false );
124
136
}
125
137
}
126
138
@@ -147,23 +159,26 @@ private boolean makePath(String path) {
147
159
}
148
160
}
149
161
150
- private void downloadBinary (String destParentDir ) throws LocalException {
162
+ private void downloadBinary (String destParentDir , Boolean custom ) throws LocalException {
151
163
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
+ }
159
173
}
174
+ URL url = new URL (httpPath );
160
175
161
176
File f = new File (source );
162
177
FileUtils .copyURLToFile (url , f );
163
178
164
179
changePermissions (binaryPath );
165
180
} 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 () );
167
182
}
168
183
}
169
184
0 commit comments