Search in sources :

Example 86 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 87 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 88 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)

Example 89 with ProcessHandler

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

the class ForkedGroovyc method runGroovyc.

@Override
public GroovycContinuation runGroovyc(Collection<String> compilationClassPath, boolean forStubs, JpsGroovySettings settings, File tempFile, final GroovycOutputParser parser) throws Exception {
    List<String> classpath = new ArrayList<>();
    if (myOptimizeClassLoading) {
        classpath.addAll(GroovyBuilder.getGroovyRtRoots());
        classpath.add(ClasspathBootstrap.getResourcePath(Function.class));
        classpath.add(ClasspathBootstrap.getResourcePath(UrlClassLoader.class));
        classpath.add(ClasspathBootstrap.getResourceFile(THashMap.class).getPath());
    } else {
        classpath.addAll(compilationClassPath);
    }
    List<String> vmParams = ContainerUtilRt.newArrayList();
    vmParams.add("-Xmx" + System.getProperty("groovyc.heap.size", settings.heapSize) + "m");
    vmParams.add("-Dfile.encoding=" + System.getProperty("file.encoding"));
    if ("false".equals(System.getProperty(GroovyRtConstants.GROOVYC_ASM_RESOLVING_ONLY))) {
        vmParams.add("-D" + GroovyRtConstants.GROOVYC_ASM_RESOLVING_ONLY + "=false");
    }
    String configScript = settings.configScript;
    if (StringUtil.isNotEmpty(configScript)) {
        vmParams.add("-D" + GroovyRtConstants.GROOVYC_CONFIG_SCRIPT + "=" + configScript);
    }
    String grapeRoot = System.getProperty(GroovycOutputParser.GRAPE_ROOT);
    if (grapeRoot != null) {
        vmParams.add("-D" + GroovycOutputParser.GRAPE_ROOT + "=" + grapeRoot);
    }
    final List<String> cmd = ExternalProcessUtil.buildJavaCommandLine(getJavaExecutable(myChunk), "org.jetbrains.groovy.compiler.rt.GroovycRunner", Collections.<String>emptyList(), classpath, vmParams, getProgramParams(tempFile, settings, forStubs));
    final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmd));
    ProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmd, " "), null) {

        @NotNull
        @Override
        protected Future<?> executeOnPooledThread(@NotNull Runnable task) {
            return SharedThreadPool.getInstance().executeOnPooledThread(task);
        }

        @Override
        public void notifyTextAvailable(String text, Key outputType) {
            parser.notifyTextAvailable(text, outputType);
        }
    };
    handler.startNotify();
    handler.waitFor();
    parser.notifyFinished(process.exitValue());
    return null;
}
Also used : Function(com.intellij.util.Function) ArrayList(java.util.ArrayList) ProcessHandler(com.intellij.execution.process.ProcessHandler) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler) UrlClassLoader(com.intellij.util.lang.UrlClassLoader) NotNull(org.jetbrains.annotations.NotNull) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler) Key(com.intellij.openapi.util.Key)

Example 90 with ProcessHandler

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

the class AbstractAutoTestManager method setAutoTestEnabled.

public void setAutoTestEnabled(@NotNull RunContentDescriptor descriptor, @NotNull ExecutionEnvironment environment, boolean enabled) {
    Content content = descriptor.getAttachedContent();
    if (content != null) {
        if (enabled) {
            myEnabledRunProfiles.add(environment.getRunProfile());
            myWatcher.activate();
        } else {
            myEnabledRunProfiles.remove(environment.getRunProfile());
            if (!hasEnabledAutoTests()) {
                myWatcher.deactivate();
            }
            ProcessHandler processHandler = descriptor.getProcessHandler();
            if (processHandler != null) {
                clearRestarterListener(processHandler);
            }
        }
    }
}
Also used : Content(com.intellij.ui.content.Content) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Aggregations

ProcessHandler (com.intellij.execution.process.ProcessHandler)100 NotNull (org.jetbrains.annotations.NotNull)31 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)16 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)15 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 SMTRunnerConsoleView (com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView)6 File (java.io.File)6 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)5