Search in sources :

Example 91 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project clion-embedded-arm by elmot.

the class OpenOcdComponent method startOpenOcd.

@SuppressWarnings("WeakerAccess")
public Future<STATUS> startOpenOcd(Project project, @Nullable File fileToLoad, @Nullable String additionalCommand) throws ConfigurationException {
    if (project == null)
        return new FutureResult<>(STATUS.FLASH_ERROR);
    GeneralCommandLine commandLine = createOcdCommandLine(project, fileToLoad, additionalCommand, false);
    if (process != null && !process.isProcessTerminated()) {
        LOG.info("openOcd is already run");
        return new FutureResult<>(STATUS.FLASH_ERROR);
    }
    try {
        process = new OSProcessHandler(commandLine) {

            @Override
            public boolean isSilentlyDestroyOnClose() {
                return true;
            }
        };
        DownloadFollower downloadFollower = new DownloadFollower();
        process.addProcessListener(downloadFollower);
        RunContentExecutor openOCDConsole = new RunContentExecutor(project, process).withTitle("OpenOCD console").withActivateToolWindow(true).withFilter(new ErrorFilter(project)).withStop(process::destroyProcess, () -> !process.isProcessTerminated() && !process.isProcessTerminating());
        openOCDConsole.run();
        return downloadFollower;
    } catch (ExecutionException e) {
        ExecutionErrorDialog.show(e, "OpenOCD start failed", project);
        return new FutureResult<>(STATUS.FLASH_ERROR);
    }
}
Also used : FutureResult(com.intellij.util.concurrency.FutureResult) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RunContentExecutor(com.intellij.execution.RunContentExecutor) ExecutionException(com.intellij.execution.ExecutionException)

Example 92 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine 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 93 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine 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)

Example 94 with GeneralCommandLine

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

the class MOEGenerateActionsAndOutletsAction 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", "Actions and Outlets Generation 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, "Actions and Outlets Generation 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, "moeGenerateUIObjCInterfaces");
                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:generateUIObjCInterfaces");
                if (!task.runTask()) {
                    ModuleUtils.runInDispatchedThread(new Runnable() {

                        @Override
                        public void run() {
                            Messages.showErrorDialog("Unable run generation", "Actions and Outlets Generation Error");
                        }
                    });
                }
            }
        }, null);
        ModuleUtils.runInDispatchedThread(new Runnable() {

            @Override
            public void run() {
                MOEMavenTask task = new MOEMavenTask(module, ACTION_TITLE, false);
                task.setGoal("moe:generateUIObjCInterfaces");
                if (!task.runTask()) {
                    Messages.showErrorDialog("Unable run generation", "Actions and Outlets Generation 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 95 with GeneralCommandLine

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

the class MOEGradleRunner method construct.

public static GeneralCommandLine construct(Module module, String... args) {
    final List<String> cmdargs = new ArrayList<String>();
    // Get Gradle
    File workingDir = new File(ModuleUtils.getModulePath(module));
    GradleExec exec = new GradleExec(workingDir);
    cmdargs.add(exec.getExecPath());
    for (String arg : args) {
        cmdargs.add(arg);
    }
    return new GeneralCommandLine(cmdargs).withWorkDirectory(workingDir);
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ArrayList(java.util.ArrayList) GradleExec(org.moe.common.exec.GradleExec) File(java.io.File)

Aggregations

GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)179 ExecutionException (com.intellij.execution.ExecutionException)70 NotNull (org.jetbrains.annotations.NotNull)47 File (java.io.File)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)25 ProcessOutput (com.intellij.execution.process.ProcessOutput)25 Key (com.intellij.openapi.util.Key)18 ProcessEvent (com.intellij.execution.process.ProcessEvent)15 Project (com.intellij.openapi.project.Project)15 IOException (java.io.IOException)15 Nullable (org.jetbrains.annotations.Nullable)15 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)14 CapturingProcessHandler (com.intellij.execution.process.CapturingProcessHandler)13 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)12 Sdk (com.intellij.openapi.projectRoots.Sdk)9 PsiFile (com.intellij.psi.PsiFile)9 ArrayList (java.util.ArrayList)9 Module (com.intellij.openapi.module.Module)8 ProcessHandler (com.intellij.execution.process.ProcessHandler)7