Search in sources :

Example 21 with ExecutionResult

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;
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionResult(com.intellij.execution.ExecutionResult) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with ExecutionResult

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);
}
Also used : ExecutionResult(com.intellij.execution.ExecutionResult) RunProfile(com.intellij.execution.configurations.RunProfile)

Example 23 with ExecutionResult

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);
    }
}
Also used : KarmaServer(com.intellij.javascript.karma.server.KarmaServer) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) KarmaConsoleView(com.intellij.javascript.karma.execution.KarmaConsoleView) ExecutionResult(com.intellij.execution.ExecutionResult) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with ExecutionResult

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;
}
Also used : KarmaServer(com.intellij.javascript.karma.server.KarmaServer) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) KarmaConsoleView(com.intellij.javascript.karma.execution.KarmaConsoleView) ExecutionResult(com.intellij.execution.ExecutionResult)

Example 25 with ExecutionResult

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());
}
Also used : CoverageEnabledConfiguration(com.intellij.execution.configurations.coverage.CoverageEnabledConfiguration) GoTestRunConfiguration(com.goide.runconfig.testing.GoTestRunConfiguration) ExecutionResult(com.intellij.execution.ExecutionResult) GoTestRunningState(com.goide.runconfig.testing.GoTestRunningState) RunContentBuilder(com.intellij.execution.runners.RunContentBuilder) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExecutionResult (com.intellij.execution.ExecutionResult)25 Nullable (org.jetbrains.annotations.Nullable)10 NotNull (org.jetbrains.annotations.NotNull)9 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)6 RunContentBuilder (com.intellij.execution.runners.RunContentBuilder)6 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)6 ProcessHandler (com.intellij.execution.process.ProcessHandler)5 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)5 XDebugSession (com.intellij.xdebugger.XDebugSession)5 ExecutionException (com.intellij.execution.ExecutionException)4 Project (com.intellij.openapi.project.Project)3 XDebugProcess (com.intellij.xdebugger.XDebugProcess)3 DartUrlResolver (com.jetbrains.lang.dart.util.DartUrlResolver)3 JstdBrowserInfo (com.google.jstestdriver.idea.server.JstdBrowserInfo)2 JstdServerLifeCycleAdapter (com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter)2 DebugEnvironment (com.intellij.debugger.DebugEnvironment)2 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)2 RunProfile (com.intellij.execution.configurations.RunProfile)2 NopProcessHandler (com.intellij.execution.process.NopProcessHandler)2 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)2