Search in sources :

Example 1 with RunProfile

use of com.intellij.execution.configurations.RunProfile in project intellij-community by JetBrains.

the class PyDebuggerTask method runTestOn.

public void runTestOn(String sdkHome) throws Exception {
    final Project project = getProject();
    final ConfigurationFactory factory = PythonConfigurationType.getInstance().getConfigurationFactories()[0];
    final RunnerAndConfigurationSettings settings = RunManager.getInstance(project).createRunConfiguration("test", factory);
    myRunConfiguration = (PythonRunConfiguration) settings.getConfiguration();
    myRunConfiguration.setSdkHome(sdkHome);
    myRunConfiguration.setScriptName(getScriptName());
    myRunConfiguration.setWorkingDirectory(myFixture.getTempDirPath());
    myRunConfiguration.setScriptParameters(getScriptParameters());
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            RunManagerEx.getInstanceEx(project).addConfiguration(settings, false);
            RunManagerEx.getInstanceEx(project).setSelectedConfiguration(settings);
            Assert.assertSame(settings, RunManagerEx.getInstanceEx(project).getSelectedConfiguration());
        }
    }.execute();
    final PyDebugRunner runner = (PyDebugRunner) ProgramRunnerUtil.getRunner(getExecutorId(), settings);
    Assert.assertTrue(runner.canRun(getExecutorId(), myRunConfiguration));
    final Executor executor = DefaultDebugExecutor.getDebugExecutorInstance();
    final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, settings, project);
    final PythonCommandLineState pyState = (PythonCommandLineState) myRunConfiguration.getState(executor, env);
    assert pyState != null;
    pyState.setMultiprocessDebug(isMultiprocessDebug());
    final ServerSocket serverSocket;
    try {
        //noinspection SocketOpenedButNotSafelyClosed
        serverSocket = new ServerSocket(0);
    } catch (IOException e) {
        throw new ExecutionException("Failed to find free socket port", e);
    }
    final int serverLocalPort = serverSocket.getLocalPort();
    final RunProfile profile = env.getRunProfile();
    //turn off exception breakpoints by default
    PythonDebuggerTest.createExceptionBreak(myFixture, false, false, false);
    before();
    setProcessCanTerminate(false);
    myTerminateSemaphore = new Semaphore(0);
    new WriteAction<ExecutionResult>() {

        @Override
        protected void run(@NotNull Result<ExecutionResult> result) throws Throwable {
            myExecutionResult = pyState.execute(executor, runner.createCommandLinePatchers(myFixture.getProject(), pyState, profile, serverLocalPort));
            mySession = XDebuggerManager.getInstance(getProject()).startSession(env, new XDebugProcessStarter() {

                @NotNull
                public XDebugProcess start(@NotNull final XDebugSession session) {
                    myDebugProcess = new PyDebugProcess(session, serverSocket, myExecutionResult.getExecutionConsole(), myExecutionResult.getProcessHandler(), isMultiprocessDebug());
                    StringBuilder output = new StringBuilder();
                    myDebugProcess.getProcessHandler().addProcessListener(new ProcessAdapter() {

                        @Override
                        public void onTextAvailable(ProcessEvent event, Key outputType) {
                            output.append(event.getText());
                        }

                        @Override
                        public void processTerminated(ProcessEvent event) {
                            myTerminateSemaphore.release();
                            if (event.getExitCode() != 0 && !myProcessCanTerminate) {
                                Assert.fail("Process terminated unexpectedly\n" + output.toString());
                            }
                        }
                    });
                    myDebugProcess.getProcessHandler().startNotify();
                    return myDebugProcess;
                }
            });
            result.setResult(myExecutionResult);
        }
    }.execute().getResultObject();
    OutputPrinter myOutputPrinter = null;
    if (shouldPrintOutput) {
        myOutputPrinter = new OutputPrinter();
        myOutputPrinter.start();
    }
    myPausedSemaphore = new Semaphore(0);
    mySession.addSessionListener(new XDebugSessionListener() {

        @Override
        public void sessionPaused() {
            if (myPausedSemaphore != null) {
                myPausedSemaphore.release();
            }
        }
    });
    doTest(myOutputPrinter);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) PyDebugRunner(com.jetbrains.python.debugger.PyDebugRunner) Semaphore(java.util.concurrent.Semaphore) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) PyDebugProcess(com.jetbrains.python.debugger.PyDebugProcess) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) PythonCommandLineState(com.jetbrains.python.run.PythonCommandLineState) WriteAction(com.intellij.openapi.application.WriteAction) ProcessEvent(com.intellij.execution.process.ProcessEvent) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) RunProfile(com.intellij.execution.configurations.RunProfile) Project(com.intellij.openapi.project.Project) Key(com.intellij.openapi.util.Key)

