Skip to content

Add alpine support with fix and --source option #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/main/java/com/browserstack/local/Local.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class Local {

private LocalProcess proc = null;

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

Expand Down Expand Up @@ -138,6 +140,8 @@ private void makeCommand(Map<String, String> options, String opCode) {
command.add(opCode);
command.add("--key");
command.add(options.get("key"));
command.add("--source");
command.add("java-" + packageVersion);

for (Map.Entry<String, String> opt : options.entrySet()) {
String parameter = opt.getKey().trim();
Expand Down Expand Up @@ -176,8 +180,14 @@ private boolean isProcessRunning(int pid) throws Exception {
}
else {
//ps exit code 0 if process exists, 1 if it doesn't
cmd.add("/bin/sh");
cmd.add("-c");
cmd.add("ps");
cmd.add("-p");
cmd.add("-o");
cmd.add("pid=");
cmd.add("|");
cmd.add("grep");
cmd.add("-w");
cmd.add(String.valueOf(pid));
}

Expand Down
26 changes: 24 additions & 2 deletions src/main/java/com/browserstack/local/LocalBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class LocalBinary {

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

private String httpPath;

Expand Down Expand Up @@ -41,14 +41,36 @@ private void initialize() throws LocalException {
binFileName = "BrowserStackLocal-darwin-x64";
} else if (osname.contains("linux")) {
String arch = System.getProperty("os.arch");
binFileName = "BrowserStackLocal-linux-" + (arch.contains("64") ? "x64" : "ia32");
if (arch.contains("64")) {
if (isAlpine()) {
binFileName = "BrowserStackLocal-alpine";
} else {
binFileName = "BrowserStackLocal-linux-x64";
}
} else {
binFileName = "BrowserStackLocal-linux-ia32";
}
} else {
throw new LocalException("Failed to detect OS type");
}

httpPath = BIN_URL + binFileName;
}

private boolean isAlpine() {
String[] cmd = { "/bin/sh", "-c", "grep -w \"NAME\" /etc/os-release" };
boolean flag = false;

try {
Process os = Runtime.getRuntime().exec(cmd);
BufferedReader stdout = new BufferedReader(new InputStreamReader(os.getInputStream()));

flag = stdout.readLine().contains("Alpine");
} finally {
return flag;
}
}

private void checkBinary() throws LocalException{
boolean binaryWorking = validateBinary();

Expand Down