use of com.intellij.execution.ExecutionResult in project intellij-community by JetBrains.
the class DebuggerManagerImpl method attachVirtualMachine.
@Override
@Nullable
public DebuggerSession attachVirtualMachine(@NotNull DebugEnvironment environment) throws ExecutionException {
ApplicationManager.getApplication().assertIsDispatchThread();
DebugProcessEvents debugProcess = new DebugProcessEvents(myProject);
DebuggerSession session = DebuggerSession.create(environment.getSessionName(), debugProcess, environment);
ExecutionResult executionResult = session.getProcess().getExecutionResult();
if (executionResult == null) {
return null;
}
session.getContextManager().addListener(mySessionListener);
getContextManager().setState(DebuggerContextUtil.createDebuggerContext(session, session.getContextManager().getContext().getSuspendContext()), session.getState(), DebuggerSession.Event.CONTEXT, null);
final ProcessHandler processHandler = executionResult.getProcessHandler();
synchronized (mySessions) {
mySessions.put(processHandler, session);
}
if (!(processHandler instanceof RemoteDebugProcessHandler)) {
// add listener only to non-remote process handler:
// on Unix systems destroying process does not cause VMDeathEvent to be generated,
// so we need to call debugProcess.stop() explicitly for graceful termination.
// RemoteProcessHandler on the other hand will call debugProcess.stop() as a part of destroyProcess() and detachProcess() implementation,
// so we shouldn't add the listener to avoid calling stop() twice
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
ProcessHandler processHandler = event.getProcessHandler();
final DebugProcessImpl debugProcess = getDebugProcess(processHandler);
if (debugProcess != null) {
// if current thread is a "debugger manager thread", stop will execute synchronously
// it is KillableColoredProcessHandler responsibility to terminate VM
debugProcess.stop(willBeDestroyed && !(processHandler instanceof KillableColoredProcessHandler && ((KillableColoredProcessHandler) processHandler).shouldKillProcessSoftly()));
// if processWillTerminate() is called from AWT thread debugProcess.waitFor() will block it and the whole app will hang
if (!DebuggerManagerThreadImpl.isManagerThread()) {
if (SwingUtilities.isEventDispatchThread()) {
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
debugProcess.waitFor(10000);
}, "Waiting For Debugger Response", false, debugProcess.getProject());
} else {
debugProcess.waitFor(10000);
}
}
}
}
});
}
myDispatcher.getMulticaster().sessionCreated(session);
if (debugProcess.isDetached() || debugProcess.isDetaching()) {
session.dispose();
return null;
}
if (environment.isRemote()) {
// optimization: that way BatchEvaluator will not try to lookup the class file in remote VM
// which is an expensive operation when executed first time
debugProcess.putUserData(BatchEvaluator.REMOTE_SESSION_KEY, Boolean.TRUE);
}
return session;
}
use of com.intellij.execution.ExecutionResult in project intellij-community by JetBrains.
the class PythonRunner method doExecute.
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment env) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
ExecutionResult executionResult;
RunProfile profile = env.getRunProfile();
if (state instanceof PythonCommandLineState && profile instanceof CommandLinePatcher) {
executionResult = ((PythonCommandLineState) state).execute(env.getExecutor(), (CommandLinePatcher) profile);
} else {
executionResult = state.execute(env.getExecutor(), this);
}
return DefaultProgramRunnerKt.showRunContent(executionResult, env);
}
use of com.intellij.execution.ExecutionResult in project intellij-plugins by JetBrains.
the class KarmaDebugProgramRunner method execute.
@NotNull
@Override
protected Promise<RunContentDescriptor> execute(@NotNull ExecutionEnvironment environment, @NotNull RunProfileState state) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
ExecutionResult executionResult = state.execute(environment.getExecutor(), this);
if (executionResult == null) {
return Promise.resolve(null);
}
KarmaConsoleView consoleView = KarmaConsoleView.get(executionResult, state);
if (consoleView == null) {
return Promise.resolve(KarmaUtil.createDefaultDescriptor(executionResult, environment));
}
KarmaServer karmaServer = consoleView.getKarmaExecutionSession().getKarmaServer();
if (karmaServer.areBrowsersReady()) {
KarmaDebugBrowserSelector browserSelector = new KarmaDebugBrowserSelector(karmaServer.getCapturedBrowsers(), environment, consoleView);
DebuggableWebBrowser debuggableWebBrowser = browserSelector.selectDebugEngine();
if (debuggableWebBrowser == null) {
return Promises.resolvedPromise(KarmaUtil.createDefaultDescriptor(executionResult, environment));
}
return KarmaKt.prepareKarmaDebugger(environment.getProject(), debuggableWebBrowser, () -> createDescriptor(environment, executionResult, consoleView, karmaServer, debuggableWebBrowser));
} else {
RunContentDescriptor descriptor = KarmaUtil.createDefaultDescriptor(executionResult, environment);
karmaServer.onBrowsersReady(() -> ExecutionUtil.restartIfActive(descriptor));
return Promises.resolvedPromise(descriptor);
}
}
use of com.intellij.execution.ExecutionResult in project intellij-plugins by JetBrains.
the class KarmaCoverageProgramRunner method doExecute.
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment env) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
ExecutionResult executionResult = state.execute(env.getExecutor(), this);
if (executionResult == null) {
return null;
}
RunContentDescriptor descriptor = KarmaUtil.createDefaultDescriptor(executionResult, env);
KarmaConsoleView consoleView = KarmaConsoleView.get(executionResult, state);
if (consoleView == null) {
return descriptor;
}
KarmaServer server = consoleView.getKarmaExecutionSession().getKarmaServer();
if (server.areBrowsersReady()) {
listenForCoverageFile(env, server);
} else {
server.onBrowsersReady(() -> ExecutionUtil.restartIfActive(descriptor));
}
return descriptor;
}
use of com.intellij.execution.ExecutionResult in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoCoverageProgramRunner method doExecute.
@Nullable
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
assert state instanceof GoTestRunningState;
GoTestRunningState runningState = (GoTestRunningState) state;
GoTestRunConfiguration runConfiguration = ObjectUtils.tryCast(environment.getRunProfile(), GoTestRunConfiguration.class);
if (runConfiguration == null) {
return null;
}
FileDocumentManager.getInstance().saveAllDocuments();
CoverageEnabledConfiguration coverageEnabledConfiguration = CoverageEnabledConfiguration.getOrCreate(runConfiguration);
runningState.setCoverageFilePath(coverageEnabledConfiguration.getCoverageFilePath());
ExecutionResult executionResult = state.execute(environment.getExecutor(), this);
if (executionResult == null) {
return null;
}
CoverageHelper.attachToProcess(runConfiguration, executionResult.getProcessHandler(), environment.getRunnerSettings());
return new RunContentBuilder(executionResult, environment).showRunContent(environment.getContentToReuse());
}
Aggregations