Search in sources :

Example 61 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project intellij-community by JetBrains.

the class GroovyScriptRunConfiguration method getState.

@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    final VirtualFile scriptFile = ScriptFileUtil.findScriptFileByPath(getScriptPath());
    if (scriptFile == null)
        return null;
    final GroovyScriptRunner scriptRunner = getScriptRunner();
    if (scriptRunner == null)
        return null;
    return new JavaCommandLineState(environment) {

        @NotNull
        @Override
        protected OSProcessHandler startProcess() throws ExecutionException {
            final OSProcessHandler handler = super.startProcess();
            handler.setShouldDestroyProcessRecursively(true);
            if (scriptRunner.shouldRefreshAfterFinish()) {
                handler.addProcessListener(new ProcessAdapter() {

                    @Override
                    public void processTerminated(ProcessEvent event) {
                        if (!ApplicationManager.getApplication().isDisposed()) {
                            VirtualFileManager.getInstance().asyncRefresh(null);
                        }
                    }
                });
            }
            return handler;
        }

        @Override
        protected JavaParameters createJavaParameters() throws ExecutionException {
            final Module module = getModule();
            final boolean tests = ProjectRootManager.getInstance(getProject()).getFileIndex().isInTestSourceContent(scriptFile);
            String jrePath = isAlternativeJrePathEnabled() ? getAlternativeJrePath() : null;
            JavaParameters params = new JavaParameters();
            params.setUseClasspathJar(true);
            params.setDefaultCharset(getProject());
            params.setJdk(module == null ? JavaParametersUtil.createProjectJdk(getProject(), jrePath) : JavaParametersUtil.createModuleJdk(module, !tests, jrePath));
            configureConfiguration(params, new CommonProgramRunConfigurationParametersDelegate(GroovyScriptRunConfiguration.this) {

                @Nullable
                @Override
                public String getProgramParameters() {
                    return null;
                }
            });
            scriptRunner.configureCommandLine(params, module, tests, scriptFile, GroovyScriptRunConfiguration.this);
            return params;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CommonProgramRunConfigurationParametersDelegate(org.jetbrains.plugins.groovy.runner.util.CommonProgramRunConfigurationParametersDelegate) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 62 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project intellij-community by JetBrains.

the class AbstractAutoTestManager method scheduleRestartOnTermination.

private void scheduleRestartOnTermination(@NotNull final RunContentDescriptor descriptor, @NotNull final ProcessHandler processHandler, final int modificationStamp, @NotNull final AutoTestWatcher watcher) {
    ProcessListener restarterListener = ON_TERMINATION_RESTARTER_KEY.get(processHandler);
    if (restarterListener != null) {
        clearRestarterListener(processHandler);
    }
    restarterListener = new ProcessAdapter() {

        @Override
        public void processTerminated(ProcessEvent event) {
            clearRestarterListener(processHandler);
            ApplicationManager.getApplication().invokeLater(() -> {
                if (isAutoTestEnabledForDescriptor(descriptor) && watcher.isUpToDate(modificationStamp)) {
                    restart(descriptor);
                }
            }, ModalityState.any());
        }
    };
    ON_TERMINATION_RESTARTER_KEY.set(processHandler, restarterListener);
    processHandler.addProcessListener(restarterListener);
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessListener(com.intellij.execution.process.ProcessListener)

Example 63 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project intellij-community by JetBrains.

the class MavenExecutionTest method execute.

private void execute(final MavenRunnerParameters params) {
    final Semaphore sema = new Semaphore();
    sema.down();
    UIUtil.invokeLaterIfNeeded(() -> MavenRunConfigurationType.runConfiguration(myProject, params, getMavenGeneralSettings(), new MavenRunnerSettings(), new ProgramRunner.Callback() {

        @Override
        public void processStarted(final RunContentDescriptor descriptor) {
            descriptor.getProcessHandler().addProcessListener(new ProcessAdapter() {

                @Override
                public void processTerminated(ProcessEvent event) {
                    sema.up();
                    UIUtil.invokeLaterIfNeeded(() -> Disposer.dispose(descriptor));
                }
            });
        }
    }));
    sema.waitFor();
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) Semaphore(com.intellij.util.concurrency.Semaphore)

Example 64 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project intellij-community by JetBrains.

the class SnapShooterConfigurationExtension method attachToProcess.

@Override
public void attachToProcess(@NotNull final RunConfigurationBase configuration, @NotNull final ProcessHandler handler, RunnerSettings runnerSettings) {
    SnapShooterConfigurationSettings settings = configuration.getUserData(SnapShooterConfigurationSettings.SNAP_SHOOTER_KEY);
    if (settings != null) {
        final Runnable runnable = settings.getNotifyRunnable();
        if (runnable != null) {
            settings.setNotifyRunnable(null);
            handler.addProcessListener(new ProcessAdapter() {

                @Override
                public void startNotified(final ProcessEvent event) {
                    runnable.run();
                }
            });
        }
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent)

Example 65 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent 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)

Aggregations

ProcessEvent (com.intellij.execution.process.ProcessEvent)90 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)82 Key (com.intellij.openapi.util.Key)34 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)25 NotNull (org.jetbrains.annotations.NotNull)24 ExecutionException (com.intellij.execution.ExecutionException)22 ProcessHandler (com.intellij.execution.process.ProcessHandler)18 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)16 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)12 IOException (java.io.IOException)12 Nullable (org.jetbrains.annotations.Nullable)12 Project (com.intellij.openapi.project.Project)9 File (java.io.File)9 ProcessListener (com.intellij.execution.process.ProcessListener)8 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)7 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)5 ProgramRunner (com.intellij.execution.runners.ProgramRunner)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)4 Disposable (com.intellij.openapi.Disposable)4