Search in sources :

Example 1 with ProgramRunner

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

the class MavenRunConfigurationMenu method update.

@Override
public void update(AnActionEvent e) {
    for (AnAction action : getChildActionsOrStubs()) {
        if (action instanceof ExecuteMavenRunConfigurationAction) {
            remove(action);
        }
    }
    final Project project = e.getProject();
    final RunnerAndConfigurationSettings settings = MavenDataKeys.RUN_CONFIGURATION.getData(e.getDataContext());
    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 ExecuteMavenRunConfigurationAction(executors[i], runner != null, project, settings);
        addAction(action, Constraints.FIRST);
    }
    super.update(e);
}
Also used : Project(com.intellij.openapi.project.Project) ProgramRunner(com.intellij.execution.runners.ProgramRunner) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 2 with ProgramRunner

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

the class PyAbstractTestProcessRunner method rerunFailedTests.

/**
   * Rerun current tests. Make sure there is at least one failed test.
   * <strong>Run in AWT thread only!</strong>
   */
public void rerunFailedTests() {
    assert getFailedTestsCount() > 0 : "No failed tests. What you want to rerun?";
    assert myLastProcessDescriptor != null : "No last run descriptor. First run tests at least one time";
    final List<ProgramRunner<?>> run = getAvailableRunnersForLastRun();
    Assert.assertFalse("No runners to rerun", run.isEmpty());
    final ProgramRunner<?> runner = run.get(0);
    final ExecutionEnvironment restartAction = RerunFailedActionsTestTools.findRestartAction(myLastProcessDescriptor);
    Assert.assertNotNull("No restart action", restartAction);
    final Ref<ProcessHandler> handlerRef = new Ref<>();
    try {
        runner.execute(restartAction, descriptor -> handlerRef.set(descriptor.getProcessHandler()));
    } catch (final ExecutionException e) {
        throw new AssertionError("ExecutionException can't be thrown in tests. Probably, API changed. Got: " + e);
    }
    final ProcessHandler handler = handlerRef.get();
    if (handler == null) {
        return;
    }
    handler.waitFor();
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Ref(com.intellij.openapi.util.Ref) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExecutionException(com.intellij.execution.ExecutionException)

Example 3 with ProgramRunner

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

the class ConfigurationBasedProcessRunner method runProcess.

@Override
final void runProcess(@NotNull final String sdkPath, @NotNull final Project project, @NotNull final ProcessListener processListener, @NotNull final String tempWorkingPath) throws ExecutionException {
    ensureConsoleOk(myConsole);
    // Do not create new environment from factory, if child provided environment to rerun
    final ExecutionEnvironment executionEnvironment = // TODO: RENAME
    (myRerunExecutionEnvironment != null ? myRerunExecutionEnvironment : createExecutionEnvironment(sdkPath, project, tempWorkingPath));
    // Engine to be run after process end to post process console
    final ProcessListener consolePostprocessor = new ProcessAdapter() {

        @Override
        public void processTerminated(final ProcessEvent event) {
            super.processTerminated(event);
            ApplicationManager.getApplication().invokeAndWait(() -> prepareConsoleAfterProcessEnd(), ModalityState.NON_MODAL);
        }
    };
    /// Find all available runners to report them to the test
    myAvailableRunnersForLastRun.clear();
    for (final ProgramRunner<?> runner : ProgramRunner.PROGRAM_RUNNER_EP.getExtensions()) {
        for (final Executor executor : Executor.EXECUTOR_EXTENSION_NAME.getExtensions()) {
            if (runner.canRun(executor.getId(), executionEnvironment.getRunProfile())) {
                myAvailableRunnersForLastRun.add(runner);
            }
        }
    }
    executionEnvironment.getRunner().execute(executionEnvironment, new ProgramRunner.Callback() {

        @Override
        public void processStarted(final RunContentDescriptor descriptor) {
            final ProcessHandler handler = descriptor.getProcessHandler();
            assert handler != null : "No process handler";
            handler.addProcessListener(consolePostprocessor);
            handler.addProcessListener(processListener);
            myConsole = null;
            fetchConsoleAndSetToField(descriptor);
            assert myConsole != null : "fetchConsoleAndSetToField did not set console!";
            // Console does not work with out of this method
            final JComponent component = myConsole.getComponent();
            assert component != null;
            myLastProcessDescriptor = descriptor;
        }
    });
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessListener(com.intellij.execution.process.ProcessListener) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner)

Example 4 with ProgramRunner

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

the class MavenServerManager method createRunProfileState.

private RunProfileState createRunProfileState() {
    return new CommandLineState(null) {

        private SimpleJavaParameters createJavaParameters() {
            final SimpleJavaParameters params = new SimpleJavaParameters();
            final Sdk jdk = getJdk();
            params.setJdk(jdk);
            params.setWorkingDirectory(PathManager.getBinPath());
            params.setMainClass(MAIN_CLASS);
            Map<String, String> defs = new THashMap<>();
            defs.putAll(MavenUtil.getPropertiesFromMavenOpts());
            // pass ssl-related options
            for (Map.Entry<Object, Object> each : System.getProperties().entrySet()) {
                Object key = each.getKey();
                Object value = each.getValue();
                if (key instanceof String && value instanceof String && ((String) key).startsWith("javax.net.ssl")) {
                    defs.put((String) key, (String) value);
                }
            }
            if (SystemInfo.isMac) {
                String arch = System.getProperty("sun.arch.data.model");
                if (arch != null) {
                    params.getVMParametersList().addParametersString("-d" + arch);
                }
            }
            defs.put("java.awt.headless", "true");
            for (Map.Entry<String, String> each : defs.entrySet()) {
                params.getVMParametersList().defineProperty(each.getKey(), each.getValue());
            }
            params.getVMParametersList().addProperty("idea.version=", MavenUtil.getIdeaVersionToPassToMavenProcess());
            boolean xmxSet = false;
            boolean forceMaven2 = false;
            if (myState.vmOptions != null) {
                ParametersList mavenOptsList = new ParametersList();
                mavenOptsList.addParametersString(myState.vmOptions);
                for (String param : mavenOptsList.getParameters()) {
                    if (param.startsWith("-Xmx")) {
                        xmxSet = true;
                    }
                    if (param.equals(FORCE_MAVEN2_OPTION)) {
                        forceMaven2 = true;
                    }
                    params.getVMParametersList().add(param);
                }
            }
            final File mavenHome;
            final String mavenVersion;
            final File currentMavenHomeFile = forceMaven2 ? BundledMavenPathHolder.myBundledMaven2Home : getCurrentMavenHomeFile();
            if (currentMavenHomeFile == null) {
                mavenHome = BundledMavenPathHolder.myBundledMaven3Home;
                mavenVersion = getMavenVersion(mavenHome);
                Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
                final Project project = openProjects.length == 1 ? openProjects[0] : null;
                if (project != null) {
                    new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "", RunnerBundle.message("external.maven.home.invalid.substitution.warning.with.fix", myState.mavenHome, mavenVersion), NotificationType.WARNING, new NotificationListener() {

                        @Override
                        public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                            ShowSettingsUtil.getInstance().showSettingsDialog(project, MavenSettings.DISPLAY_NAME);
                        }
                    }).notify(null);
                } else {
                    new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "", RunnerBundle.message("external.maven.home.invalid.substitution.warning", myState.mavenHome, mavenVersion), NotificationType.WARNING).notify(null);
                }
            } else {
                mavenHome = currentMavenHomeFile;
                mavenVersion = getMavenVersion(mavenHome);
            }
            assert mavenVersion != null;
            params.getVMParametersList().addProperty(MavenServerEmbedder.MAVEN_EMBEDDER_VERSION, mavenVersion);
            String sdkConfigLocation = "Settings | Build, Execution, Deployment | Build Tools | Maven | Importing | JDK for Importer";
            verifyMavenSdkRequirements(jdk, mavenVersion, sdkConfigLocation);
            final List<String> classPath = new ArrayList<>();
            classPath.add(PathUtil.getJarPathForClass(org.apache.log4j.Logger.class));
            if (StringUtil.compareVersionNumbers(mavenVersion, "3.1") < 0) {
                classPath.add(PathUtil.getJarPathForClass(Logger.class));
                classPath.add(PathUtil.getJarPathForClass(Log4jLoggerFactory.class));
            }
            classPath.addAll(PathManager.getUtilClassPath());
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(Query.class));
            params.getClassPath().add(PathManager.getResourceRoot(getClass(), "/messages/CommonBundle.properties"));
            params.getClassPath().addAll(classPath);
            params.getClassPath().addAllFiles(collectClassPathAndLibsFolder(mavenVersion, mavenHome));
            String embedderXmx = System.getProperty("idea.maven.embedder.xmx");
            if (embedderXmx != null) {
                params.getVMParametersList().add("-Xmx" + embedderXmx);
            } else {
                if (!xmxSet) {
                    params.getVMParametersList().add("-Xmx768m");
                }
            }
            String mavenEmbedderDebugPort = System.getProperty("idea.maven.embedder.debug.port");
            if (mavenEmbedderDebugPort != null) {
                params.getVMParametersList().addParametersString("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=" + mavenEmbedderDebugPort);
            }
            String mavenEmbedderParameters = System.getProperty("idea.maven.embedder.parameters");
            if (mavenEmbedderParameters != null) {
                params.getProgramParametersList().addParametersString(mavenEmbedderParameters);
            }
            String mavenEmbedderCliOptions = System.getProperty(MavenServerEmbedder.MAVEN_EMBEDDER_CLI_ADDITIONAL_ARGS);
            if (mavenEmbedderCliOptions != null) {
                params.getVMParametersList().addProperty(MavenServerEmbedder.MAVEN_EMBEDDER_CLI_ADDITIONAL_ARGS, mavenEmbedderCliOptions);
            }
            return params;
        }

        @NotNull
        @Override
        public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
            ProcessHandler processHandler = startProcess();
            return new DefaultExecutionResult(processHandler);
        }

        @Override
        @NotNull
        protected OSProcessHandler startProcess() throws ExecutionException {
            SimpleJavaParameters params = createJavaParameters();
            GeneralCommandLine commandLine = params.toCommandLine();
            OSProcessHandler processHandler = new OSProcessHandler(commandLine);
            processHandler.setShouldDestroyProcessRecursively(false);
            return processHandler;
        }
    };
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) Query(org.apache.lucene.search.Query) Logger(org.slf4j.Logger) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) Executor(com.intellij.execution.Executor) THashMap(gnu.trove.THashMap) Log4jLoggerFactory(org.slf4j.impl.Log4jLoggerFactory) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Project(com.intellij.openapi.project.Project) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) THashMap(gnu.trove.THashMap) File(java.io.File) NotificationListener(com.intellij.notification.NotificationListener)

Example 5 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)

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