Search in sources :

Example 51 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project flutter-intellij by flutter.

the class OpenInAndroidStudioAction method openFileInStudio.

private static void openFileInStudio(@NotNull VirtualFile file, @NotNull String androidStudioPath) {
    try {
        final GeneralCommandLine cmd;
        if (SystemInfo.isMac) {
            cmd = new GeneralCommandLine().withExePath("open").withParameters("-a", androidStudioPath, file.getPath());
        } else {
            cmd = new GeneralCommandLine().withExePath(androidStudioPath).withParameters(file.getPath());
        }
        final OSProcessHandler handler = new OSProcessHandler(cmd);
        handler.addProcessListener(new ProcessAdapter() {

            @Override
            public void processTerminated(@NotNull final ProcessEvent event) {
                if (event.getExitCode() != 0) {
                    FlutterMessages.showError("Error Opening", file.getPath());
                }
            }
        });
        handler.startNotify();
    } catch (ExecutionException ex) {
        FlutterMessages.showError("Error Opening", "Exception: " + ex.getMessage());
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException)

Example 52 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project flutter-intellij by flutter.

the class FlutterApp method start.

/**
 * Creates a process that will launch the flutter app.
 * <p>
 * (Assumes we are launching it in --machine mode.)
 */
@NotNull
public static FlutterApp start(@NotNull ExecutionEnvironment env, @NotNull Project project, @Nullable Module module, @NotNull RunMode mode, @NotNull FlutterDevice device, @NotNull GeneralCommandLine command, @NotNull String analyticsStart, @NotNull String analyticsStop) throws ExecutionException {
    LOG.info(analyticsStart + " " + project.getName() + " (" + mode.mode() + ")");
    LOG.info(command.toString());
    final ProcessHandler process = new OSProcessHandler(command);
    Disposer.register(project, process::destroyProcess);
    // Send analytics for the start and stop events.
    FlutterInitializer.sendAnalyticsAction(analyticsStart);
    final DaemonApi api = new DaemonApi(process);
    final FlutterApp app = new FlutterApp(project, module, mode, device, process, env, api);
    process.addProcessListener(new ProcessAdapter() {

        @Override
        public void processTerminated(@NotNull ProcessEvent event) {
            LOG.info(analyticsStop + " " + project.getName() + " (" + mode.mode() + ")");
            FlutterInitializer.sendAnalyticsAction(analyticsStop);
            // Send analytics about whether this session used the reload workflow, the restart workflow, or neither.
            final String workflowType = app.reloadCount > 0 ? "reload" : (app.restartCount > 0 ? "restart" : "none");
            FlutterInitializer.getAnalytics().sendEvent("workflow", workflowType);
        }
    });
    api.listen(process, new io.flutter.run.daemon.FlutterAppListener(app, project));
    return app;
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project moe-ide-integration by multi-os-engine.

the class MOERefreshXcodeProject method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Module module = (Module) dataContext.getData(LangDataKeys.MODULE.getName());
    if (module == null) {
        Messages.showErrorDialog("Failed to locate module", "Injecting/Refreshing Xcode Settings Error");
        return;
    }
    boolean isMaven = ModuleUtils.isMOEMavenModule(module);
    if (!isMaven) {
        ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {

            @Override
            public void run() {
                ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
                if (progress == null) {
                    progress = new EmptyProgressIndicator();
                }
                progress.pushState();
                try {
                    progress.setText(ACTION_PROGRESS_LABEL);
                    runInternal();
                } catch (final Throwable t) {
                    t.printStackTrace(System.err);
                    UIUtil.invokeLaterIfNeeded(new Runnable() {

                        @Override
                        public void run() {
                            String message = t.getMessage();
                            if (message == null || message.length() == 0) {
                                message = "Unknown error";
                            }
                            Messages.showErrorDialog(message, "Injecting/Refreshing Xcode Settings Error");
                            final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
                            toolWindow.show();
                        }
                    });
                } finally {
                    progress.popState();
                }
            }

            private void runInternal() throws IOException, ExecutionException {
                final GeneralCommandLine commandLine = MOEGradleRunner.construct(module, "moeUpdateXcodeSettings");
                final OSProcessHandler handler = new OSProcessHandler(commandLine);
                handler.setShouldDestroyProcessRecursively(true);
                // Configure output
                final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
                toolWindow.clear();
                handler.addProcessListener(new ProcessAdapter() {

                    @Override
                    public void onTextAvailable(ProcessEvent event, Key outputType) {
                        if (ProcessOutputTypes.STDERR.equals(outputType)) {
                            toolWindow.error(event.getText());
                        } else if (ProcessOutputTypes.STDOUT.equals(outputType)) {
                            toolWindow.log(event.getText());
                        }
                    }
                });
                handler.startNotify();
                // Start and wait
                handler.waitFor();
                final int exitValue = handler.getProcess().exitValue();
                if (exitValue != 0) {
                    throw new IOException(ACTION_TITLE + " finished with non-zero exit value (" + exitValue + ")");
                }
            }
        }, ACTION_TITLE, true, module.getProject());
    } else {
        CompilerTask compilerTask = new CompilerTask(module.getProject(), "", false, true, true, true);
        compilerTask.start(new Runnable() {

            @Override
            public void run() {
                MOEMavenTask task = new MOEMavenTask(module, ACTION_TITLE, false);
                task.setGoal("moe:updateXcodeSettings");
                if (!task.runTask()) {
                    ModuleUtils.runInDispatchedThread(new Runnable() {

                        @Override
                        public void run() {
                            Messages.showErrorDialog("Unable to refresh Xcode project", "Injecting/Refreshing Xcode Settings Error");
                        }
                    });
                }
            }
        }, null);
        ModuleUtils.runInDispatchedThread(new Runnable() {

            @Override
            public void run() {
                MOEMavenTask task = new MOEMavenTask(module, ACTION_TITLE, false);
                task.setGoal("moe:updateXcodeSettings");
                if (!task.runTask()) {
                    Messages.showErrorDialog("Unable to refresh Xcode project", "Injecting/Refreshing Xcode Settings Error");
                }
            }
        });
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) CompilerTask(com.intellij.compiler.progress.CompilerTask) IOException(java.io.IOException) MOEMavenTask(org.moe.idea.maven.MOEMavenTask) DataContext(com.intellij.openapi.actionSystem.DataContext) MOEToolWindow(org.moe.idea.ui.MOEToolWindow) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 54 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project moe-ide-integration by multi-os-engine.

the class MOEMavenExternalExecutor method execute.

public boolean execute(final ProgressIndicator indicator) {
    displayProgress();
    try {
        if (myParameterCreationError != null) {
            throw myParameterCreationError;
        }
        myProcessHandler = new OSProcessHandler(myJavaParameters.toCommandLine()) {

            @Override
            public void notifyTextAvailable(String text, Key outputType) {
                // todo move this logic to ConsoleAdapter class
                if (!myConsole.isSuppressed(text)) {
                    super.notifyTextAvailable(text, outputType);
                }
                updateProgress(indicator, text);
            }
        };
        myProcessHandler.setShouldDestroyProcessRecursively(true);
        myConsole.attachToProcess(myProcessHandler);
    } catch (ExecutionException e) {
        myConsole.systemMessage(MavenServerConsole.LEVEL_FATAL, RunnerBundle.message("external.startup.failed", e.getMessage()), null);
        return false;
    }
    start();
    IndicatorHandler indicatorHandler = new IndicatorHandler(indicator, this);
    indicatorHandler.start();
    readProcessOutput();
    stop();
    indicatorHandler.stop();
    return printExitSummary();
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 55 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project clion-embedded-arm by elmot.

the class OpenOcdLauncher method createProcess.

@Override
protected ProcessHandler createProcess(@NotNull CommandLineState commandLineState) throws ExecutionException {
    File runFile = findRunFile(commandLineState);
    findOpenOcdAction(commandLineState.getEnvironment().getProject()).stopOpenOcd();
    try {
        GeneralCommandLine commandLine = OpenOcdComponent.createOcdCommandLine(commandLineState.getEnvironment().getProject(), runFile, "reset", true);
        OSProcessHandler osProcessHandler = new OSProcessHandler(commandLine);
        osProcessHandler.addProcessListener(new ProcessAdapter() {

            @Override
            public void processTerminated(@NotNull ProcessEvent event) {
                super.processTerminated(event);
                Project project = commandLineState.getEnvironment().getProject();
                if (event.getExitCode() == 0) {
                    Informational.showSuccessfulDownloadNotification(project);
                } else {
                    Informational.showFailedDownloadNotification(project);
                }
            }
        });
        return osProcessHandler;
    } catch (ConfigurationException e) {
        Messages.showErrorDialog(getProject(), e.getLocalizedMessage(), e.getTitle());
        throw new ExecutionException(e);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ConfigurationException(com.intellij.openapi.options.ConfigurationException) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File)

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