Search in sources :

Example 11 with OSProcessHandler

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;
    }
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler)

Example 12 with OSProcessHandler

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;
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 13 with OSProcessHandler

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;
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) Key(com.intellij.openapi.util.Key) RelativePoint(com.intellij.ui.awt.RelativePoint) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with OSProcessHandler

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);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExecutionException(com.intellij.execution.ExecutionException)

Example 15 with OSProcessHandler

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;
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

OSProcessHandler (com.intellij.execution.process.OSProcessHandler)55 ExecutionException (com.intellij.execution.ExecutionException)25 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)24 ProcessEvent (com.intellij.execution.process.ProcessEvent)24 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)23 NotNull (org.jetbrains.annotations.NotNull)18 Key (com.intellij.openapi.util.Key)14 ProcessHandler (com.intellij.execution.process.ProcessHandler)6 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 File (java.io.File)6 Module (com.intellij.openapi.module.Module)5 Sdk (com.intellij.openapi.projectRoots.Sdk)5 IOException (java.io.IOException)5 ProgramRunner (com.intellij.execution.runners.ProgramRunner)4 Nullable (org.jetbrains.annotations.Nullable)4 Executor (com.intellij.execution.Executor)3 RunContentExecutor (com.intellij.execution.RunContentExecutor)3 KillableColoredProcessHandler (com.intellij.execution.process.KillableColoredProcessHandler)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3