use of com.intellij.execution.process.OSProcessHandler in project intellij-community by JetBrains.
the class NativeFileWatcherImpl method shutdownProcess.
private void shutdownProcess() {
final OSProcessHandler processHandler = myProcessHandler;
if (processHandler != null) {
if (!processHandler.isProcessTerminated()) {
boolean killProcess = true;
try {
writeLine(EXIT_COMMAND);
killProcess = !processHandler.waitFor(500);
if (killProcess) {
LOG.warn("File watcher is still alive. Doing a force quit.");
}
} catch (IOException ignore) {
}
if (killProcess) {
processHandler.destroyProcess();
}
}
myProcessHandler = null;
}
}
use of com.intellij.execution.process.OSProcessHandler in project android by JetBrains.
the class AndroidSdkUtils method activateDdmsIfNecessary.
public static boolean activateDdmsIfNecessary(@NotNull Project project) {
if (AndroidEnableAdbServiceAction.isAdbServiceEnabled()) {
AndroidDebugBridge bridge = getDebugBridge(project);
if (bridge != null && AdbService.isDdmsCorrupted(bridge)) {
LOG.info("DDMLIB is corrupted and will be restarted");
AdbService.getInstance().restartDdmlib(project);
}
} else {
OSProcessHandler ddmsProcessHandler = AndroidRunDdmsAction.getDdmsProcessHandler();
if (ddmsProcessHandler != null) {
String message = "Monitor will be closed to enable ADB integration. Continue?";
int result = Messages.showYesNoDialog(project, message, "ADB Integration", Messages.getQuestionIcon());
if (result != Messages.YES) {
return false;
}
Runnable destroyingRunnable = () -> {
if (!ddmsProcessHandler.isProcessTerminated()) {
OSProcessManager.getInstance().killProcessTree(ddmsProcessHandler.getProcess());
ddmsProcessHandler.waitFor();
}
};
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(destroyingRunnable, "Closing Monitor", true, project)) {
return false;
}
setAdbServiceEnabled(project, true);
return true;
}
int result = Messages.showYesNoDialog(project, AndroidBundle.message("android.ddms.disabled.error"), AndroidBundle.message("android.ddms.disabled.dialog.title"), Messages.getQuestionIcon());
if (result != Messages.YES) {
return false;
}
setAdbServiceEnabled(project, true);
}
return true;
}
use of com.intellij.execution.process.OSProcessHandler in project android by JetBrains.
the class AndroidUtils method executeCommand.
@NotNull
public static ExecutionStatus executeCommand(@NotNull GeneralCommandLine commandLine, @Nullable final OutputProcessor processor, @Nullable WaitingStrategies.Strategy strategy) throws ExecutionException {
LOG.info(commandLine.getCommandLineString());
OSProcessHandler handler = new OSProcessHandler(commandLine);
final ProcessAdapter listener = new ProcessAdapter() {
@Override
public void onTextAvailable(final ProcessEvent event, final Key outputType) {
if (processor != null) {
final String message = event.getText();
processor.onTextAvailable(message);
}
}
};
if (!(strategy instanceof WaitingStrategies.DoNotWait)) {
handler.addProcessListener(listener);
}
handler.startNotify();
try {
if (!(strategy instanceof WaitingStrategies.WaitForever)) {
if (strategy instanceof WaitingStrategies.WaitForTime) {
handler.waitFor(((WaitingStrategies.WaitForTime) strategy).getTimeMs());
}
} else {
handler.waitFor();
}
} catch (ProcessCanceledException e) {
return ExecutionStatus.ERROR;
}
if (!handler.isProcessTerminated()) {
return ExecutionStatus.TIMEOUT;
}
if (!(strategy instanceof WaitingStrategies.DoNotWait)) {
handler.removeProcessListener(listener);
}
int exitCode = handler.getProcess().exitValue();
return exitCode == 0 ? ExecutionStatus.SUCCESS : ExecutionStatus.ERROR;
}
use of com.intellij.execution.process.OSProcessHandler in project intellij-community by JetBrains.
the class Tool method execute.
public void execute(AnActionEvent event, DataContext dataContext, long executionId, @Nullable final ProcessListener processListener) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return;
}
FileDocumentManager.getInstance().saveAllDocuments();
try {
if (isUseConsole()) {
ExecutionEnvironment environment = ExecutionEnvironmentBuilder.create(project, DefaultRunExecutor.getRunExecutorInstance(), new ToolRunProfile(this, dataContext)).build();
environment.setExecutionId(executionId);
environment.getRunner().execute(environment, new ProgramRunner.Callback() {
@Override
public void processStarted(RunContentDescriptor descriptor) {
ProcessHandler processHandler = descriptor.getProcessHandler();
if (processHandler != null && processListener != null) {
LOG.assertTrue(!processHandler.isStartNotified(), "ProcessHandler is already startNotified, the listener won't be correctly notified");
processHandler.addProcessListener(processListener);
}
}
});
} else {
GeneralCommandLine commandLine = createCommandLine(dataContext);
if (commandLine == null) {
return;
}
OSProcessHandler handler = new OSProcessHandler(commandLine);
handler.addProcessListener(new ToolProcessAdapter(project, synchronizeAfterExecution(), getName()));
if (processListener != null) {
handler.addProcessListener(processListener);
}
handler.startNotify();
}
} catch (ExecutionException ex) {
ExecutionErrorDialog.show(ex, ToolsBundle.message("tools.process.start.error"), project);
}
}
use of com.intellij.execution.process.OSProcessHandler in project intellij-community by JetBrains.
the class SimpleJavaParameters method createOSProcessHandler.
@NotNull
public OSProcessHandler createOSProcessHandler() throws ExecutionException {
OSProcessHandler processHandler = new OSProcessHandler(toCommandLine());
ProcessTerminatedListener.attach(processHandler);
return processHandler;
}
Aggregations