Search in sources :

Example 1 with SMTRunnerConsoleProperties

use of com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties in project intellij-community by JetBrains.

the class JavaTestFrameworkRunnableState method execute.

@NotNull
@Override
public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
    final RunnerSettings runnerSettings = getRunnerSettings();
    final SMTRunnerConsoleProperties testConsoleProperties = getConfiguration().createTestConsoleProperties(executor);
    testConsoleProperties.setIfUndefined(TestConsoleProperties.HIDE_PASSED_TESTS, false);
    final BaseTestsOutputConsoleView consoleView = SMTestRunnerConnectionUtil.createConsole(getFrameworkName(), testConsoleProperties);
    final SMTestRunnerResultsForm viewer = ((SMTRunnerConsoleView) consoleView).getResultsViewer();
    Disposer.register(getConfiguration().getProject(), consoleView);
    final OSProcessHandler handler = createHandler(executor);
    consoleView.attachToProcess(handler);
    final AbstractTestProxy root = viewer.getRoot();
    if (root instanceof TestProxyRoot) {
        ((TestProxyRoot) root).setHandler(handler);
    }
    handler.addProcessListener(new ProcessAdapter() {

        @Override
        public void startNotified(ProcessEvent event) {
            if (getConfiguration().isSaveOutputToFile()) {
                final File file = OutputFileUtil.getOutputFile(getConfiguration());
                root.setOutputFilePath(file != null ? file.getAbsolutePath() : null);
            }
        }

        @Override
        public void processTerminated(ProcessEvent event) {
            Runnable runnable = () -> {
                root.flushOutputFile();
                deleteTempFiles();
                clear();
            };
            UIUtil.invokeLaterIfNeeded(runnable);
            handler.removeProcessListener(this);
        }
    });
    AbstractRerunFailedTestsAction rerunFailedTestsAction = testConsoleProperties.createRerunFailedTestsAction(consoleView);
    LOG.assertTrue(rerunFailedTestsAction != null);
    rerunFailedTestsAction.setModelProvider(() -> viewer);
    final DefaultExecutionResult result = new DefaultExecutionResult(consoleView, handler);
    result.setRestartActions(rerunFailedTestsAction, new ToggleAutoTestAction() {

        @Override
        public boolean isDelayApplicable() {
            return false;
        }

        @Override
        public AbstractAutoTestManager getAutoTestManager(Project project) {
            return JavaAutoRunManager.getInstance(project);
        }
    });
    JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(getConfiguration(), handler, runnerSettings);
    return result;
}
Also used : SMTestRunnerResultsForm(com.intellij.execution.testframework.sm.runner.ui.SMTestRunnerResultsForm) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) AbstractAutoTestManager(com.intellij.execution.testframework.autotest.AbstractAutoTestManager) GenericDebuggerRunnerSettings(com.intellij.debugger.impl.GenericDebuggerRunnerSettings) ProcessEvent(com.intellij.execution.process.ProcessEvent) AbstractRerunFailedTestsAction(com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction) ToggleAutoTestAction(com.intellij.execution.testframework.autotest.ToggleAutoTestAction) BaseTestsOutputConsoleView(com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView) SMTRunnerConsoleProperties(com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties) SMTRunnerConsoleView(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView) Project(com.intellij.openapi.project.Project) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with SMTRunnerConsoleProperties

use of com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties in project intellij-community by JetBrains.

