Search in sources :

Example 26 with ProgramRunner

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

the class AbstractRerunFailedTestsAction method execute.

void execute(@NotNull AnActionEvent e, @NotNull ExecutionEnvironment environment) {
    MyRunProfile profile = getRunProfile(environment);
    if (profile == null) {
        return;
    }
    final ExecutionEnvironmentBuilder environmentBuilder = new ExecutionEnvironmentBuilder(environment).runProfile(profile);
    final InputEvent event = e.getInputEvent();
    if (!(event instanceof MouseEvent) || !event.isShiftDown()) {
        performAction(environmentBuilder);
        return;
    }
    final LinkedHashMap<Executor, ProgramRunner> availableRunners = new LinkedHashMap<>();
    for (Executor ex : new Executor[] { DefaultRunExecutor.getRunExecutorInstance(), DefaultDebugExecutor.getDebugExecutorInstance() }) {
        final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(ex.getId(), profile);
        if (runner != null) {
            availableRunners.put(ex, runner);
        }
    }
    if (availableRunners.isEmpty()) {
        LOG.error(environment.getExecutor().getActionName() + " is not available now");
    } else if (availableRunners.size() == 1) {
        //noinspection ConstantConditions
        performAction(environmentBuilder.runner(availableRunners.get(environment.getExecutor())));
    } else {
        final JBList list = new JBList(availableRunners.keySet());
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        list.setSelectedValue(environment.getExecutor(), true);
        list.setCellRenderer(new DefaultListCellRenderer() {

            @NotNull
            @Override
            public Component getListCellRendererComponent(@NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (value instanceof Executor) {
                    setText(UIUtil.removeMnemonic(((Executor) value).getStartActionText()));
                    setIcon(((Executor) value).getIcon());
                }
                return component;
            }
        });
        //noinspection ConstantConditions
        JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Restart Failed Tests").setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
            final Object value = list.getSelectedValue();
            if (value instanceof Executor) {
                //noinspection ConstantConditions
                performAction(environmentBuilder.runner(availableRunners.get(value)).executor((Executor) value));
            }
        }).createPopup().showUnderneathOf(event.getComponent());
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) NotNull(org.jetbrains.annotations.NotNull) LinkedHashMap(java.util.LinkedHashMap) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) Executor(com.intellij.execution.Executor) JBList(com.intellij.ui.components.JBList) InputEvent(java.awt.event.InputEvent) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ProgramRunner(com.intellij.execution.runners.ProgramRunner)

Example 27 with ProgramRunner

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

the class MavenRunConfiguration method getState.

@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
    JavaCommandLineState state = new JavaCommandLineState(env) {

        @Override
        protected JavaParameters createJavaParameters() throws ExecutionException {
            return MavenRunConfiguration.this.createJavaParameters(env.getProject());
        }

        @NotNull
        @Override
        public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
            DefaultExecutionResult res = (DefaultExecutionResult) super.execute(executor, runner);
            if (executor.getId().equals(ToolWindowId.RUN) && MavenResumeAction.isApplicable(env.getProject(), getJavaParameters(), MavenRunConfiguration.this)) {
                MavenResumeAction resumeAction = new MavenResumeAction(res.getProcessHandler(), runner, env);
                res.setRestartActions(resumeAction);
            }
            return res;
        }

        @NotNull
        @Override
        protected OSProcessHandler startProcess() throws ExecutionException {
            OSProcessHandler result = super.startProcess();
            result.setShouldDestroyProcessRecursively(true);
            result.addProcessListener(new ProcessAdapter() {

                @Override
                public void processTerminated(ProcessEvent event) {
                    updateProjectsFolders();
                }
            });
            return result;
        }
    };
    state.setConsoleBuilder(MavenConsoleImpl.createConsoleBuilder(getProject()));
    return state;
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with ProgramRunner

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

the class MavenRunConfigurationType method runConfiguration.

public static void runConfiguration(Project project, @NotNull MavenRunnerParameters params, @Nullable MavenGeneralSettings settings, @Nullable MavenRunnerSettings runnerSettings, @Nullable ProgramRunner.Callback callback) {
    RunnerAndConfigurationSettings configSettings = createRunnerAndConfigurationSettings(settings, runnerSettings, params, project);
    ProgramRunner runner = DefaultJavaProgramRunner.getInstance();
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    try {
        runner.execute(new ExecutionEnvironment(executor, runner, configSettings, project), callback);
    } catch (ExecutionException e) {
        MavenUtil.showError(project, "Failed to execute Maven goal", e);
    }
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) DefaultJavaProgramRunner(com.intellij.execution.impl.DefaultJavaProgramRunner) ProgramRunner(com.intellij.execution.runners.ProgramRunner)

Example 29 with ProgramRunner

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

the class ExternalSystemUtil method createExecutionEnvironment.

@Nullable
public static ExecutionEnvironment createExecutionEnvironment(@NotNull Project project, @NotNull ProjectSystemId externalSystemId, @NotNull ExternalSystemTaskExecutionSettings taskSettings, @NotNull String executorId) {
    Executor executor = ExecutorRegistry.getInstance().getExecutorById(executorId);
    if (executor == null)
        return null;
    String runnerId = getRunnerId(executorId);
    if (runnerId == null)
        return null;
    ProgramRunner runner = RunnerRegistry.getInstance().findRunnerById(runnerId);
    if (runner == null)
        return null;
    RunnerAndConfigurationSettings settings = createExternalSystemRunnerAndConfigurationSettings(taskSettings, project, externalSystemId);
    if (settings == null)
        return null;
    return new ExecutionEnvironment(executor, runner, settings, project);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with ProgramRunner

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

the class SearchEverywhereAction method findExecutor.

@Nullable
public Executor findExecutor(@NotNull RunnerAndConfigurationSettings settings) {
    final Executor runExecutor = DefaultRunExecutor.getRunExecutorInstance();
    final Executor debugExecutor = ExecutorRegistry.getInstance().getExecutorById(ToolWindowId.DEBUG);
    Executor executor = ourShiftIsPressed.get() ? runExecutor : debugExecutor;
    RunConfiguration runConf = settings.getConfiguration();
    if (executor == null || runConf == null) {
        return null;
    }
    ProgramRunner runner = RunnerRegistry.getInstance().getRunner(executor.getId(), runConf);
    if (runner == null) {
        executor = runExecutor == executor ? debugExecutor : runExecutor;
    }
    return executor;
}
Also used : DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ProgramRunner(com.intellij.execution.runners.ProgramRunner) 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