Search in sources :

Example 21 with ProgramRunner

use of com.intellij.execution.runners.ProgramRunner in project intellij-plugins by JetBrains.

the class FlexUnitExecutionTest method doTest.

private AbstractTestProxy doTest(boolean debugNotRun, FlexUnitRunnerParameters.Scope testScope, String testClassOrPackage, @Nullable String testMethod, @Nullable String projectRoot, @Nullable FlexUnitRunnerParameters.OutputLogLevel outputLogLevel, String... files) throws Exception {
    configureByFiles(projectRoot, files);
    final Ref<IXMLElement> expected = new Ref<>();
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> WriteAction.run(() -> {
        try {
            Collection<IXMLElement> collection = JSTestUtils.extractXml(myEditor.getDocument(), "testResults");
            assertEquals("Invalid expected structure", 1, collection.size());
            expected.set(collection.iterator().next());
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }));
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> WriteAction.run(() -> FlexTestUtils.modifyBuildConfiguration(myModule, configuration -> configuration.setTargetPlatform(myTargetPlatform))));
    final RunnerAndConfigurationSettings runnerAndConfigurationSettings = RunManager.getInstance(myProject).createRunConfiguration("test", FlexUnitRunConfigurationType.getFactory());
    final FlexUnitRunConfiguration flexUnitRunConfig = (FlexUnitRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
    final FlexUnitRunnerParameters params = flexUnitRunConfig.getRunnerParameters();
    params.setModuleName(myModule.getName());
    params.setBCName(FlexBuildConfigurationManager.getInstance(myModule).getBuildConfigurations()[0].getName());
    params.setOutputLogLevel(outputLogLevel);
    params.setScope(testScope);
    switch(testScope) {
        case Class:
            params.setClassName(testClassOrPackage);
            break;
        case Method:
            params.setClassName(testClassOrPackage);
            params.setMethodName(testMethod);
            break;
        case Package:
            params.setPackageName(testClassOrPackage);
            break;
        default:
            fail("Unknown scope: " + testScope);
    }
    flexUnitRunConfig.checkConfiguration();
    final ProgramRunner runner = new FlexUnitTestRunner();
    final Executor executor = debugNotRun ? DefaultDebugExecutor.getDebugExecutorInstance() : DefaultRunExecutor.getRunExecutorInstance();
    final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, runnerAndConfigurationSettings, getProject());
    final Semaphore compilation = new Semaphore();
    compilation.down();
    final Semaphore execution = new Semaphore();
    execution.down();
    final Semaphore startup = new Semaphore();
    final ProcessListener listener = new ProcessListener() {

        @Override
        public void startNotified(ProcessEvent event) {
            startup.up();
        }

        @Override
        public void processTerminated(ProcessEvent event) {
            execution.up();
        }

        @Override
        public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
        }

        @Override
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            System.out.println("FlexUnit: " + event.getText());
        }
    };
    final Ref<ExecutionConsole> executionConsole = new Ref<>();
    ApplicationManager.getApplication().invokeLater(() -> {
        try {
            runner.execute(env, new ProgramRunner.Callback() {

                @Override
                public void processStarted(RunContentDescriptor descriptor) {
                    compilation.up();
                    startup.down();
                    descriptor.getProcessHandler().addProcessListener(listener);
                    executionConsole.set(descriptor.getExecutionConsole());
                }
            });
        } catch (Throwable t) {
            t.printStackTrace();
            fail(t.getMessage());
            compilation.up();
            startup.up();
            execution.up();
        }
    });
    if (!compilation.waitFor(COMPILATION_TIMEOUT * 1000)) {
        fail("Compilation did not succeed in " + COMPILATION_TIMEOUT + " seconds. There was an error or it took too long\n" + FlexCompilerHandler.getInstance(myProject).getLastCompilationMessages());
    }
    if (!startup.waitFor(STARTUP_TIMEOUT * 1000)) {
        fail("Process was not started in " + STARTUP_TIMEOUT + " seconds");
    }
    if (!execution.waitFor(EXECUTION_TIMEOUT * 1000)) {
        fail("Execution did not finish in " + EXECUTION_TIMEOUT + " seconds");
    }
    // give tests tree some time to stabilize
    Thread.sleep(200);
    final AbstractTestProxy testRoot = ((SMTRunnerConsoleView) executionConsole.get()).getResultsViewer().getRoot();
    checkResults(expected.get(), testRoot);
    if (outputLogLevel == null) {
        checkOutput(testRoot, outputLogLevel);
    }
    return testRoot;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) TargetPlatform(com.intellij.flex.model.bc.TargetPlatform) ServerSocket(java.net.ServerSocket) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType) FlexCompilerHandler(com.intellij.lang.javascript.flex.build.FlexCompilerHandler) Semaphore(com.intellij.util.concurrency.Semaphore) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Map(java.util.Map) TestStateInfo(com.intellij.execution.testframework.sm.runner.states.TestStateInfo) FlexUnitRunConfigurationType(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfigurationType) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) Collection(java.util.Collection) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) Nullable(org.jetbrains.annotations.Nullable) Printable(com.intellij.execution.testframework.Printable) ProcessListener(com.intellij.execution.process.ProcessListener) SMTRunnerConsoleView(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JSTestOptions(com.intellij.lang.javascript.JSTestOptions) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ProcessEvent(com.intellij.execution.process.ProcessEvent) NotNull(org.jetbrains.annotations.NotNull) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) Ref(com.intellij.openapi.util.Ref) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) CodeInsightTestCase(com.intellij.codeInsight.CodeInsightTestCase) WriteAction(com.intellij.openapi.application.WriteAction) JSTestOption(com.intellij.lang.javascript.JSTestOption) FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) FlexUnitLibs(com.intellij.flex.util.FlexUnitLibs) HashMap(java.util.HashMap) CompilerProjectExtension(com.intellij.openapi.roots.CompilerProjectExtension) IXMLElement(net.n3.nanoxml.IXMLElement) SocketTimeoutException(java.net.SocketTimeoutException) RunManager(com.intellij.execution.RunManager) ModuleType(com.intellij.openapi.module.ModuleType) FlexTestUtils(com.intellij.flex.util.FlexTestUtils) ThrowableRunnable(com.intellij.util.ThrowableRunnable) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ProgramRunner(com.intellij.execution.runners.ProgramRunner) FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) Key(com.intellij.openapi.util.Key) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) IOException(java.io.IOException) Executor(com.intellij.execution.Executor) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) JSTestUtils(com.intellij.lang.javascript.JSTestUtils) Printer(com.intellij.execution.testframework.Printer) FlexCompilerProjectConfiguration(com.intellij.lang.javascript.flex.build.FlexCompilerProjectConfiguration) Assert(org.junit.Assert) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessListener(com.intellij.execution.process.ProcessListener) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) Semaphore(com.intellij.util.concurrency.Semaphore) IXMLElement(net.n3.nanoxml.IXMLElement) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) Ref(com.intellij.openapi.util.Ref) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Key(com.intellij.openapi.util.Key)

