Search in sources :

Example 11 with ProcessEvent

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

the class JavaTestFrameworkRunnableState method execute.

@NotNull
@Override
public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
    final RunnerSettings runnerSettings = getRunnerSettings();
    final SMTRunnerConsoleProperties testConsoleProperties = getConfiguration().createTestConsoleProperties(executor);
    testConsoleProperties.setIfUndefined(TestConsoleProperties.HIDE_PASSED_TESTS, false);
    final BaseTestsOutputConsoleView consoleView = SMTestRunnerConnectionUtil.createConsole(getFrameworkName(), testConsoleProperties);
    final SMTestRunnerResultsForm viewer = ((SMTRunnerConsoleView) consoleView).getResultsViewer();
    Disposer.register(getConfiguration().getProject(), consoleView);
    final OSProcessHandler handler = createHandler(executor);
    consoleView.attachToProcess(handler);
    final AbstractTestProxy root = viewer.getRoot();
    if (root instanceof TestProxyRoot) {
        ((TestProxyRoot) root).setHandler(handler);
    }
    handler.addProcessListener(new ProcessAdapter() {

        @Override
        public void startNotified(ProcessEvent event) {
            if (getConfiguration().isSaveOutputToFile()) {
                final File file = OutputFileUtil.getOutputFile(getConfiguration());
                root.setOutputFilePath(file != null ? file.getAbsolutePath() : null);
            }
        }

        @Override
        public void processTerminated(ProcessEvent event) {
            Runnable runnable = () -> {
                root.flushOutputFile();
                deleteTempFiles();
                clear();
            };
            UIUtil.invokeLaterIfNeeded(runnable);
            handler.removeProcessListener(this);
        }
    });
    AbstractRerunFailedTestsAction rerunFailedTestsAction = testConsoleProperties.createRerunFailedTestsAction(consoleView);
    LOG.assertTrue(rerunFailedTestsAction != null);
    rerunFailedTestsAction.setModelProvider(() -> viewer);
    final DefaultExecutionResult result = new DefaultExecutionResult(consoleView, handler);
    result.setRestartActions(rerunFailedTestsAction, new ToggleAutoTestAction() {

        @Override
        public boolean isDelayApplicable() {
            return false;
        }

        @Override
        public AbstractAutoTestManager getAutoTestManager(Project project) {
            return JavaAutoRunManager.getInstance(project);
        }
    });
    JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(getConfiguration(), handler, runnerSettings);
    return result;
}
Also used : SMTestRunnerResultsForm(com.intellij.execution.testframework.sm.runner.ui.SMTestRunnerResultsForm) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) AbstractAutoTestManager(com.intellij.execution.testframework.autotest.AbstractAutoTestManager) GenericDebuggerRunnerSettings(com.intellij.debugger.impl.GenericDebuggerRunnerSettings) ProcessEvent(com.intellij.execution.process.ProcessEvent) AbstractRerunFailedTestsAction(com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction) ToggleAutoTestAction(com.intellij.execution.testframework.autotest.ToggleAutoTestAction) BaseTestsOutputConsoleView(com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView) SMTRunnerConsoleProperties(com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties) SMTRunnerConsoleView(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView) Project(com.intellij.openapi.project.Project) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with ProcessEvent

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

the class BaseRemoteProcessHandler method startNotify.

