Search in sources :

Example 41 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoApplicationRunningState method startProcess.

@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
    ProcessHandler processHandler = myCompilationFailed ? new GoNopProcessHandler() : super.startProcess();
    processHandler.addProcessListener(new ProcessAdapter() {

        @Override
        public void startNotified(ProcessEvent event) {
            if (myHistoryProcessHandler != null) {
                myHistoryProcessHandler.apply(processHandler);
            }
        }

        @Override
        public void processTerminated(ProcessEvent event) {
            super.processTerminated(event);
            if (StringUtil.isEmpty(myConfiguration.getOutputFilePath())) {
                File file = new File(myOutputFilePath);
                if (file.exists()) {
                    // noinspection ResultOfMethodCallIgnored
                    file.delete();
                }
            }
        }
    });
    return processHandler;
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessHandler(com.intellij.execution.process.ProcessHandler) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoBuildingRunner method prepare.

@NotNull
@Override
protected Promise<RunProfileStarter> prepare(@NotNull ExecutionEnvironment environment, @NotNull RunProfileState state) throws ExecutionException {
    File outputFile = getOutputFile(environment, (GoApplicationRunningState) state);
    FileDocumentManager.getInstance().saveAllDocuments();
    AsyncPromise<RunProfileStarter> buildingPromise = new AsyncPromise<>();
    GoHistoryProcessListener historyProcessListener = new GoHistoryProcessListener();
    ((GoApplicationRunningState) state).createCommonExecutor().withParameters("build").withParameterString(((GoApplicationRunningState) state).getGoBuildParams()).withParameters("-o", outputFile.getAbsolutePath()).withParameters(((GoApplicationRunningState) state).isDebug() ? new String[] { "-gcflags", "-N -l" } : ArrayUtil.EMPTY_STRING_ARRAY).withParameters(((GoApplicationRunningState) state).getTarget()).disablePty().withPresentableName("go build").withProcessListener(historyProcessListener).withProcessListener(new ProcessAdapter() {

        @Override
        public void processTerminated(ProcessEvent event) {
            super.processTerminated(event);
            boolean compilationFailed = event.getExitCode() != 0;
            if (((GoApplicationRunningState) state).isDebug()) {
                buildingPromise.setResult(new MyDebugStarter(outputFile.getAbsolutePath(), historyProcessListener, compilationFailed));
            } else {
                buildingPromise.setResult(new MyRunStarter(outputFile.getAbsolutePath(), historyProcessListener, compilationFailed));
            }
        }
    }).executeWithProgress(false);
    return buildingPromise;
}
Also used : RunProfileStarter(com.intellij.execution.RunProfileStarter) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) GoApplicationRunningState(com.goide.runconfig.application.GoApplicationRunningState) GoHistoryProcessListener(com.goide.util.GoHistoryProcessListener) AsyncPromise(org.jetbrains.concurrency.AsyncPromise) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 43 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project buck by facebook.

the class BuckToGeneralTestEventsConverter method onStartTesting.

@Override
public void onStartTesting() {
    mConnection = mProject.getMessageBus().connect();
    mConnection.subscribe(TestResultsAvailableConsumer.BUCK_TEST_RESULTS_AVAILABLE, this);
    mConnection.subscribe(TestRunCompleteConsumer.BUCK_TEST_RUN_COMPLETE, this);
    mConnection.subscribe(TestRunStartedConsumer.BUCK_TEST_RUN_STARTED, this);
    mConnection.subscribe(BuckBuildStartConsumer.BUCK_BUILD_START, this);
    mConnection.subscribe(BuckBuildEndConsumer.BUCK_BUILD_END, this);
    mConnection.subscribe(CompilerErrorConsumer.COMPILER_ERROR_CONSUMER, this);
    myHandler.addProcessListener(new ProcessAdapter() {

        @Override
        public void processTerminated(ProcessEvent event) {
            mConnection.disconnect();
        }
    });
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent)

Example 44 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project intellij-leiningen-plugin by derkork.

the class LeiningenRunConfigurationType method runConfiguration.

public static void runConfiguration(Project project, LeiningenRunnerParameters params, DataContext context) {
    RunnerAndConfigurationSettings configSettings = createRunnerAndConfigurationSettings(params, project);
    ProgramRunner runner = RunnerRegistry.getInstance().findRunnerById(DefaultRunExecutor.EXECUTOR_ID);
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, configSettings, project);
    try {
        runner.execute(env, new ProgramRunner.Callback() {

            public void processStarted(RunContentDescriptor runContentDescriptor) {
                final ProcessHandler runContentDescriptorProcessHandler = runContentDescriptor.getProcessHandler();
                if (runContentDescriptorProcessHandler != null) {
                    runContentDescriptorProcessHandler.addProcessListener(new ProcessAdapter() {

                        @Override
                        public void processTerminated(ProcessEvent event) {
                            LocalFileSystem.getInstance().refreshWithoutFileWatcher(true);
                        }
                    });
                }
            }
        });
    } catch (ExecutionException e) {
    }
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner)

Example 45 with ProcessEvent

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

the class EmulatorProcessHandler method startNotify.

@Override
public void startNotify() {
    // Wait for both the stdout and stderr reader threads to finish and then indicate that the process has terminated
    addProcessListener(new ProcessAdapter() {

        @Override
        public void startNotified(final ProcessEvent event) {
            try {
                String presentableName = CommandLineUtil.extractPresentableName(myCommandLine.getCommandLineString());
                final BaseDataReader stdoutReader = new EmulatorOutputReader(myProcess.getInputStream(), ProcessOutputTypes.STDOUT, presentableName);
                final BaseDataReader stderrReader = new EmulatorOutputReader(myProcess.getErrorStream(), ProcessOutputTypes.STDERR, presentableName);
                executeTask(() -> {
                    try {
                        stderrReader.waitFor();
                        stdoutReader.waitFor();
                    } catch (InterruptedException ignore) {
                    } finally {
                        notifyProcessTerminated(0);
                    }
                });
            } finally {
                removeProcessListener(this);
            }
        }
    });
    super.startNotify();
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) BaseDataReader(com.intellij.util.io.BaseDataReader) ProcessEvent(com.intellij.execution.process.ProcessEvent)

Aggregations

ProcessEvent (com.intellij.execution.process.ProcessEvent)89 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)81 Key (com.intellij.openapi.util.Key)33 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)24 NotNull (org.jetbrains.annotations.NotNull)24 ExecutionException (com.intellij.execution.ExecutionException)21 ProcessHandler (com.intellij.execution.process.ProcessHandler)18 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)15 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