Example 22 with ProgramRunner

use of com.intellij.execution.runners.ProgramRunner in project intellij-community by JetBrains.

the class SingleConfigurationConfigurable method getValidationResult.

@Nullable
private ValidationResult getValidationResult() {
    if (!myValidationResultValid) {
        myLastValidationResult = null;
        RunnerAndConfigurationSettings snapshot = null;
        try {
            snapshot = getSnapshot();
            if (snapshot != null) {
                snapshot.setName(getNameText());
                snapshot.checkSettings(myExecutor);
                for (Executor executor : ExecutorRegistry.getInstance().getRegisteredExecutors()) {
                    ProgramRunner runner = RunnerRegistry.getInstance().getRunner(executor.getId(), snapshot.getConfiguration());
                    if (runner != null) {
                        checkConfiguration(runner, snapshot);
                    }
                }
            }
        } catch (RuntimeConfigurationException exception) {
            final Runnable quickFix = exception.getQuickFix();
            Runnable resultQuickFix;
            if (quickFix != null && snapshot != null) {
                final RunnerAndConfigurationSettings fixedSettings = snapshot;
                resultQuickFix = () -> {
                    quickFix.run();
                    getEditor().resetFrom(fixedSettings);
                };
            } else {
                resultQuickFix = quickFix;
            }
            myLastValidationResult = new ValidationResult(exception.getLocalizedMessage(), exception.getTitle(), resultQuickFix);
        } catch (ConfigurationException e) {
            myLastValidationResult = new ValidationResult(e.getLocalizedMessage(), ExecutionBundle.message("invalid.data.dialog.title"), null);
        }
        myValidationResultValid = true;
    }
    return myLastValidationResult;
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with ProgramRunner

use of com.intellij.execution.runners.ProgramRunner in project intellij-community by JetBrains.

the class RemoteProcessSupport method startProcess.

private void startProcess(Target target, Parameters configuration, @NotNull Pair<Target, Parameters> key) {
    ProgramRunner runner = new DefaultProgramRunner() {

        @Override
        @NotNull
        public String getRunnerId() {
            return "MyRunner";
        }

        @Override
        public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
            return true;
        }
    };
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    ProcessHandler processHandler;
    try {
        RunProfileState state = getRunProfileState(target, configuration, executor);
        ExecutionResult result = state.execute(executor, runner);
        //noinspection ConstantConditions
        processHandler = result.getProcessHandler();
    } catch (Exception e) {
        dropProcessInfo(key, e instanceof ExecutionException ? e.getMessage() : ExceptionUtil.getUserStackTrace(e, LOG), null);
        return;
    }
    processHandler.addProcessListener(getProcessListener(key));
    processHandler.startNotify();
}
Also used : DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) RunProfileState(com.intellij.execution.configurations.RunProfileState) DefaultProgramRunner(com.intellij.execution.runners.DefaultProgramRunner) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionResult(com.intellij.execution.ExecutionResult) RunProfile(com.intellij.execution.configurations.RunProfile) DefaultProgramRunner(com.intellij.execution.runners.DefaultProgramRunner) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull) ExecutionException(com.intellij.execution.ExecutionException)