@Override
public void startNotify() {
    notifyTextAvailable(myCommandLine + '\n', ProcessOutputTypes.SYSTEM);
    addProcessListener(new ProcessAdapter() {

        @Override
        public void startNotified(final ProcessEvent event) {
            try {
                final RemoteOutputReader stdoutReader = new RemoteOutputReader(myProcess.getInputStream(), getCharset(), myProcess, myCommandLine) {

                    @Override
                    protected void onTextAvailable(@NotNull String text) {
                        notifyTextAvailable(text, ProcessOutputTypes.STDOUT);
                    }

                    @NotNull
                    @Override
                    protected Future<?> executeOnPooledThread(@NotNull Runnable runnable) {
                        return BaseRemoteProcessHandler.executeOnPooledThread(runnable);
                    }
                };
                final RemoteOutputReader stderrReader = new RemoteOutputReader(myProcess.getErrorStream(), getCharset(), myProcess, myCommandLine) {

                    @Override
                    protected void onTextAvailable(@NotNull String text) {
                        notifyTextAvailable(text, ProcessOutputTypes.STDERR);
                    }

                    @NotNull
                    @Override
                    protected Future<?> executeOnPooledThread(@NotNull Runnable runnable) {
                        return BaseRemoteProcessHandler.executeOnPooledThread(runnable);
                    }
                };
                myWaitFor.setTerminationCallback(exitCode -> {
                    try {
                        try {
                            stderrReader.waitFor();
                            stdoutReader.waitFor();
                        } catch (InterruptedException ignore) {
                        }
                    } finally {
                        onOSProcessTerminated(exitCode);
                    }
                });
            } finally {
                removeProcessListener(this);
            }
        }
    });
    super.startNotify();
}
Also used : OutputStream(java.io.OutputStream) ProcessOutputTypes(com.intellij.execution.process.ProcessOutputTypes) StringUtil(com.intellij.openapi.util.text.StringUtil) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable) Future(java.util.concurrent.Future) Charset(java.nio.charset.Charset) ProcessWaitFor(com.intellij.execution.process.ProcessWaitFor) CommandLineUtil(com.intellij.execution.CommandLineUtil) ProcessEvent(com.intellij.execution.process.ProcessEvent) AppExecutorUtil(com.intellij.util.concurrency.AppExecutorUtil) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) TaskExecutor(com.intellij.execution.TaskExecutor) BaseOutputReader(com.intellij.util.io.BaseOutputReader) InputStream(java.io.InputStream) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) Future(java.util.concurrent.Future) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ProcessEvent

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

the class SMTestRunnerConnectionUtil method attachEventsProcessors.

private static void attachEventsProcessors(TestConsoleProperties consoleProperties, SMTestRunnerResultsForm resultsViewer, ProcessHandler processHandler, String testFrameworkName, @Nullable SMTestLocator locator, boolean idBasedTestTree, @Nullable TestProxyPrinterProvider printerProvider) {
    // build messages consumer
    final OutputToGeneralTestEventsConverter outputConsumer;
    if (consoleProperties instanceof SMCustomMessagesParsing) {
        outputConsumer = ((SMCustomMessagesParsing) consoleProperties).createTestEventsConverter(testFrameworkName, consoleProperties);
    } else {
        outputConsumer = new OutputToGeneralTestEventsConverter(testFrameworkName, consoleProperties);
    }
    // events processor
    final GeneralTestEventsProcessor eventsProcessor;
    if (idBasedTestTree) {
        eventsProcessor = new GeneralIdBasedToSMTRunnerEventsConvertor(consoleProperties.getProject(), resultsViewer.getTestsRootNode(), testFrameworkName);
    } else {
        eventsProcessor = new GeneralToSMTRunnerEventsConvertor(consoleProperties.getProject(), resultsViewer.getTestsRootNode(), testFrameworkName);
    }
    if (locator != null) {
        eventsProcessor.setLocator(locator);
    }
    if (printerProvider != null) {
        eventsProcessor.setPrinterProvider(printerProvider);
    }
    // UI actions
    final SMTRunnerUIActionsHandler uiActionsHandler = new SMTRunnerUIActionsHandler(consoleProperties);
    // subscribe to events
    // subscribes event processor on output consumer events
    outputConsumer.setProcessor(eventsProcessor);
    // subscribes result viewer on event processor
    eventsProcessor.addEventsListener(resultsViewer);
    // subscribes test runner's actions on results viewer events
    resultsViewer.addEventsListener(uiActionsHandler);
    processHandler.addProcessListener(new ProcessAdapter() {

        @Override
        public void processTerminated(final ProcessEvent event) {
            outputConsumer.flushBufferBeforeTerminating();
            eventsProcessor.onFinishTesting();
            Disposer.dispose(eventsProcessor);
            Disposer.dispose(outputConsumer);
        }

        @Override
        public void startNotified(final ProcessEvent event) {
            eventsProcessor.onStartTesting();
            outputConsumer.onStartTesting();
        }

        @Override
        public void onTextAvailable(final ProcessEvent event, final Key outputType) {
            outputConsumer.process(event.getText(), outputType);
        }
    });
}
Also used : SMTRunnerUIActionsHandler(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerUIActionsHandler) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) Key(com.intellij.openapi.util.Key)