the class AbstractImportTestsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    LOG.assertTrue(project != null);
    final VirtualFile file = getFile(project);
    if (file != null) {
        try {
            final ImportRunProfile profile = new ImportRunProfile(file, project);
            SMTRunnerConsoleProperties properties = profile.getProperties();
            if (properties == null) {
                properties = myProperties;
                LOG.info("Failed to detect test framework in " + file.getPath() + "; use " + (properties != null ? properties.getTestFrameworkName() + " from toolbar" : "no properties"));
            }
            final Executor executor = properties != null ? properties.getExecutor() : ExecutorRegistry.getInstance().getExecutorById(DefaultRunExecutor.EXECUTOR_ID);
            ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.create(project, executor, profile);
            ExecutionTarget target = profile.getTarget();
            if (target != null) {
                builder = builder.target(target);
            }
            final RunConfiguration initialConfiguration = profile.getInitialConfiguration();
            final ProgramRunner runner = initialConfiguration != null ? RunnerRegistry.getInstance().getRunner(executor.getId(), initialConfiguration) : null;
            if (runner != null) {
                builder = builder.runner(runner);
            }
            builder.buildAndExecute();
        } catch (ExecutionException e1) {
            Messages.showErrorDialog(project, e1.getMessage(), "Import Failed");
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ProgramRunner(com.intellij.execution.runners.ProgramRunner) SMTRunnerConsoleProperties(com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties)

Example 3 with SMTRunnerConsoleProperties

use of com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties 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 SMTRunnerConsoleProperties

use of com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties in project intellij-plugins by JetBrains.

the class CucumberJavaRunConfiguration method getState.

@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
    return new JavaApplicationCommandLineState<CucumberJavaRunConfiguration>(CucumberJavaRunConfiguration.this, env) {

        protected JavaParameters createJavaParameters() throws ExecutionException {
            final JavaParameters params = new JavaParameters();
            final JavaRunConfigurationModule module = getConfigurationModule();
            final int classPathType = JavaParameters.JDK_AND_CLASSES_AND_TESTS;
            final String jreHome = CucumberJavaRunConfiguration.this.ALTERNATIVE_JRE_PATH_ENABLED ? ALTERNATIVE_JRE_PATH : null;
            JavaParametersUtil.configureModule(module, params, classPathType, jreHome);
            JavaParametersUtil.configureConfiguration(params, CucumberJavaRunConfiguration.this);
            String path = getSMRunnerPath();
            params.getClassPath().add(path);
            params.setMainClass(MAIN_CLASS_NAME);
            for (RunConfigurationExtension ext : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
                ext.updateJavaParameters(CucumberJavaRunConfiguration.this, params, getRunnerSettings());
            }
            final String glueValue = getGlue();
            if (glueValue != null && !StringUtil.isEmpty(glueValue)) {
                final String[] glues = glueValue.split(" ");
                for (String glue : glues) {
                    if (!StringUtil.isEmpty(glue)) {
                        params.getProgramParametersList().addParametersString(" --glue " + glue);
                    }
                }
            }
            File f = new File(myFilePath);
            if (!f.isDirectory()) {
                f = f.getParentFile();
            }
            params.getVMParametersList().addParametersString("-Dorg.jetbrains.run.directory=\"" + f.getAbsolutePath() + "\"");
            params.getProgramParametersList().addParametersString("\"" + myFilePath + "\"");
            return params;
        }

        @Nullable
        private ConsoleView createConsole(@NotNull final Executor executor, ProcessHandler processHandler) throws ExecutionException {
            // console view
            final String testFrameworkName = "cucumber";
            final CucumberJavaRunConfiguration runConfiguration = CucumberJavaRunConfiguration.this;
            final SMTRunnerConsoleProperties consoleProperties = new SMTRunnerConsoleProperties(runConfiguration, testFrameworkName, executor);
            return SMTestRunnerConnectionUtil.createAndAttachConsole(testFrameworkName, processHandler, consoleProperties);
        }

        @NotNull
        @Override
        public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
            final ProcessHandler processHandler = startProcess();
            final ConsoleView console = createConsole(executor, processHandler);
            return new DefaultExecutionResult(console, processHandler, createActions(console, processHandler, executor));
        }
    };
}
Also used : ConsoleView(com.intellij.execution.ui.ConsoleView) NotNull(org.jetbrains.annotations.NotNull) SMTRunnerConsoleProperties(com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner) File(java.io.File)

Example 5 with SMTRunnerConsoleProperties

use of com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties in project intellij-plugins by JetBrains.

the class FlexBaseRunner method createFlexUnitRunnerConsole.

public static ExecutionConsole createFlexUnitRunnerConsole(Project project, ExecutionEnvironment env, ProcessHandler processHandler) throws ExecutionException {
    FlexStackTraceFilter stackTraceFilter = new FlexStackTraceFilter(project);
    SMTRunnerConsoleProperties consoleProps = new FlexUnitConsoleProperties((FlexUnitRunConfiguration) env.getRunProfile(), env);
    consoleProps.addStackTraceFilter(stackTraceFilter);
    BaseTestsOutputConsoleView consoleView = SMTestRunnerConnectionUtil.createAndAttachConsole("FlexUnit", processHandler, consoleProps);
    consoleView.addMessageFilter(stackTraceFilter);
    Disposer.register(project, consoleView);
    return consoleView;
}
Also used : BaseTestsOutputConsoleView(com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView) SMTRunnerConsoleProperties(com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties) FlexStackTraceFilter(com.intellij.lang.javascript.flex.FlexStackTraceFilter)

Aggregations

SMTRunnerConsoleProperties (com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties)8 BaseTestsOutputConsoleView (com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView)3 NotNull (org.jetbrains.annotations.NotNull)3 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)2 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)2 ProcessHandler (com.intellij.execution.process.ProcessHandler)2 ProgramRunner (com.intellij.execution.runners.ProgramRunner)2 AbstractRerunFailedTestsAction (com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction)2 SMTRunnerConsoleView (com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView)2 ConsoleView (com.intellij.execution.ui.ConsoleView)2 Project (com.intellij.openapi.project.Project)2 AndroidTestConsoleProperties (com.android.tools.idea.testartifacts.instrumented.AndroidTestConsoleProperties)1 AndroidTestRunConfiguration (com.android.tools.idea.testartifacts.instrumented.AndroidTestRunConfiguration)1 AndroidJUnitConfiguration (com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration)1 GenericDebuggerRunnerSettings (com.intellij.debugger.impl.GenericDebuggerRunnerSettings)1 Executor (com.intellij.execution.Executor)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 RunProfile (com.intellij.execution.configurations.RunProfile)1 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)1 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)1