Search in sources :

Example 6 with ProgramRunner

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

the class ExternalSystemBeforeRunTaskProvider method executeTask.

@Override
public boolean executeTask(DataContext context, RunConfiguration configuration, ExecutionEnvironment env, ExternalSystemBeforeRunTask beforeRunTask) {
    final ExternalSystemTaskExecutionSettings executionSettings = beforeRunTask.getTaskExecutionSettings();
    final List<ExternalTaskPojo> tasks = ContainerUtilRt.newArrayList();
    for (String taskName : executionSettings.getTaskNames()) {
        tasks.add(new ExternalTaskPojo(taskName, executionSettings.getExternalProjectPath(), null));
    }
    if (tasks.isEmpty())
        return true;
    ExecutionEnvironment environment = ExternalSystemUtil.createExecutionEnvironment(myProject, mySystemId, executionSettings, DefaultRunExecutor.EXECUTOR_ID);
    if (environment == null)
        return false;
    final ProgramRunner runner = environment.getRunner();
    environment.setExecutionId(env.getExecutionId());
    return RunConfigurationBeforeRunProvider.doRunTask(DefaultRunExecutor.getRunExecutorInstance().getId(), environment, runner);
}
Also used : ExternalTaskPojo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskPojo) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Example 7 with ProgramRunner

use of com.intellij.execution.runners.ProgramRunner 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 8 with ProgramRunner

use of com.intellij.execution.runners.ProgramRunner 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 9 with ProgramRunner

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

the class ToolRunProfile method getState.

@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) {
    final Project project = env.getProject();
    if (myCommandLine == null) {
        // can return null if creation of cmd line has been cancelled
        return null;
    }
    final CommandLineState commandLineState = new CommandLineState(env) {

        GeneralCommandLine createCommandLine() {
            return myCommandLine;
        }

        @Override
        @NotNull
        protected OSProcessHandler startProcess() throws ExecutionException {
            final GeneralCommandLine commandLine = createCommandLine();
            final OSProcessHandler processHandler = new ColoredProcessHandler(commandLine);
            ProcessTerminatedListener.attach(processHandler);
            return processHandler;
        }

        @Override
        @NotNull
        public ExecutionResult execute(@NotNull final Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
            final ExecutionResult result = super.execute(executor, runner);
            final ProcessHandler processHandler = result.getProcessHandler();
            if (processHandler != null) {
                processHandler.addProcessListener(new ToolProcessAdapter(project, myTool.synchronizeAfterExecution(), getName()));
                processHandler.addProcessListener(new ProcessAdapter() {

                    @Override
                    public void onTextAvailable(ProcessEvent event, Key outputType) {
                        if ((outputType == ProcessOutputTypes.STDOUT && myTool.isShowConsoleOnStdOut()) || (outputType == ProcessOutputTypes.STDERR && myTool.isShowConsoleOnStdErr())) {
                            ExecutionManager.getInstance(project).getContentManager().toFrontRunContent(executor, processHandler);
                        }
                    }
                });
            }
            return result;
        }
    };
    TextConsoleBuilder builder = TextConsoleBuilderFactory.getInstance().createBuilder(project);
    final FilterInfo[] outputFilters = myTool.getOutputFilters();
    for (FilterInfo outputFilter : outputFilters) {
        builder.addFilter(new RegexpFilter(project, outputFilter.getRegExp()));
    }
    commandLineState.setConsoleBuilder(builder);
    return commandLineState;
}
Also used : RegexpFilter(com.intellij.execution.filters.RegexpFilter) ExecutionResult(com.intellij.execution.ExecutionResult) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor) TextConsoleBuilder(com.intellij.execution.filters.TextConsoleBuilder) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) CommandLineState(com.intellij.execution.configurations.CommandLineState) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Key(com.intellij.openapi.util.Key)

Example 10 with ProgramRunner

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

the class CompoundRunConfiguration method getState.

@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
    try {
        checkConfiguration();
    } catch (RuntimeConfigurationException e) {
        throw new ExecutionException(e.getMessage());
    }
    return new RunProfileState() {

        @Nullable
        @Override
        public ExecutionResult execute(final Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
            ApplicationManager.getApplication().invokeLater(() -> {
                RunManagerImpl manager = RunManagerImpl.getInstanceImpl(getProject());
                for (RunConfiguration configuration : getSetToRun()) {
                    RunnerAndConfigurationSettings settings = new RunnerAndConfigurationSettingsImpl(manager, configuration, false);
                    ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.createOrNull(executor, settings);
                    if (builder != null) {
                        ExecutionManager.getInstance(getProject()).restartRunProfile(builder.activeTarget().dataContext(null).build());
                    }
                }
            });
            return null;
        }
    };
}
Also used : DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) RunnerAndConfigurationSettingsImpl(com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) NotNull(org.jetbrains.annotations.NotNull) RunManagerImpl(com.intellij.execution.impl.RunManagerImpl) Nullable(org.jetbrains.annotations.Nullable)

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