Example 14 with ProcessEvent

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

the class DebuggerTestCase method createLocalSession.

protected DebuggerSession createLocalSession(final JavaParameters javaParameters) throws ExecutionException, InterruptedException {
    createBreakpoints(javaParameters.getMainClass());
    DebuggerSettings.getInstance().DEBUGGER_TRANSPORT = DebuggerSettings.SOCKET_TRANSPORT;
    GenericDebuggerRunnerSettings debuggerRunnerSettings = new GenericDebuggerRunnerSettings();
    debuggerRunnerSettings.LOCAL = true;
    final RemoteConnection debugParameters = DebuggerManagerImpl.createDebugParameters(javaParameters, debuggerRunnerSettings, false);
    ExecutionEnvironment environment = new ExecutionEnvironmentBuilder(myProject, DefaultDebugExecutor.getDebugExecutorInstance()).runnerSettings(debuggerRunnerSettings).runProfile(new MockConfiguration()).build();
    final JavaCommandLineState javaCommandLineState = new JavaCommandLineState(environment) {

        @Override
        protected JavaParameters createJavaParameters() {
            return javaParameters;
        }

        @Override
        protected GeneralCommandLine createCommandLine() throws ExecutionException {
            return getJavaParameters().toCommandLine();
        }
    };
    ApplicationManager.getApplication().invokeAndWait(() -> {
        try {
            myDebuggerSession = DebuggerManagerEx.getInstanceEx(myProject).attachVirtualMachine(new DefaultDebugEnvironment(new ExecutionEnvironmentBuilder(myProject, DefaultDebugExecutor.getDebugExecutorInstance()).runProfile(new MockConfiguration()).build(), javaCommandLineState, debugParameters, false));
            XDebuggerManager.getInstance(myProject).startSession(javaCommandLineState.getEnvironment(), new XDebugProcessStarter() {

                @Override
                @NotNull
                public XDebugProcess start(@NotNull XDebugSession session) {
                    return JavaDebugProcess.create(session, myDebuggerSession);
                }
            });
        } catch (ExecutionException e) {
            LOG.error(e);
        }
    });
    myDebugProcess = myDebuggerSession.getProcess();
    myDebugProcess.addProcessListener(new ProcessAdapter() {

        @Override
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            print(event.getText(), outputType);
        }
    });
    assertNotNull(myDebuggerSession);
    assertNotNull(myDebugProcess);
    return myDebuggerSession;
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) NotNull(org.jetbrains.annotations.NotNull) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 15 with ProcessEvent

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

the class FlexCommonUtils method getVersionOfAirSdkIncludedInFlexSdk.

@Nullable
public static String getVersionOfAirSdkIncludedInFlexSdk(final String flexSdkHomePath) {
    final File adtFile = new File(flexSdkHomePath + "/lib/adt.jar");
    if (!adtFile.isFile()) {
        return null;
    }
    String version = ourAdtJarPathAndTimestampToVersion.get(Pair.create(adtFile.getPath(), adtFile.lastModified()));
    if (version != null) {
        return version;
    }
    try {
        final Ref<String> versionRef = Ref.create();
        final String javaExecutable = FileUtil.toSystemDependentName((SystemProperties.getJavaHome() + "/bin/java" + (SystemInfo.isWindows ? ".exe" : "")));
        String[] cmdarray = { javaExecutable, "-jar", adtFile.getPath(), "-version" };
        final Process process = Runtime.getRuntime().exec(cmdarray);
        final BaseOSProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmdarray, " "), Charset.defaultCharset());
        handler.addProcessListener(new ProcessAdapter() {

            public void onTextAvailable(ProcessEvent event, Key outputType) {
                if (outputType != ProcessOutputTypes.SYSTEM) {
                    parseAirVersionFromAdtOutput(event.getText().trim(), versionRef);
                }
            }
        });
        handler.startNotify();
        handler.waitFor(3000);
        if (!handler.isProcessTerminated()) {
            handler.destroyProcess();
        }
        version = versionRef.get();
        ourAdtJarPathAndTimestampToVersion.put(Pair.create(adtFile.getPath(), adtFile.lastModified()), version);
        return version;
    } catch (IOException e) {
    /*ignore*/
    }
    return null;
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler) Nullable(org.jetbrains.annotations.Nullable)

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