use of com.intellij.execution.runners.ExecutionEnvironment 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.runners.ExecutionEnvironment in project intellij-community by JetBrains.
the class ExecutionManagerImpl method compileAndRun.
@Override
public void compileAndRun(@NotNull final Runnable startRunnable, @NotNull final ExecutionEnvironment environment, @Nullable final RunProfileState state, @Nullable final Runnable onCancelRunnable) {
long id = environment.getExecutionId();
if (id == 0) {
id = environment.assignNewExecutionId();
}
RunProfile profile = environment.getRunProfile();
if (!(profile instanceof RunConfiguration)) {
startRunnable.run();
return;
}
final RunConfiguration runConfiguration = (RunConfiguration) profile;
final List<BeforeRunTask> beforeRunTasks = RunManagerEx.getInstanceEx(myProject).getBeforeRunTasks(runConfiguration);
if (beforeRunTasks.isEmpty()) {
startRunnable.run();
} else {
DataContext context = environment.getDataContext();
final DataContext projectContext = context != null ? context : SimpleDataContext.getProjectContext(myProject);
final long finalId = id;
final Long executionSessionId = new Long(id);
ApplicationManager.getApplication().executeOnPooledThread(() -> {
for (BeforeRunTask task : beforeRunTasks) {
if (myProject.isDisposed()) {
return;
}
@SuppressWarnings("unchecked") BeforeRunTaskProvider<BeforeRunTask> provider = BeforeRunTaskProvider.getProvider(myProject, task.getProviderId());
if (provider == null) {
LOG.warn("Cannot find BeforeRunTaskProvider for id='" + task.getProviderId() + "'");
continue;
}
ExecutionEnvironment taskEnvironment = new ExecutionEnvironmentBuilder(environment).contentToReuse(null).build();
taskEnvironment.setExecutionId(finalId);
EXECUTION_SESSION_ID_KEY.set(taskEnvironment, executionSessionId);
if (!provider.executeTask(projectContext, runConfiguration, taskEnvironment, task)) {
if (onCancelRunnable != null) {
SwingUtilities.invokeLater(onCancelRunnable);
}
return;
}
}
doRun(environment, startRunnable);
});
}
}
use of com.intellij.execution.runners.ExecutionEnvironment 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);
}
});
}
}
use of com.intellij.execution.runners.ExecutionEnvironment in project intellij-community by JetBrains.
the class RunConfigurationBeforeRunProvider method doExecuteTask.
public static boolean doExecuteTask(@NotNull final ExecutionEnvironment env, @NotNull final RunnerAndConfigurationSettings settings) {
final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
final String executorId = executor.getId();
ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.createOrNull(executor, settings);
if (builder == null) {
return false;
}
ExecutionTarget compatibleTarget = getCompatibleTarget(env, settings);
if (compatibleTarget == null) {
return false;
}
final ExecutionEnvironment environment = builder.target(compatibleTarget).build();
environment.setExecutionId(env.getExecutionId());
if (!environment.getRunner().canRun(executorId, environment.getRunProfile())) {
return false;
} else {
beforeRun(environment);
return doRunTask(executorId, environment, environment.getRunner());
}
}
use of com.intellij.execution.runners.ExecutionEnvironment in project intellij-community by JetBrains.
the class DebuggerTestCase method createLocalSession.
protected DebuggerSession createLocalSession(final JavaParameters javaParameters) throws ExecutionException, InterruptedException {
createBreakpoints(javaParameters.getMainClass());
DebuggerSettings.getInstance().DEBUGGER_TRANSPORT = DebuggerSettings.SOCKET_TRANSPORT;
GenericDebuggerRunnerSettings debuggerRunnerSettings = new GenericDebuggerRunnerSettings();
debuggerRunnerSettings.LOCAL = true;
final RemoteConnection debugParameters = DebuggerManagerImpl.createDebugParameters(javaParameters, debuggerRunnerSettings, false);
ExecutionEnvironment environment = new ExecutionEnvironmentBuilder(myProject, DefaultDebugExecutor.getDebugExecutorInstance()).runnerSettings(debuggerRunnerSettings).runProfile(new MockConfiguration()).build();
final JavaCommandLineState javaCommandLineState = new JavaCommandLineState(environment) {
@Override
protected JavaParameters createJavaParameters() {
return javaParameters;
}
@Override
protected GeneralCommandLine createCommandLine() throws ExecutionException {
return getJavaParameters().toCommandLine();
}
};
ApplicationManager.getApplication().invokeAndWait(() -> {
try {
myDebuggerSession = DebuggerManagerEx.getInstanceEx(myProject).attachVirtualMachine(new DefaultDebugEnvironment(new ExecutionEnvironmentBuilder(myProject, DefaultDebugExecutor.getDebugExecutorInstance()).runProfile(new MockConfiguration()).build(), javaCommandLineState, debugParameters, false));
XDebuggerManager.getInstance(myProject).startSession(javaCommandLineState.getEnvironment(), new XDebugProcessStarter() {
@Override
@NotNull
public XDebugProcess start(@NotNull XDebugSession session) {
return JavaDebugProcess.create(session, myDebuggerSession);
}
});
} catch (ExecutionException e) {
LOG.error(e);
}
});
myDebugProcess = myDebuggerSession.getProcess();
myDebugProcess.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
print(event.getText(), outputType);
}
});
assertNotNull(myDebuggerSession);
assertNotNull(myDebugProcess);
return myDebuggerSession;
}
Aggregations