use of com.intellij.execution.process.ProcessHandler in project intellij-community by JetBrains.
the class EOFAction method update.
@Override
public void update(AnActionEvent e) {
RunContentDescriptor descriptor = StopAction.getRecentlyStartedContentDescriptor(e.getDataContext());
ProcessHandler handler = descriptor != null ? descriptor.getProcessHandler() : null;
e.getPresentation().setEnabledAndVisible(e.getData(LangDataKeys.CONSOLE_VIEW) != null && e.getData(CommonDataKeys.EDITOR) != null && handler != null && !handler.isProcessTerminated());
}
use of com.intellij.execution.process.ProcessHandler in project intellij-community by JetBrains.
the class ExecutionManagerTest method testRerunSingleton.
public void testRerunSingleton() throws Exception {
Project project = getProject();
ExecutionManagerImpl executionManager = ExecutionManagerImpl.getInstance(project);
FakeRunConfiguration rc = new FakeRunConfiguration(project, true);
RunnerAndConfigurationSettingsImpl settings = new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(project), rc, false);
settings.setSingleton(true);
ExecutionEnvironment env1 = createEnv(project, settings);
executionManager.restartRunProfile(env1);
UIUtil.dispatchAllInvocationEvents();
ProcessHandler processHandler1 = getProcessHandler(executionManager);
ExecutionEnvironment env2 = createEnv(project, settings);
executionManager.restartRunProfile(env2);
// Dispatching all events at this point will run into an endless cycle, because
// runContentDescriptors of the same type are asked to terminate and then are awaited for termination:
// com.intellij.execution.impl.ExecutionManagerImpl.awaitTermination
//
// However, the created processHandler is not willing to terminate on the first request (surviveSoftKill=true).
// It will be terminated on the second request: executionManager.restartRunProfile(env3)
ProcessHandler processHandler2 = getProcessHandler(executionManager);
assertTrue(processHandler1 == processHandler2);
assertTrue(processHandler1.isProcessTerminating());
ExecutionEnvironment env3 = createEnv(project, settings);
executionManager.restartRunProfile(env3);
UIUtil.dispatchAllInvocationEvents();
FakeProcessHandler processHandler3 = getProcessHandler(executionManager);
assertTrue(processHandler1 != processHandler3);
assertTrue(!processHandler3.isProcessTerminating() && !processHandler3.isProcessTerminated());
processHandler3.killProcess();
}
use of com.intellij.execution.process.ProcessHandler in project intellij-community by JetBrains.
the class ExecutionManagerTest method getProcessHandler.
@NotNull
private static FakeProcessHandler getProcessHandler(@NotNull ExecutionManagerImpl executionManager) {
RunContentDescriptor descriptor = ExecutionTestUtil.getSingleRunContentDescriptor(executionManager);
ProcessHandler processHandler = descriptor.getProcessHandler();
assertNotNull(processHandler);
return (FakeProcessHandler) processHandler;
}
use of com.intellij.execution.process.ProcessHandler in project intellij-community by JetBrains.
the class RunDashboardContributor method getStatus.
/**
* Returns node's status. Subclasses may override this method to provide custom statuses.
* @param node dashboard node
* @return node's status. Returned status is used for grouping nodes by status.
*/
public DashboardRunConfigurationStatus getStatus(DashboardRunConfigurationNode node) {
RunContentDescriptor descriptor = node.getDescriptor();
if (descriptor == null) {
return DashboardRunConfigurationStatus.STOPPED;
}
ProcessHandler processHandler = descriptor.getProcessHandler();
if (processHandler == null) {
return DashboardRunConfigurationStatus.STOPPED;
}
Integer exitCode = processHandler.getExitCode();
if (exitCode == null) {
return DashboardRunConfigurationStatus.STARTED;
}
Boolean terminationRequested = processHandler.getUserData(ProcessHandler.TERMINATION_REQUESTED);
if (exitCode == 0 || (terminationRequested != null && terminationRequested)) {
return DashboardRunConfigurationStatus.STOPPED;
}
return DashboardRunConfigurationStatus.FAILED;
}
use of com.intellij.execution.process.ProcessHandler in project intellij-community by JetBrains.
the class ExecutionManagerImpl method startRunProfile.
@Override
public void startRunProfile(@NotNull final RunProfileStarter starter, @NotNull final RunProfileState state, @NotNull final ExecutionEnvironment environment) {
final Project project = environment.getProject();
RunContentDescriptor reuseContent = getContentManager().getReuseContent(environment);
if (reuseContent != null) {
reuseContent.setExecutionId(environment.getExecutionId());
environment.setContentToReuse(reuseContent);
}
final Executor executor = environment.getExecutor();
project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processStartScheduled(executor.getId(), environment);
Runnable startRunnable;
startRunnable = () -> {
if (project.isDisposed()) {
return;
}
RunProfile profile = environment.getRunProfile();
project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processStarting(executor.getId(), environment);
starter.executeAsync(state, environment).done(descriptor -> {
AppUIUtil.invokeOnEdt(() -> {
if (descriptor != null) {
final Trinity<RunContentDescriptor, RunnerAndConfigurationSettings, Executor> trinity = Trinity.create(descriptor, environment.getRunnerAndConfigurationSettings(), executor);
myRunningConfigurations.add(trinity);
Disposer.register(descriptor, () -> myRunningConfigurations.remove(trinity));
getContentManager().showRunContent(executor, descriptor, environment.getContentToReuse());
final ProcessHandler processHandler = descriptor.getProcessHandler();
if (processHandler != null) {
if (!processHandler.isStartNotified()) {
processHandler.startNotify();
}
project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processStarted(executor.getId(), environment, processHandler);
ProcessExecutionListener listener = new ProcessExecutionListener(project, executor.getId(), environment, processHandler, descriptor);
processHandler.addProcessListener(listener);
boolean terminating = processHandler.isProcessTerminating();
boolean terminated = processHandler.isProcessTerminated();
if (terminating || terminated) {
listener.processWillTerminate(new ProcessEvent(processHandler), false);
if (terminated) {
int exitCode = processHandler.isStartNotified() ? processHandler.getExitCode() : -1;
listener.processTerminated(new ProcessEvent(processHandler, exitCode));
}
}
}
environment.setContentToReuse(descriptor);
} else {
project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processNotStarted(executor.getId(), environment);
}
}, o -> project.isDisposed());
}).rejected(e -> {
if (!(e instanceof ProcessCanceledException)) {
ExecutionException error = e instanceof ExecutionException ? (ExecutionException) e : new ExecutionException(e);
ExecutionUtil.handleExecutionError(project, ExecutionManager.getInstance(project).getContentManager().getToolWindowIdByEnvironment(environment), profile, error);
}
LOG.info(e);
project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processNotStarted(executor.getId(), environment);
});
};
if (ApplicationManager.getApplication().isUnitTestMode() && !myForceCompilationInTests) {
startRunnable.run();
} else {
compileAndRun(() -> TransactionGuard.submitTransaction(project, startRunnable), environment, state, () -> {
if (!project.isDisposed()) {
project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processNotStarted(executor.getId(), environment);
}
});
}
}
Aggregations