Android module: stop ddms process for unix systems
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.jet.compiler;
|
||||
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.compiler.run.RunUtils;
|
||||
import org.jetbrains.jet.compiler.run.result.RunResult;
|
||||
|
||||
@@ -31,6 +32,7 @@ import java.util.regex.Pattern;
|
||||
public class OutputUtils {
|
||||
|
||||
private final static Pattern EMULATOR_PATTERN = Pattern.compile("emulator-([0-9])*");
|
||||
private final static Pattern EMULATOR_PROCESS_PATTERN = Pattern.compile("\\w*[\\s]+([0-9]*) .* java .* emulator .*");
|
||||
|
||||
public static boolean isResultOk(String output) {
|
||||
return !(output.contains("BUILD FAILED") || output.contains("Build failed"));
|
||||
@@ -49,7 +51,7 @@ public class OutputUtils {
|
||||
commandLineForListOfDevices.addParameter("devices");
|
||||
RunResult runResult = RunUtils.execute(commandLineForListOfDevices);
|
||||
checkResult(runResult);
|
||||
|
||||
|
||||
Matcher matcher = EMULATOR_PATTERN.matcher(runResult.getOutput());
|
||||
while (matcher.find()) {
|
||||
System.out.println("Stopping redundant emulator...");
|
||||
@@ -73,6 +75,17 @@ public class OutputUtils {
|
||||
}
|
||||
checkResult(RunUtils.execute(commandLineForListOfDevices));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getPidFromPsCommand(String output) {
|
||||
if (!output.isEmpty()) {
|
||||
Matcher matcher = EMULATOR_PROCESS_PATTERN.matcher(output);
|
||||
if (matcher.find()) {
|
||||
return matcher.group(1);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private OutputUtils() {
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.jet.compiler.run.result.RunResult;
|
||||
*/
|
||||
|
||||
public class Emulator {
|
||||
|
||||
|
||||
private final PathManager pathManager;
|
||||
|
||||
public Emulator(PathManager pathManager) {
|
||||
@@ -69,7 +69,7 @@ public class Emulator {
|
||||
commandLine.addParameter("wait-for-device");
|
||||
return commandLine;
|
||||
}
|
||||
|
||||
|
||||
private GeneralCommandLine getStopCommandForAdb() {
|
||||
GeneralCommandLine commandLine = new GeneralCommandLine();
|
||||
String adbCmdName = SystemInfo.isWindows ? "adb.exe" : "adb";
|
||||
@@ -117,5 +117,42 @@ public class Emulator {
|
||||
OutputUtils.checkResult(RunUtils.execute(getStopCommand()));
|
||||
System.out.println("Stopping adb...");
|
||||
OutputUtils.checkResult(RunUtils.execute(getStopCommandForAdb()));
|
||||
if (SystemInfo.isUnix) {
|
||||
finishProcess("emulator-arm");
|
||||
finishProcess("adb");
|
||||
stopDdmsProcess();
|
||||
}
|
||||
}
|
||||
|
||||
//Only for Unix
|
||||
private void stopDdmsProcess() {
|
||||
GeneralCommandLine listOfEmulatorProcess = new GeneralCommandLine();
|
||||
listOfEmulatorProcess.setExePath("sh");
|
||||
listOfEmulatorProcess.addParameter("-c");
|
||||
listOfEmulatorProcess.addParameter("ps aux | grep emulator");
|
||||
RunResult runResult = RunUtils.execute(listOfEmulatorProcess);
|
||||
OutputUtils.checkResult(runResult);
|
||||
String pidFromPsCommand = OutputUtils.getPidFromPsCommand(runResult.getOutput());
|
||||
if (pidFromPsCommand != null) {
|
||||
GeneralCommandLine killCommand = new GeneralCommandLine();
|
||||
killCommand.setExePath("kill");
|
||||
killCommand.addParameter(pidFromPsCommand);
|
||||
OutputUtils.checkResult(RunUtils.execute(killCommand));
|
||||
}
|
||||
}
|
||||
|
||||
//Only for Unix
|
||||
private void finishProcess(String processName) {
|
||||
GeneralCommandLine pidOfProcess = new GeneralCommandLine();
|
||||
pidOfProcess.setExePath("pidof");
|
||||
pidOfProcess.addParameter(processName);
|
||||
RunResult runResult = RunUtils.execute(pidOfProcess);
|
||||
String pid = runResult.getOutput().substring(("pidof " + processName).length());
|
||||
if (pid.length() > 1) {
|
||||
GeneralCommandLine killCommand = new GeneralCommandLine();
|
||||
killCommand.setExePath("kill");
|
||||
killCommand.addParameter(pid);
|
||||
OutputUtils.checkResult(RunUtils.execute(killCommand));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user