Search in sources :

Example 51 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project android by JetBrains.

the class AndroidCommonUtils method handleDexCompilationResult.

public static void handleDexCompilationResult(@NotNull Process process, @NotNull String commandLine, @NotNull String outputFilePath, @NotNull final Map<AndroidCompilerMessageKind, List<String>> messages, boolean multiDex) {
    final BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commandLine, null);
    handler.addProcessListener(new ProcessAdapter() {

        private AndroidCompilerMessageKind myCategory = null;

        @Override
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            String[] msgs = event.getText().split("\\n");
            for (String msg : msgs) {
                msg = msg.trim();
                String msglc = msg.toLowerCase();
                if (outputType == ProcessOutputTypes.STDERR) {
                    if (WARNING_PATTERN.matcher(msglc).matches()) {
                        myCategory = AndroidCompilerMessageKind.WARNING;
                    }
                    if (ERROR_PATTERN.matcher(msglc).matches() || EXCEPTION_PATTERN.matcher(msglc).matches() || myCategory == null) {
                        myCategory = AndroidCompilerMessageKind.ERROR;
                    }
                    messages.get(myCategory).add(msg);
                } else if (outputType == ProcessOutputTypes.STDOUT) {
                    if (!msglc.startsWith("processing")) {
                        messages.get(AndroidCompilerMessageKind.INFORMATION).add(msg);
                    }
                }
                LOG.debug(msg);
            }
        }
    });
    handler.startNotify();
    handler.waitFor();
    final List<String> errors = messages.get(AndroidCompilerMessageKind.ERROR);
    if (new File(outputFilePath).isFile()) {
        // if compilation finished correctly, show all errors as warnings
        messages.get(AndroidCompilerMessageKind.WARNING).addAll(errors);
        errors.clear();
    } else if (errors.size() == 0 && !multiDex) {
        errors.add("Cannot create classes.dex file");
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler) Key(com.intellij.openapi.util.Key)

Example 52 with ProcessEvent

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

the class AbstractToolBeforeRunTask method execute.

public boolean execute(final DataContext context, final long executionId) {
    final Semaphore targetDone = new Semaphore();
    final Ref<Boolean> result = new Ref<>(false);
    try {
        ApplicationManager.getApplication().invokeAndWait(() -> ToolAction.runTool(myToolActionId, context, null, executionId, new ProcessAdapter() {

            public void startNotified(final ProcessEvent event) {
                targetDone.down();
            }

            @Override
            public void processTerminated(ProcessEvent event) {
                result.set(event.getExitCode() == 0);
                targetDone.up();
            }
        }), ModalityState.NON_MODAL);
    } catch (Exception e) {
        LOG.error(e);
        return false;
    }
    targetDone.waitFor();
    return result.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) Semaphore(com.intellij.util.concurrency.Semaphore)

Example 53 with ProcessEvent

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

the class XDebugSessionImpl method init.

XDebugSessionTab init(@NotNull XDebugProcess process, @Nullable RunContentDescriptor contentToReuse) {
    LOG.assertTrue(myDebugProcess == null);
    myDebugProcess = process;
    if (myDebugProcess.checkCanInitBreakpoints()) {
        initBreakpoints();
    }
    myDebugProcess.getProcessHandler().addProcessListener(new ProcessAdapter() {

        @Override
        public void processTerminated(final ProcessEvent event) {
            stopImpl();
            myDebugProcess.getProcessHandler().removeProcessListener(this);
        }
    });
    //todo[nik] make 'createConsole()' method return ConsoleView
    myConsoleView = (ConsoleView) myDebugProcess.createConsole();
    if (!myShowTabOnSuspend.get()) {
        initSessionTab(contentToReuse);
    }
    return mySessionTab;
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent)

Example 54 with ProcessEvent

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

the class RunContentManagerImpl method showRunContent.

