Skip to content

Commit 3ffdab3

Browse files
authored
Merge pull request #56 from AdityaHirapara/LOC-1636_Alpine_binary
Add alpine support with fix and --source option
2 parents 1de4e8f + 4895633 commit 3ffdab3

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/main/java/com/browserstack/local/Local.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class Local {
2222

2323
private LocalProcess proc = null;
2424

25+
// Current version of binding package, used for --source option of binary
26+
private final String packageVersion = "1.0.6";
2527
private final Map<String, String> parameters;
2628
private final Map<String, String> avoidValueParameters;
2729

@@ -138,6 +140,8 @@ private void makeCommand(Map<String, String> options, String opCode) {
138140
command.add(opCode);
139141
command.add("--key");
140142
command.add(options.get("key"));
143+
command.add("--source");
144+
command.add("java-" + packageVersion);
141145

142146
for (Map.Entry<String, String> opt : options.entrySet()) {
143147
String parameter = opt.getKey().trim();
@@ -176,8 +180,14 @@ private boolean isProcessRunning(int pid) throws Exception {
176180
}
177181
else {
178182
//ps exit code 0 if process exists, 1 if it doesn't
183+
cmd.add("/bin/sh");
184+
cmd.add("-c");
179185
cmd.add("ps");
180-
cmd.add("-p");
186+
cmd.add("-o");
187+
cmd.add("pid=");
188+
cmd.add("|");
189+
cmd.add("grep");
190+
cmd.add("-w");
181191
cmd.add(String.valueOf(pid));
182192
}
183193

src/main/java/com/browserstack/local/LocalBinary.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class LocalBinary {
1212

13-
private static final String BIN_URL = "https://s3.amazonaws.com/browserStack/browserstack-local/";
13+
private static final String BIN_URL = "https://bstack-local-prod.s3.amazonaws.com/";
1414

1515
private String httpPath;
1616

@@ -41,14 +41,36 @@ private void initialize() throws LocalException {
4141
binFileName = "BrowserStackLocal-darwin-x64";
4242
} else if (osname.contains("linux")) {
4343
String arch = System.getProperty("os.arch");
44-
binFileName = "BrowserStackLocal-linux-" + (arch.contains("64") ? "x64" : "ia32");
44+
if (arch.contains("64")) {
45+
if (isAlpine()) {
46+
binFileName = "BrowserStackLocal-alpine";
47+
} else {
48+
binFileName = "BrowserStackLocal-linux-x64";
49+
}
50+
} else {
51+
binFileName = "BrowserStackLocal-linux-ia32";
52+
}
4553
} else {
4654
throw new LocalException("Failed to detect OS type");
4755
}
4856

4957
httpPath = BIN_URL + binFileName;
5058
}
5159

60+
private boolean isAlpine() {
61+
String[] cmd = { "/bin/sh", "-c", "grep -w \"NAME\" /etc/os-release" };
62+
boolean flag = false;
63+
64+
try {
65+
Process os = Runtime.getRuntime().exec(cmd);
66+
BufferedReader stdout = new BufferedReader(new InputStreamReader(os.getInputStream()));
67+
68+
flag = stdout.readLine().contains("Alpine");
69+
} finally {
70+
return flag;
71+
}
72+
}
73+
5274
private void checkBinary() throws LocalException{
5375
boolean binaryWorking = validateBinary();
5476

0 commit comments

Comments
 (0)