Search in sources :

Example 31 with ProcessEvent

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

the class OpenInXcodeAction method openWithXcode.

private static void openWithXcode(String path) {
    try {
        final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters(path);
        final OSProcessHandler handler = new OSProcessHandler(cmd);
        handler.addProcessListener(new ProcessAdapter() {

            @Override
            public void processTerminated(final ProcessEvent event) {
                if (event.getExitCode() != 0) {
                    FlutterMessages.showError("Error Opening", path);
                }
            }
        });
        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 32 with ProcessEvent

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

the class OpenSimulatorAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    try {
        final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters("-a", "Simulator.app");
        final OSProcessHandler handler = new OSProcessHandler(cmd);
        handler.addProcessListener(new ProcessAdapter() {

            @Override
            public void processTerminated(final ProcessEvent event) {
                if (event.getExitCode() != 0) {
                    final String msg = event.getText() != null ? event.getText() : "Process error - exit code: (" + event.getExitCode() + ")";
                    FlutterMessages.showError("Error Opening Simulator", msg);
                }
            }
        });
        handler.startNotify();
    } catch (ExecutionException e) {
        FlutterMessages.showError("Error Opening Simulator", FlutterBundle.message("flutter.command.exception.message", e.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 33 with ProcessEvent

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

the class System method which.

/**
 * Locate a given command-line tool given its name.
 */
@Nullable
public static String which(String toolName) {
    final String whichCommandName = SystemInfo.isWindows ? "where" : "which";
    final GeneralCommandLine cmd = new GeneralCommandLine().withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE).withExePath(whichCommandName).withParameters(toolName);
    try {
        final StringBuilder stringBuilder = new StringBuilder();
        final OSProcessHandler process = new OSProcessHandler(cmd);
        process.addProcessListener(new ProcessAdapter() {

            @Override
            public void onTextAvailable(ProcessEvent event, Key outputType) {
                if (outputType == ProcessOutputTypes.STDOUT) {
                    stringBuilder.append(event.getText());
                }
            }
        });
        process.startNotify();
        // We wait a maximum of 2000ms.
        if (!process.waitFor(2000)) {
            return null;
        }
        final Integer exitCode = process.getExitCode();
        if (exitCode == null || process.getExitCode() != 0) {
            return null;
        }
        final String[] results = stringBuilder.toString().split("\n");
        return results.length == 0 ? null : results[0].trim();
    } catch (ExecutionException | RuntimeException e) {
        return null;
    }
}
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) Key(com.intellij.openapi.util.Key) Nullable(org.jetbrains.annotations.Nullable)

Example 34 with ProcessEvent

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

the class MOERunProfileState method createProcessHandler.

@NotNull
private OSProcessHandler createProcessHandler() throws ExecutionException {
    if (runConfiguration.configuration() == null) {
        throw new ExecutionException("Invalid build configuration for " + runConfiguration.getClass().getName());
    } else if (runConfiguration.architecture() == null) {
        throw new ExecutionException("Invalid architecture for " + runConfiguration.getClass().getName());
    }
    final MOEGradleRunner gradleRunner = new MOEGradleRunner(runConfiguration);
    final boolean isDebug = runConfiguration.getActionType().equals("Debug");
    final GeneralCommandLine commandLine = gradleRunner.construct(isDebug, true);
    final OSProcessHandler handler = new MOEOSProcessHandler(commandLine);
    handler.setShouldDestroyProcessRecursively(true);
    final MOETestResultParser parser = new MOETestResultParser(new MOETestListener(this));
    final boolean isTest = runConfiguration.runJUnitTests();
    handler.addProcessListener(new ProcessListener() {

        @Override
        public void startNotified(ProcessEvent event) {
        }

        @Override
        public void processTerminated(ProcessEvent event) {
        }

        @Override
        public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
        }

        @Override
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            String text = event.getText();
            if (isTest) {
                parser.addOutput(text);
            }
            if (text.contains("ApplicationVerificationFailed")) {
                MOEToolWindow.getInstance(project).balloon(MessageType.ERROR, "Application installation failed. Please check log for details...");
                MOEToolWindow.getInstance(project).log("Application installation failed. Please make sure you have correct bundle id in your Info.plist file.");
            }
        }
    });
    return handler;
}
Also used : ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessListener(com.intellij.execution.process.ProcessListener) MOEGradleRunner(org.moe.idea.compiler.MOEGradleRunner) MOETestResultParser(org.moe.common.junit.MOETestResultParser) MOEOSProcessHandler(org.moe.idea.execution.process.MOEOSProcessHandler) MOETestListener(org.moe.idea.runconfig.configuration.test.MOETestListener) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) MOEOSProcessHandler(org.moe.idea.execution.process.MOEOSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with ProcessEvent

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

the class MOEGradleRunner method buildProject.

private void buildProject(MOEGradleInvocationResult result) {
    final Stopwatch stopwatch = Stopwatch.createUnstarted();
    stopwatch.start();
    String errorMessage = null;
    try {
        LOG.debug("Start build process");
        final org.moe.idea.compiler.MOEGradleRunner gradleRunner = new org.moe.idea.compiler.MOEGradleRunner(runConfig);
        final boolean isDebug = runConfig.getActionType().equals("Debug");
        boolean isMaven = ModuleUtils.isMOEMavenModule(runConfig.module());
        final MOEToolWindow toolWindow = MOEToolWindow.getInstance(runConfig.getProject());
        if (!isMaven) {
            final GeneralCommandLine commandLine = gradleRunner.construct(isDebug, false);
            final OSProcessHandler handler = new OSProcessHandler(commandLine);
            handler.setShouldDestroyProcessRecursively(true);
            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();
            int returnCode = handler.getProcess().exitValue();
            // Show on failure
            if (returnCode != 0) {
                toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
                errorMessage = "Multi-OS Engine module build failed";
            }
        } else {
            MOEMavenBuildTask mavenTask = new MOEMavenBuildTask(runConfig, "Building " + runConfig.moduleName(), true);
            boolean res = mavenTask.runTask();
            if (!res) {
                toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
                errorMessage = "Multi-OS Engine module build failed";
            }
        }
        if (errorMessage == null) {
            result.setBuildSuccessful(true);
        } else {
            result.setBuildSuccessful(false);
            result.setErrorMessage(errorMessage);
        }
    } catch (Exception e) {
        result.setBuildSuccessful(false);
        result.setErrorMessage(String.format("Error while building %s .%n", e.getMessage()));
    } finally {
        stopwatch.stop();
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) Stopwatch(com.google.common.base.Stopwatch) MOEToolWindow(org.moe.idea.ui.MOEToolWindow) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) MOEMavenBuildTask(org.moe.idea.maven.MOEMavenBuildTask) Key(com.intellij.openapi.util.Key)

Aggregations

ProcessEvent (com.intellij.execution.process.ProcessEvent)89 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)81 Key (com.intellij.openapi.util.Key)33 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)24 NotNull (org.jetbrains.annotations.NotNull)24 ExecutionException (com.intellij.execution.ExecutionException)21 ProcessHandler (com.intellij.execution.process.ProcessHandler)18 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)15 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)12 IOException (java.io.IOException)12 Nullable (org.jetbrains.annotations.Nullable)12 Project (com.intellij.openapi.project.Project)9 File (java.io.File)9 ProcessListener (com.intellij.execution.process.ProcessListener)8 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)7 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)5 ProgramRunner (com.intellij.execution.runners.ProgramRunner)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)4 Disposable (com.intellij.openapi.Disposable)4