private void showRunContent(@NotNull final Executor executor, @NotNull final RunContentDescriptor descriptor, final long executionId) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return;
    }
    final ContentManager contentManager = getContentManagerForRunner(executor, descriptor);
    RunContentDescriptor oldDescriptor = chooseReuseContentForDescriptor(contentManager, descriptor, executionId, descriptor.getDisplayName());
    final Content content;
    if (oldDescriptor == null) {
        content = createNewContent(descriptor, executor);
    } else {
        content = oldDescriptor.getAttachedContent();
        LOG.assertTrue(content != null);
        getSyncPublisher().contentRemoved(oldDescriptor, executor);
        // is of the same category, can be reused
        Disposer.dispose(oldDescriptor);
    }
    content.setExecutionId(executionId);
    content.setComponent(descriptor.getComponent());
    content.setPreferredFocusedComponent(descriptor.getPreferredFocusComputable());
    content.putUserData(RunContentDescriptor.DESCRIPTOR_KEY, descriptor);
    content.putUserData(EXECUTOR_KEY, executor);
    content.setDisplayName(descriptor.getDisplayName());
    descriptor.setAttachedContent(content);
    String toolWindowId = getToolWindowIdForRunner(executor, descriptor);
    final ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId);
    final ProcessHandler processHandler = descriptor.getProcessHandler();
    if (processHandler != null) {
        final ProcessAdapter processAdapter = new ProcessAdapter() {

            @Override
            public void startNotified(final ProcessEvent event) {
                UIUtil.invokeLaterIfNeeded(() -> {
                    content.setIcon(ExecutionUtil.getLiveIndicator(descriptor.getIcon()));
                    toolWindow.setIcon(ExecutionUtil.getLiveIndicator(myToolwindowIdToBaseIconMap.get(toolWindowId)));
                });
            }

            @Override
            public void processTerminated(final ProcessEvent event) {
                ApplicationManager.getApplication().invokeLater(() -> {
                    boolean alive = false;
                    ContentManager manager = myToolwindowIdToContentManagerMap.get(toolWindowId);
                    if (manager == null)
                        return;
                    for (Content content1 : manager.getContents()) {
                        RunContentDescriptor descriptor1 = getRunContentDescriptorByContent(content1);
                        if (descriptor1 != null) {
                            ProcessHandler handler = descriptor1.getProcessHandler();
                            if (handler != null && !handler.isProcessTerminated()) {
                                alive = true;
                                break;
                            }
                        }
                    }
                    Icon base = myToolwindowIdToBaseIconMap.get(toolWindowId);
                    toolWindow.setIcon(alive ? ExecutionUtil.getLiveIndicator(base) : base);
                    Icon icon = descriptor.getIcon();
                    content.setIcon(icon == null ? executor.getDisabledIcon() : IconLoader.getTransparentIcon(icon));
                });
            }
        };
        processHandler.addProcessListener(processAdapter);
        final Disposable disposer = content.getDisposer();
        if (disposer != null) {
            Disposer.register(disposer, new Disposable() {

                @Override
                public void dispose() {
                    processHandler.removeProcessListener(processAdapter);
                }
            });
        }
    }
    if (oldDescriptor == null) {
        contentManager.addContent(content);
        new CloseListener(content, executor);
    }
    content.getManager().setSelectedContent(content);
    if (!descriptor.isActivateToolWindowWhenAdded()) {
        return;
    }
    ApplicationManager.getApplication().invokeLater(() -> {
        ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId);
        // let's activate tool window, but don't move focus
        //
        // window.show() isn't valid here, because it will not
        // mark the window as "last activated" windows and thus
        // some action like navigation up/down in stacktrace wont
        // work correctly
        descriptor.getPreferredFocusComputable();
        window.activate(descriptor.getActivationCallback(), descriptor.isAutoFocusContent(), descriptor.isAutoFocusContent());
    }, myProject.getDisposed());
}
Also used : Disposable(com.intellij.openapi.Disposable) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ToolWindow(com.intellij.openapi.wm.ToolWindow) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 55 with ProcessEvent

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

the class DefaultJavaProgramRunner method addDefaultActions.

private static void addDefaultActions(@NotNull RunContentBuilder contentBuilder, @NotNull ExecutionResult executionResult) {
    final ExecutionConsole executionConsole = executionResult.getExecutionConsole();
    final JComponent consoleComponent = executionConsole != null ? executionConsole.getComponent() : null;
    final ControlBreakAction controlBreakAction = new ControlBreakAction(executionResult.getProcessHandler());
    if (consoleComponent != null) {
        controlBreakAction.registerCustomShortcutSet(controlBreakAction.getShortcutSet(), consoleComponent);
        final ProcessHandler processHandler = executionResult.getProcessHandler();
        assert processHandler != null : executionResult;
        processHandler.addProcessListener(new ProcessAdapter() {

            @Override
            public void processTerminated(final ProcessEvent event) {
                processHandler.removeProcessListener(this);
                controlBreakAction.unregisterCustomShortcutSet(consoleComponent);
            }
        });
    }
    contentBuilder.addAction(controlBreakAction);
    contentBuilder.addAction(new SoftExitAction(executionResult.getProcessHandler()));
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) CapturingProcessAdapter(com.intellij.execution.process.CapturingProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole)

Aggregations

ProcessEvent (com.intellij.execution.process.ProcessEvent)90 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)82 Key (com.intellij.openapi.util.Key)34 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)25 NotNull (org.jetbrains.annotations.NotNull)24 ExecutionException (com.intellij.execution.ExecutionException)22 ProcessHandler (com.intellij.execution.process.ProcessHandler)18 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)16 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