Example 2 with RunProfile

use of com.intellij.execution.configurations.RunProfile in project intellij-community by JetBrains.

the class SMTestRunnerResultsForm method addToHistory.

private void addToHistory(final SMTestProxy.SMRootTestProxy root, TestConsoleProperties consoleProperties, Disposable parentDisposable) {
    final RunProfile configuration = consoleProperties.getConfiguration();
    if (configuration instanceof RunConfiguration && !(consoleProperties instanceof ImportedTestConsoleProperties) && !ApplicationManager.getApplication().isUnitTestMode() && !myDisposed) {
        final MySaveHistoryTask backgroundable = new MySaveHistoryTask(consoleProperties, root, (RunConfiguration) configuration);
        final BackgroundableProcessIndicator processIndicator = new BackgroundableProcessIndicator(backgroundable);
        Disposer.register(parentDisposable, new Disposable() {

            @Override
            public void dispose() {
                processIndicator.cancel();
                backgroundable.dispose();
            }
        });
        Disposer.register(parentDisposable, processIndicator);
        ProgressManager.getInstance().runProcessWithProgressAsynchronously(backgroundable, processIndicator);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) ImportedTestConsoleProperties(com.intellij.execution.testframework.sm.runner.history.ImportedTestConsoleProperties) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) RunProfile(com.intellij.execution.configurations.RunProfile)

Example 3 with RunProfile

use of com.intellij.execution.configurations.RunProfile in project intellij-community by JetBrains.

the class ImportedTestRunnableState method execute.

@Nullable
@Override
public ExecutionResult execute(Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
    final MyEmptyProcessHandler handler = new MyEmptyProcessHandler();
    final SMTRunnerConsoleProperties properties = myRunProfile.getProperties();
    RunProfile configuration;
    final String frameworkName;
    if (properties != null) {
        configuration = properties.getConfiguration();
        frameworkName = properties.getTestFrameworkName();
    } else {
        configuration = myRunProfile;
        frameworkName = "Import Test Results";
    }
    final ImportedTestConsoleProperties consoleProperties = new ImportedTestConsoleProperties(properties, myFile, handler, myRunProfile.getProject(), configuration, frameworkName, executor);
    final BaseTestsOutputConsoleView console = SMTestRunnerConnectionUtil.createConsole(consoleProperties.getTestFrameworkName(), consoleProperties);
    final JComponent component = console.getComponent();
    AbstractRerunFailedTestsAction rerunFailedTestsAction = null;
    if (component instanceof TestFrameworkRunningModel) {
        rerunFailedTestsAction = consoleProperties.createRerunFailedTestsAction(console);
        if (rerunFailedTestsAction != null) {
            rerunFailedTestsAction.setModelProvider(() -> (TestFrameworkRunningModel) component);
        }
    }
    console.attachToProcess(handler);
    final DefaultExecutionResult result = new DefaultExecutionResult(console, handler);
    if (rerunFailedTestsAction != null) {
        result.setRestartActions(rerunFailedTestsAction);
    }
    return result;
}
Also used : TestFrameworkRunningModel(com.intellij.execution.testframework.TestFrameworkRunningModel) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) AbstractRerunFailedTestsAction(com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction) RunProfile(com.intellij.execution.configurations.RunProfile) BaseTestsOutputConsoleView(com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView) SMTRunnerConsoleProperties(com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with RunProfile

use of com.intellij.execution.configurations.RunProfile in project intellij-plugins by JetBrains.

the class CfmlRunner method doExecute.

@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment env) throws ExecutionException {
    final RunProfile runProfileRaw = env.getRunProfile();
    if (runProfileRaw instanceof CfmlRunConfiguration) {
        FileDocumentManager.getInstance().saveAllDocuments();
        final CfmlRunConfiguration runProfile = (CfmlRunConfiguration) runProfileRaw;
        //check if CfmlRunConfiguration generated from default server http://localhost:8500/
        if (runProfile.isFromDefaultHost()) {
            showDefaultRunConfigWarn(env, runProfile);
        } else {
            final CfmlRunnerParameters params = runProfile.getRunnerParameters();
            BrowserLauncher.getInstance().browse(params.getUrl(), params.getCustomBrowser(), env.getProject());
        }
        return null;
    } else {
        return DefaultProgramRunnerKt.executeState(state, env, this);
    }
}
Also used : RunProfile(com.intellij.execution.configurations.RunProfile)

