package se.vidstige.jadb;

import java.io.IOException;
import java.util.Map;

/**
 * Launches the ADB server
 */
public class AdbServerLauncher {
    private final String executable;
    private Subprocess subprocess;

    public AdbServerLauncher(Subprocess subprocess, Map<String, String> environment) {
        this.subprocess = subprocess;
        this.executable = findAdbExecutable(environment);
    }

    private static String findAdbExecutable(Map<String, String> environment) {
        String android_home = environment.get("ANDROID_HOME");
        if (android_home == null || android_home.equals("")) {
            return "adb";
        }
        return android_home + "/platform-tools/adb";
    }

    public void launch() throws IOException, InterruptedException {
        Process p = subprocess.execute(new String[]{executable, "start-server"});
        p.waitFor();
        int exitValue = p.exitValue();
        if (exitValue != 0) throw new IOException("adb exited with exit code: " + exitValue);
    }
}

@@ -220,104 +220,448 @@
     
-public AdbServerLauncher(Subprocess subprocess, Map%3CString, String%3E environment) %7B%0A        this.
+/**%0A     * Creates a new launcher loading ADB from the environment.%0A     * %0A     * @param subprocess the sub-process.%0A     * @param environment the environment to use to locate the ADB executable.%0A     */%0A    public AdbServerLauncher(Subprocess subprocess, Map%3CString, String%3E environment) %7B%0A        this(subprocess, findAdbExecutable(environment));%0A    %7D%0A%0A    /**%0A     * Creates a new launcher with the specified ADB.%0A     *%0A     * @param 
 subp
@@ -671,78 +671,241 @@
 ess 
-=
+the
  sub
+-
 process
-;
+.
 %0A     
-   this.executable = findAdbExecutable(environment)
+* @param executable the location of the ADB executable.%0A     */%0A    public AdbServerLauncher(Subprocess subprocess, String executable) %7B%0A        this.subprocess = subprocess;%0A        this.executable = executable
 ;%0A  

Allow the location of the ADB binary to be specified.