Search in sources :

Example 26 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler 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 27 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler 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 28 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler 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 29 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project intellij by bazelbuild.

the class BlazeIntellijPluginConfiguration method getState.

/**
 * Plugin jar has been previously created via blaze build. This method: - copies jar to sandbox
 * environment - cracks open jar and finds plugin.xml (with ID, etc., needed for JVM args) - sets
 * up the SDK, etc. (use project SDK?) - sets up the JVM, and returns a JavaCommandLineState
 */
@Nullable
@Override
public RunProfileState getState(Executor executor, ExecutionEnvironment env) throws ExecutionException {
    final Sdk ideaJdk = pluginSdk;
    if (!IdeaJdkHelper.isIdeaJdk(ideaJdk)) {
        throw new ExecutionException("Choose an IntelliJ Platform Plugin SDK");
    }
    String sandboxHome = IdeaJdkHelper.getSandboxHome(ideaJdk);
    if (sandboxHome == null) {
        throw new ExecutionException("No sandbox specified for IntelliJ Platform Plugin SDK");
    }
    try {
        sandboxHome = new File(sandboxHome).getCanonicalPath();
    } catch (IOException e) {
        throw new ExecutionException("No sandbox specified for IntelliJ Platform Plugin SDK");
    }
    String buildNumber = IdeaJdkHelper.getBuildNumber(ideaJdk);
    final BlazeIntellijPluginDeployer deployer = new BlazeIntellijPluginDeployer(sandboxHome, buildNumber, getTarget());
    env.putUserData(BlazeIntellijPluginDeployer.USER_DATA_KEY, deployer);
    // copy license from running instance of idea
    IdeaJdkHelper.copyIDEALicense(sandboxHome);
    return new JavaCommandLineState(env) {

        @Override
        protected JavaParameters createJavaParameters() throws ExecutionException {
            List<String> pluginIds = deployer.deployNonBlocking();
            final JavaParameters params = new JavaParameters();
            ParametersList vm = params.getVMParametersList();
            fillParameterList(vm, vmParameters);
            fillParameterList(params.getProgramParametersList(), programParameters);
            IntellijWithPluginClasspathHelper.addRequiredVmParams(params, ideaJdk);
            vm.defineProperty(JetBrainsProtocolHandler.REQUIRED_PLUGINS_KEY, Joiner.on(',').join(pluginIds));
            if (!vm.hasProperty(PlatformUtils.PLATFORM_PREFIX_KEY) && buildNumber != null) {
                String prefix = IdeaJdkHelper.getPlatformPrefix(buildNumber);
                if (prefix != null) {
                    vm.defineProperty(PlatformUtils.PLATFORM_PREFIX_KEY, prefix);
                }
            }
            return params;
        }

        @Override
        protected OSProcessHandler startProcess() throws ExecutionException {
            deployer.blockUntilDeployComplete();
            final OSProcessHandler handler = super.startProcess();
            handler.addProcessListener(new ProcessAdapter() {

                @Override
                public void processTerminated(ProcessEvent event) {
                    deployer.deleteDeployment();
                }
            });
            return handler;
        }
    };
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) IOException(java.io.IOException) JavaCommandLineState(com.intellij.execution.configurations.JavaCommandLineState) ParametersList(com.intellij.execution.configurations.ParametersList) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) JavaParameters(com.intellij.execution.configurations.JavaParameters) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 30 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project intellij by bazelbuild.

the class AaptUtil method getAaptBadging.

/**
 * Uses aapt to dump badging information for the given apk, and extracts information from the
 * output matching the given pattern.
 */
@Nullable
private static MatchResult getAaptBadging(Project project, File apk, Pattern pattern) throws AaptUtilException {
    if (!apk.exists()) {
        throw new AaptUtilException("apk file does not exist: " + apk);
    }
    AndroidPlatform androidPlatform = SdkUtil.getAndroidPlatform(project);
    if (androidPlatform == null) {
        throw new AaptUtilException("Could not find Android platform sdk for project " + project.getName());
    }
    BuildToolInfo toolInfo = androidPlatform.getSdkData().getLatestBuildTool();
    if (toolInfo == null) {
        throw new AaptUtilException("Could not find Android sdk build-tools for project " + project.getName());
    }
    String aapt = toolInfo.getPath(PathId.AAPT);
    GeneralCommandLine commandLine = new GeneralCommandLine(aapt, "dump", "badging", apk.getAbsolutePath());
    OSProcessHandler handler;
    try {
        handler = new OSProcessHandler(commandLine);
    } catch (ExecutionException e) {
        throw new AaptUtilException("Could not execute aapt to extract apk information.", e);
    }
    // The wrapped stream is closed by the process handler.
    BufferedReader reader = new BufferedReader(new InputStreamReader(handler.getProcess().getInputStream()));
    try {
        String line;
        while ((line = reader.readLine()) != null) {
            Matcher matcher = pattern.matcher(line);
            if (matcher.find()) {
                return matcher.toMatchResult();
            }
        }
    } catch (IOException e) {
        throw new AaptUtilException("Could not read aapt output.", e);
    }
    return null;
}
Also used : InputStreamReader(java.io.InputStreamReader) BuildToolInfo(com.android.sdklib.BuildToolInfo) Matcher(java.util.regex.Matcher) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) BufferedReader(java.io.BufferedReader) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) Nullable(javax.annotation.Nullable)

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