Search in sources :

Example 56 with ProcessHandler

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

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

the class RunContentManagerImpl method isTerminated.

public static boolean isTerminated(@NotNull Content content) {
    RunContentDescriptor descriptor = getRunContentDescriptorByContent(content);
    ProcessHandler processHandler = descriptor == null ? null : descriptor.getProcessHandler();
    return processHandler == null || processHandler.isProcessTerminated();
}
Also used : ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 58 with ProcessHandler

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

the class FakeRerunAction method isEnabled.

protected boolean isEnabled(AnActionEvent event) {
    RunContentDescriptor descriptor = getDescriptor(event);
    ProcessHandler processHandler = descriptor == null ? null : descriptor.getProcessHandler();
    ExecutionEnvironment environment = getEnvironment(event);
    return environment != null && !ExecutorRegistry.getInstance().isStarting(environment) && !(processHandler != null && processHandler.isProcessTerminating());
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 59 with ProcessHandler

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

the class RunTab method initLogConsoles.

protected final void initLogConsoles(@NotNull RunProfile runConfiguration, @NotNull RunContentDescriptor contentDescriptor, @Nullable ExecutionConsole console) {
    ProcessHandler processHandler = contentDescriptor.getProcessHandler();
    if (runConfiguration instanceof RunConfigurationBase) {
        RunConfigurationBase configuration = (RunConfigurationBase) runConfiguration;
        if (myManager == null) {
            myManager = new LogFilesManager(myProject, getLogConsoleManager(), contentDescriptor);
        }
        myManager.addLogConsoles(configuration, processHandler);
        if (processHandler != null) {
            OutputFileUtil.attachDumpListener(configuration, processHandler, console);
        }
    }
}
Also used : RunConfigurationBase(com.intellij.execution.configurations.RunConfigurationBase) LogFilesManager(com.intellij.diagnostic.logging.LogFilesManager) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 60 with ProcessHandler

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

the class RunConfigurationBeforeRunProvider method doRunTask.

public static boolean doRunTask(final String executorId, final ExecutionEnvironment environment, ProgramRunner<?> runner) {
    final Semaphore targetDone = new Semaphore();
    final Ref<Boolean> result = new Ref<>(false);
    final Disposable disposable = Disposer.newDisposable();
    environment.getProject().getMessageBus().connect(disposable).subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() {

        @Override
        public void processStartScheduled(@NotNull final String executorIdLocal, @NotNull final ExecutionEnvironment environmentLocal) {
            if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
                targetDone.down();
            }
        }

        @Override
        public void processNotStarted(@NotNull final String executorIdLocal, @NotNull final ExecutionEnvironment environmentLocal) {
            if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
                Boolean skipRun = environment.getUserData(ExecutionManagerImpl.EXECUTION_SKIP_RUN);
                if (skipRun != null && skipRun) {
                    result.set(true);
                }
                targetDone.up();
            }
        }

        @Override
        public void processTerminated(@NotNull String executorIdLocal, @NotNull ExecutionEnvironment environmentLocal, @NotNull ProcessHandler handler, int exitCode) {
            if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
                result.set(exitCode == 0);
                targetDone.up();
            }
        }
    });
    try {
        ApplicationManager.getApplication().invokeAndWait(() -> {
            try {
                runner.execute(environment);
            } catch (ExecutionException e) {
                targetDone.up();
                LOG.error(e);
            }
        }, ModalityState.NON_MODAL);
    } catch (Exception e) {
        LOG.error(e);
        Disposer.dispose(disposable);
        return false;
    }
    targetDone.waitFor();
    Disposer.dispose(disposable);
    return result.get();
}
Also used : Disposable(com.intellij.openapi.Disposable) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Semaphore(com.intellij.util.concurrency.Semaphore) Ref(com.intellij.openapi.util.Ref) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Aggregations

ProcessHandler (com.intellij.execution.process.ProcessHandler)99 NotNull (org.jetbrains.annotations.NotNull)30 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)24 ExecutionException (com.intellij.execution.ExecutionException)17 Project (com.intellij.openapi.project.Project)17 ConsoleView (com.intellij.execution.ui.ConsoleView)15 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)14 ProcessEvent (com.intellij.execution.process.ProcessEvent)14 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)14 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)13 ProgramRunner (com.intellij.execution.runners.ProgramRunner)12 Nullable (org.jetbrains.annotations.Nullable)10 Executor (com.intellij.execution.Executor)9 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)7 Disposable (com.intellij.openapi.Disposable)7 RunProfile (com.intellij.execution.configurations.RunProfile)6 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)6 File (java.io.File)6 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)5 ToggleAutoTestAction (com.intellij.execution.testframework.autotest.ToggleAutoTestAction)5