Search in sources :

Example 51 with ProcessAdapter

use of com.intellij.execution.process.ProcessAdapter 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 52 with ProcessAdapter

use of com.intellij.execution.process.ProcessAdapter 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 53 with ProcessAdapter

use of com.intellij.execution.process.ProcessAdapter 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 54 with ProcessAdapter

use of com.intellij.execution.process.ProcessAdapter 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 55 with ProcessAdapter

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

ProcessAdapter (com.intellij.execution.process.ProcessAdapter)62 ProcessEvent (com.intellij.execution.process.ProcessEvent)59 Key (com.intellij.openapi.util.Key)19 NotNull (org.jetbrains.annotations.NotNull)15 ProcessHandler (com.intellij.execution.process.ProcessHandler)12 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)10 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)10 ExecutionException (com.intellij.execution.ExecutionException)9 IOException (java.io.IOException)8 BaseOSProcessHandler (com.intellij.execution.process.BaseOSProcessHandler)7 Nullable (org.jetbrains.annotations.Nullable)7 Project (com.intellij.openapi.project.Project)5 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)4 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)4 File (java.io.File)4 ExecutionResult (com.intellij.execution.ExecutionResult)3 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)3 Disposable (com.intellij.openapi.Disposable)3 Semaphore (com.intellij.util.concurrency.Semaphore)3 RunProfile (com.intellij.execution.configurations.RunProfile)2