Search in sources :

Example 1 with ProcessAdapter

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

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

use of com.intellij.execution.process.ProcessAdapter in project intellij-elixir by KronicDeth.

the class MixBuilder method runMix.

private static void runMix(@NotNull String elixirPath, @NotNull String mixPath, @Nullable String contentRootPath, boolean addDebugInfo, @NotNull CompileContext context) throws ProjectBuildException {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.withWorkDirectory(contentRootPath);
    commandLine.setExePath(elixirPath);
    commandLine.addParameter(mixPath);
    commandLine.addParameter("compile");
    if (!addDebugInfo) {
        commandLine.addParameter("--no-debug-info");
    }
    Process process;
    try {
        process = commandLine.createProcess();
    } catch (ExecutionException e) {
        throw new ProjectBuildException("Failed to run mix.", e);
    }
    BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commandLine.getCommandLineString(), Charset.defaultCharset());
    ProcessAdapter adapter = new ElixirCompilerProcessAdapter(context, NAME, commandLine.getWorkDirectory().getPath());
    handler.addProcessListener(adapter);
    handler.startNotify();
    handler.waitFor();
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler)

Example 4 with ProcessAdapter

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

the class PydevConsoleRunnerImpl method connect.

private void connect(final String[] statements2execute) {
    if (handshake()) {
        ApplicationManager.getApplication().invokeLater(() -> {
            // Propagate console communication to language console
            final PythonConsoleView consoleView = myConsoleView;
            consoleView.setConsoleCommunication(myPydevConsoleCommunication);
            consoleView.setSdk(mySdk);
            consoleView.setExecutionHandler(myConsoleExecuteActionHandler);
            myProcessHandler.addProcessListener(new ProcessAdapter() {

                @Override
                public void onTextAvailable(ProcessEvent event, Key outputType) {
                    consoleView.print(event.getText(), outputType);
                }
            });
            if (myEnableAfterConnection) {
                enableConsoleExecuteAction();
            }
            for (String statement : statements2execute) {
                consoleView.executeStatement(statement + "\n", ProcessOutputTypes.SYSTEM);
            }
            fireConsoleInitializedEvent(consoleView);
            consoleView.initialized();
        });
    } else {
        myConsoleView.print("Couldn't connect to console process.", ProcessOutputTypes.STDERR);
        myProcessHandler.destroyProcess();
        myConsoleView.setEditable(false);
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) Key(com.intellij.openapi.util.Key)

Example 5 with ProcessAdapter

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

the class PydevConsoleRunnerImpl method initAndRun.

private void initAndRun() throws ExecutionException {
    // Create Server process
    final Process process = createProcess();
    UIUtil.invokeLaterIfNeeded(() -> {
        // Init console view
        myConsoleView = createConsoleView();
        if (myConsoleView != null) {
            ((JComponent) myConsoleView).setBorder(new SideBorder(JBColor.border(), SideBorder.LEFT));
        }
        myProcessHandler = createProcessHandler(process);
        myConsoleExecuteActionHandler = createExecuteActionHandler();
        ProcessTerminatedListener.attach(myProcessHandler);
        PythonConsoleView consoleView = myConsoleView;
        myProcessHandler.addProcessListener(new ProcessAdapter() {

            @Override
            public void processTerminated(ProcessEvent event) {
                consoleView.setEditable(false);
            }
        });
        // Attach to process
        myConsoleView.attachToProcess(myProcessHandler);
        createContentDescriptorAndActions();
        // Run
        myProcessHandler.startNotify();
    });
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) RemoteProcess(com.intellij.remote.RemoteProcess) XDebugProcess(com.intellij.xdebugger.XDebugProcess) SideBorder(com.intellij.ui.SideBorder)

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