Example 5 with RunProfile

use of com.intellij.execution.configurations.RunProfile in project intellij-plugins by JetBrains.

the class DartRunner method doExecuteDartDebug.

private RunContentDescriptor doExecuteDartDebug(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment env, @Nullable final String dasExecutionContextId) throws RuntimeConfigurationError, ExecutionException {
    final DartSdk sdk = DartSdk.getDartSdk(env.getProject());
    // already checked
    assert (sdk != null);
    final RunProfile runConfiguration = env.getRunProfile();
    final VirtualFile contextFileOrDir;
    VirtualFile currentWorkingDirectory;
    final ExecutionResult executionResult;
    final String debuggingHost;
    final int observatoryPort;
    if (runConfiguration instanceof DartRunConfigurationBase) {
        contextFileOrDir = ((DartRunConfigurationBase) runConfiguration).getRunnerParameters().getDartFileOrDirectory();
        final String cwd = ((DartRunConfigurationBase) runConfiguration).getRunnerParameters().computeProcessWorkingDirectory(env.getProject());
        currentWorkingDirectory = LocalFileSystem.getInstance().findFileByPath((cwd));
        executionResult = state.execute(env.getExecutor(), this);
        if (executionResult == null) {
            return null;
        }
        debuggingHost = null;
        observatoryPort = ((DartCommandLineRunningState) state).getObservatoryPort();
    } else if (runConfiguration instanceof DartRemoteDebugConfiguration) {
        final String path = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getDartProjectPath();
        contextFileOrDir = LocalFileSystem.getInstance().findFileByPath(path);
        if (contextFileOrDir == null) {
            throw new RuntimeConfigurationError("Folder not found: " + FileUtil.toSystemDependentName(path));
        }
        currentWorkingDirectory = contextFileOrDir;
        executionResult = null;
        debuggingHost = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getHost();
        observatoryPort = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getPort();
    } else {
        LOG.error("Unexpected run configuration: " + runConfiguration.getClass().getName());
        return null;
    }
    FileDocumentManager.getInstance().saveAllDocuments();
    final XDebuggerManager debuggerManager = XDebuggerManager.getInstance(env.getProject());
    final XDebugSession debugSession = debuggerManager.startSession(env, new XDebugProcessStarter() {

        @Override
        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            final DartUrlResolver dartUrlResolver = getDartUrlResolver(env.getProject(), contextFileOrDir);
            return new DartVmServiceDebugProcess(session, StringUtil.notNullize(debuggingHost, "localhost"), observatoryPort, executionResult, dartUrlResolver, dasExecutionContextId, runConfiguration instanceof DartRemoteDebugConfiguration, getTimeout(), currentWorkingDirectory);
        }
    });
    return debugSession.getRunContentDescriptor();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) DartRunConfigurationBase(com.jetbrains.lang.dart.ide.runner.base.DartRunConfigurationBase) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) ExecutionResult(com.intellij.execution.ExecutionResult) RunProfile(com.intellij.execution.configurations.RunProfile) NotNull(org.jetbrains.annotations.NotNull) DartVmServiceDebugProcess(com.jetbrains.lang.dart.ide.runner.server.vmService.DartVmServiceDebugProcess) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartRemoteDebugConfiguration(com.jetbrains.lang.dart.ide.runner.server.DartRemoteDebugConfiguration) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Aggregations

RunProfile (com.intellij.execution.configurations.RunProfile)33 ProcessHandler (com.intellij.execution.process.ProcessHandler)9 Project (com.intellij.openapi.project.Project)8 NotNull (org.jetbrains.annotations.NotNull)8 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)7 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)7 RunConfigurationBase (com.intellij.execution.configurations.RunConfigurationBase)6 Nullable (org.jetbrains.annotations.Nullable)6 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)5 ExecutionException (com.intellij.execution.ExecutionException)4 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)4 Test (org.junit.Test)4 AndroidSessionInfo (com.android.tools.idea.run.AndroidSessionInfo)3 ExecutionResult (com.intellij.execution.ExecutionResult)3 Module (com.intellij.openapi.module.Module)3 XDebugSession (com.intellij.xdebugger.XDebugSession)3 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)2 CompatibilityAwareRunProfile (com.intellij.execution.configuration.CompatibilityAwareRunProfile)2 RemoteConnection (com.intellij.execution.configurations.RemoteConnection)2