Example 24 with ProgramRunner

use of com.intellij.execution.runners.ProgramRunner in project intellij-community by JetBrains.

the class ExecutorAction method isEnabled4.

@Override
protected boolean isEnabled4(DashboardRunConfigurationNode node) {
    String executorId = getExecutor().getId();
    ProgramRunner runner = ProgramRunnerUtil.getRunner(executorId, node.getConfigurationSettings());
    return runner != null && runner.canRun(executorId, node.getConfigurationSettings().getConfiguration());
}
Also used : ProgramRunner(com.intellij.execution.runners.ProgramRunner)

Example 25 with ProgramRunner

use of com.intellij.execution.runners.ProgramRunner in project intellij-community by JetBrains.

the class ExternalSystemRunConfigurationMenu method update.

@Override
public void update(AnActionEvent e) {
    for (AnAction action : getChildActionsOrStubs()) {
        if (action instanceof ExecuteExternalSystemRunConfigurationAction) {
            remove(action);
        }
    }
    final Project project = e.getProject();
    final List<ExternalSystemNode> selectedNodes = ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext());
    if (selectedNodes == null || selectedNodes.size() != 1 || !(selectedNodes.get(0) instanceof RunConfigurationNode))
        return;
    final RunnerAndConfigurationSettings settings = ((RunConfigurationNode) selectedNodes.get(0)).getSettings();
    if (settings == null || project == null)
        return;
    Executor[] executors = ExecutorRegistry.getInstance().getRegisteredExecutors();
    for (int i = executors.length; --i >= 0; ) {
        final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(executors[i].getId(), settings.getConfiguration());
        AnAction action = new ExecuteExternalSystemRunConfigurationAction(executors[i], runner != null, project, settings);
        addAction(action, Constraints.FIRST);
    }
    super.update(e);
}
Also used : Project(com.intellij.openapi.project.Project) ExternalSystemNode(com.intellij.openapi.externalSystem.view.ExternalSystemNode) RunConfigurationNode(com.intellij.openapi.externalSystem.view.RunConfigurationNode) ProgramRunner(com.intellij.execution.runners.ProgramRunner) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

ProgramRunner (com.intellij.execution.runners.ProgramRunner)30 NotNull (org.jetbrains.annotations.NotNull)13 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)10 ProcessHandler (com.intellij.execution.process.ProcessHandler)9 Executor (com.intellij.execution.Executor)8 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)7 Project (com.intellij.openapi.project.Project)5 ProcessEvent (com.intellij.execution.process.ProcessEvent)4 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)4 Nullable (org.jetbrains.annotations.Nullable)4 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)3 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)3 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)3 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)3 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)3 File (java.io.File)3 ExecutionException (com.intellij.execution.ExecutionException)2 ExecutionResult (com.intellij.execution.ExecutionResult)2 CommandLineState (com.intellij.execution.configurations.CommandLineState)2 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)2