Search in sources :

Example 66 with ProcessHandler

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

the class CommandLineState method execute.

@Override
@NotNull
public ExecutionResult execute(@NotNull final Executor executor, @NotNull final ProgramRunner runner) throws ExecutionException {
    final ProcessHandler processHandler = startProcess();
    final ConsoleView console = createConsole(executor);
    if (console != null) {
        console.attachToProcess(processHandler);
    }
    return new DefaultExecutionResult(console, processHandler, createActions(console, processHandler, executor));
}
Also used : ConsoleView(com.intellij.execution.ui.ConsoleView) ProcessHandler(com.intellij.execution.process.ProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 67 with ProcessHandler

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

the class ShowRunningListAction method getCurrentState.

private static Pair<? extends JComponent, String> getCurrentState(@NotNull List<Project> projects) {
    NonOpaquePanel panel = new NonOpaquePanel(new GridLayout(0, 1, 10, 10));
    StringBuilder state = new StringBuilder();
    for (int i = 0; i < projects.size(); i++) {
        Project project = projects.get(i);
        final ExecutionManagerImpl executionManager = ExecutionManagerImpl.getInstance(project);
        List<RunContentDescriptor> runningDescriptors = executionManager.getRunningDescriptors(Condition.TRUE);
        if (!runningDescriptors.isEmpty() && projects.size() > 1) {
            state.append(project.getName());
            panel.add(new JLabel("<html><body><b>Project '" + project.getName() + "'</b></body></html>"));
        }
        for (RunContentDescriptor descriptor : runningDescriptors) {
            Set<Executor> executors = executionManager.getExecutors(descriptor);
            for (Executor executor : executors) {
                state.append(System.identityHashCode(descriptor.getAttachedContent())).append("@").append(System.identityHashCode(executor.getIcon())).append(";");
                ProcessHandler processHandler = descriptor.getProcessHandler();
                Icon icon = (processHandler instanceof KillableProcess && processHandler.isProcessTerminating()) ? AllIcons.Debugger.KillProcess : executor.getIcon();
                JLabel label = new JLabel("<html><body><a href=\"\">" + descriptor.getDisplayName() + "</a></body></html>", icon, SwingConstants.LEADING);
                label.setIconTextGap(JBUI.scale(2));
                label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                label.putClientProperty(KEY, Trinity.create(project, executor, descriptor));
                panel.add(label);
            }
        }
    }
    if (panel.getComponentCount() == 0) {
        panel.setBorder(JBUI.Borders.empty(10));
        panel.add(new JLabel(ExecutionBundle.message("show.running.list.balloon.nothing"), SwingConstants.CENTER));
    } else {
        panel.setBorder(JBUI.Borders.empty(10, 10, 0, 10));
        JLabel label = new JLabel(ExecutionBundle.message("show.running.list.balloon.hint"));
        label.setFont(JBUI.Fonts.miniFont());
        panel.add(label);
    }
    return Pair.create(panel, state.toString());
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) RelativePoint(com.intellij.ui.awt.RelativePoint) KillableProcess(com.intellij.execution.KillableProcess) NonOpaquePanel(com.intellij.ui.components.panels.NonOpaquePanel) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor) ProcessHandler(com.intellij.execution.process.ProcessHandler) LayeredIcon(com.intellij.ui.LayeredIcon) ExecutionManagerImpl(com.intellij.execution.impl.ExecutionManagerImpl)

Example 68 with ProcessHandler

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

the class StopAction method getItemsList.

