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);
}
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);
}
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) {
}
}
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;
}
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);
}
}
}
}
Aggregations