@Nullable
private static Pair<List<HandlerItem>, HandlerItem> getItemsList(List<Pair<TaskInfo, ProgressIndicator>> tasks, List<RunContentDescriptor> descriptors, RunContentDescriptor toSelect) {
    if (tasks.isEmpty() && descriptors.isEmpty()) {
        return null;
    }
    List<HandlerItem> items = new ArrayList<>(tasks.size() + descriptors.size());
    HandlerItem selected = null;
    for (final RunContentDescriptor descriptor : descriptors) {
        final ProcessHandler handler = descriptor.getProcessHandler();
        if (handler != null) {
            HandlerItem item = new HandlerItem(descriptor.getDisplayName(), descriptor.getIcon(), false) {

                @Override
                void stop() {
                    ExecutionManagerImpl.stopProcess(descriptor);
                }
            };
            items.add(item);
            if (descriptor == toSelect) {
                selected = item;
            }
        }
    }
    boolean hasSeparator = true;
    for (final Pair<TaskInfo, ProgressIndicator> eachPair : tasks) {
        items.add(new HandlerItem(eachPair.first.getTitle(), AllIcons.Process.Step_passive, hasSeparator) {

            @Override
            void stop() {
                eachPair.second.cancel();
            }
        });
        hasSeparator = false;
    }
    return Pair.create(items, selected);
}
Also used : TaskInfo(com.intellij.openapi.progress.TaskInfo) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ArrayList(java.util.ArrayList) ProcessHandler(com.intellij.execution.process.ProcessHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 69 with ProcessHandler

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

the class StopAction method update.

@Override
public void update(final AnActionEvent e) {
    boolean enable = false;
    Icon icon = getTemplatePresentation().getIcon();
    String description = getTemplatePresentation().getDescription();
    Presentation presentation = e.getPresentation();
    if (isPlaceGlobal(e)) {
        List<RunContentDescriptor> stoppableDescriptors = getActiveStoppableDescriptors(e.getDataContext());
        List<Pair<TaskInfo, ProgressIndicator>> cancellableProcesses = getCancellableProcesses(e.getProject());
        int todoSize = stoppableDescriptors.size() + cancellableProcesses.size();
        if (todoSize > 1) {
            presentation.setText(getTemplatePresentation().getText() + "...");
        } else if (todoSize == 1) {
            if (stoppableDescriptors.size() == 1) {
                presentation.setText(ExecutionBundle.message("stop.configuration.action.name", StringUtil.escapeMnemonics(stoppableDescriptors.get(0).getDisplayName())));
            } else {
                TaskInfo taskInfo = cancellableProcesses.get(0).first;
                presentation.setText(taskInfo.getCancelText() + " " + taskInfo.getTitle());
            }
        } else {
            presentation.setText(getTemplatePresentation().getText());
        }
        enable = todoSize > 0;
        if (todoSize > 1) {
            icon = IconUtil.addText(icon, String.valueOf(todoSize));
        }
    } else {
        RunContentDescriptor contentDescriptor = e.getData(LangDataKeys.RUN_CONTENT_DESCRIPTOR);
        ProcessHandler processHandler = contentDescriptor == null ? null : contentDescriptor.getProcessHandler();
        if (processHandler != null && !processHandler.isProcessTerminated()) {
            if (!processHandler.isProcessTerminating()) {
                enable = true;
            } else if (processHandler instanceof KillableProcess && ((KillableProcess) processHandler).canKillProcess()) {
                enable = true;
                icon = AllIcons.Debugger.KillProcess;
                description = "Kill process";
            }
        }
        RunProfile runProfile = e.getData(LangDataKeys.RUN_PROFILE);
        if (runProfile == null && contentDescriptor == null) {
            presentation.setText(getTemplatePresentation().getText());
        } else {
            presentation.setText(ExecutionBundle.message("stop.configuration.action.name", StringUtil.escapeMnemonics(runProfile == null ? contentDescriptor.getDisplayName() : runProfile.getName())));
        }
    }
    presentation.setEnabled(enable);
    presentation.setIcon(icon);
    presentation.setDescription(description);
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) RunProfile(com.intellij.execution.configurations.RunProfile) KillableProcess(com.intellij.execution.KillableProcess) TaskInfo(com.intellij.openapi.progress.TaskInfo) ProcessHandler(com.intellij.execution.process.ProcessHandler) Pair(com.intellij.openapi.util.Pair)

Example 70 with ProcessHandler

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

the class EOFAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    RunContentDescriptor descriptor = StopAction.getRecentlyStartedContentDescriptor(e.getDataContext());
    ProcessHandler activeProcessHandler = descriptor != null ? descriptor.getProcessHandler() : null;
    if (activeProcessHandler == null || activeProcessHandler.isProcessTerminated())
        return;
    try {
        OutputStream input = activeProcessHandler.getProcessInput();
        if (input != null) {
            ConsoleView console = e.getData(LangDataKeys.CONSOLE_VIEW);
            if (console != null) {
                console.print("^D\n", ConsoleViewContentType.SYSTEM_OUTPUT);
            }
            input.close();
        }
    } catch (IOException ignored) {
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ConsoleView(com.intellij.execution.ui.ConsoleView) OutputStream(java.io.OutputStream) ProcessHandler(com.intellij.execution.process.ProcessHandler) IOException(java.io.IOException)

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