Search in sources :

Example 6 with OSProcessHandler

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

the class MavenExternalExecutor method execute.

public boolean execute(final ProgressIndicator indicator) {
    displayProgress();
    try {
        if (myParameterCreationError != null) {
            throw myParameterCreationError;
        }
        myProcessHandler = new OSProcessHandler(myJavaParameters.toCommandLine()) {

            @Override
            public void notifyTextAvailable(String text, Key outputType) {
                // todo move this logic to ConsoleAdapter class
                if (!myConsole.isSuppressed(text)) {
                    super.notifyTextAvailable(text, outputType);
                }
                updateProgress(indicator, text);
            }
        };
        myConsole.attachToProcess(myProcessHandler);
    } catch (ExecutionException e) {
        myConsole.systemMessage(MavenServerConsole.LEVEL_FATAL, RunnerBundle.message("external.startup.failed", e.getMessage()), null);
        return false;
    }
    start();
    readProcessOutput();
    stop();
    return printExitSummary();
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 7 with OSProcessHandler

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

the class JUnit4IntegrationTest method ignoredTestMethod.

@Test
public void ignoredTestMethod() throws Throwable {
    EdtTestUtil.runInEdtAndWait(() -> {
        PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
        assertNotNull(psiClass);
        PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, false)[0];
        JUnitConfiguration configuration = createConfiguration(testMethod);
        Executor executor = DefaultRunExecutor.getRunExecutorInstance();
        RunnerAndConfigurationSettingsImpl settings = new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(getProject()), configuration, false);
        ExecutionEnvironment environment = new ExecutionEnvironment(executor, ProgramRunnerUtil.getRunner(DefaultRunExecutor.EXECUTOR_ID, settings), settings, getProject());
        TestObject state = configuration.getState(executor, environment);
        JavaParameters parameters = state.getJavaParameters();
        parameters.setUseDynamicClasspath(getProject());
        GeneralCommandLine commandLine = parameters.toCommandLine();
        StringBuffer buf = new StringBuffer();
        StringBuffer err = new StringBuffer();
        OSProcessHandler process = new OSProcessHandler(commandLine);
        process.addProcessListener(new ProcessAdapter() {

            @Override
            public void onTextAvailable(ProcessEvent event, Key outputType) {
                String text = event.getText();
                try {
                    if (outputType == ProcessOutputTypes.STDOUT && !text.isEmpty() && ServiceMessage.parse(text.trim()) == null) {
                        buf.append(text);
                    }
                    if (outputType == ProcessOutputTypes.STDERR) {
                        err.append(text);
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        });
        process.startNotify();
        process.waitFor();
        process.destroyProcess();
        String testOutput = buf.toString();
        assertEmpty(err.toString());
        switch(myJUnitVersion) {
            //shouldn't work for old versions
            case "4.4":
            //shouldn't work for old versions
            case "4.5":
                break;
            default:
                assertTrue(testOutput, testOutput.contains("Test1"));
        }
    });
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) PsiMethod(com.intellij.psi.PsiMethod) ProcessEvent(com.intellij.execution.process.ProcessEvent) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) PsiClass(com.intellij.psi.PsiClass) TestObject(com.intellij.execution.junit.TestObject) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RunnerAndConfigurationSettingsImpl(com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl) JavaParameters(com.intellij.execution.configurations.JavaParameters) ParseException(java.text.ParseException) Key(com.intellij.openapi.util.Key) Test(org.junit.Test)

Example 8 with OSProcessHandler

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

the class TestObject method createHandler.

@NotNull
protected OSProcessHandler createHandler(Executor executor) throws ExecutionException {
    appendForkInfo(executor);
    final String repeatMode = getConfiguration().getRepeatMode();
    if (!RepeatCount.ONCE.equals(repeatMode)) {
        final int repeatCount = getConfiguration().getRepeatCount();
        final String countString = RepeatCount.N.equals(repeatMode) && repeatCount > 0 ? RepeatCount.getCountString(repeatCount) : repeatMode;
        getJavaParameters().getProgramParametersList().add(countString);
    }
    final OSProcessHandler processHandler = new KillableColoredProcessHandler(createCommandLine());
    ProcessTerminatedListener.attach(processHandler);
    final SearchForTestsTask searchForTestsTask = createSearchingForTestsTask();
    if (searchForTestsTask != null) {
        searchForTestsTask.attachTaskToProcess(processHandler);
    }
    return processHandler;
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler) SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with OSProcessHandler

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

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

the class RemoteExternalSystemCommunicationManager method createRunProfileState.

private RunProfileState createRunProfileState(final String configuration) {
    return new CommandLineState(null) {

        private SimpleJavaParameters createJavaParameters() throws ExecutionException {
            final SimpleJavaParameters params = new SimpleJavaParameters();
            params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()));
            File myWorkingDirectory = new File(configuration);
            params.setWorkingDirectory(myWorkingDirectory.isDirectory() ? myWorkingDirectory.getPath() : PathManager.getBinPath());
            final List<String> classPath = ContainerUtilRt.newArrayList();
            // IDE jars.
            classPath.addAll(PathManager.getUtilClassPath());
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ProjectBundle.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(PlaceHolder.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(DebuggerView.class));
            ExternalSystemApiUtil.addBundle(params.getClassPath(), "messages.ProjectBundle", ProjectBundle.class);
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(PsiBundle.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(Alarm.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(DependencyScope.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ExtensionPointName.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(StorageUtilKt.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ExternalSystemTaskNotificationListener.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(StdModuleTypes.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(JavaModuleType.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ModuleType.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(EmptyModuleType.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(LanguageLevel.class));
            // add Kotlin runtime
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(Unit.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(KotlinReflectionInternalError.class));
            // External system module jars
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(getClass()));
            // external-system-rt.jar
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ExternalSystemException.class));
            ExternalSystemApiUtil.addBundle(params.getClassPath(), "messages.CommonBundle", CommonBundle.class);
            params.getClassPath().addAll(classPath);
            params.setMainClass(MAIN_CLASS_NAME);
            params.getVMParametersList().addParametersString("-Djava.awt.headless=true");
            // It may take a while for external system api to resolve external dependencies. Default RMI timeout
            // is 15 seconds (http://download.oracle.com/javase/6/docs/technotes/guides/rmi/sunrmiproperties.html#connectionTimeout),
            // we don't want to get EOFException because of that.
            params.getVMParametersList().addParametersString("-Dsun.rmi.transport.connectionTimeout=" + String.valueOf(TimeUnit.HOURS.toMillis(1)));
            final String debugPort = System.getProperty(ExternalSystemConstants.EXTERNAL_SYSTEM_REMOTE_COMMUNICATION_MANAGER_DEBUG_PORT);
            if (debugPort != null) {
                params.getVMParametersList().addParametersString("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + debugPort);
            }
            ProjectSystemId externalSystemId = myTargetExternalSystemId.get();
            if (externalSystemId != null) {
                ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
                if (manager != null) {
                    params.getClassPath().add(PathUtil.getJarPathForClass(manager.getProjectResolverClass()));
                    params.getProgramParametersList().add(manager.getProjectResolverClass().getName());
                    params.getProgramParametersList().add(manager.getTaskManagerClass().getName());
                    manager.enhanceRemoteProcessing(params);
                }
            }
            return params;
        }

        @Override
        @NotNull
        public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
            ProcessHandler processHandler = startProcess();
            return new DefaultExecutionResult(processHandler);
        }

        @Override
        @NotNull
        protected OSProcessHandler startProcess() throws ExecutionException {
            SimpleJavaParameters params = createJavaParameters();
            GeneralCommandLine commandLine = params.toCommandLine();
            OSProcessHandler processHandler = new OSProcessHandler(commandLine);
            ProcessTerminatedListener.attach(processHandler);
            return processHandler;
        }
    };
}
Also used : KotlinReflectionInternalError(kotlin.reflect.KotlinReflectionInternalError) DependencyScope(com.intellij.openapi.roots.DependencyScope) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) PlaceHolder(com.intellij.ui.PlaceHolder) SimpleJavaParameters(com.intellij.execution.configurations.SimpleJavaParameters) Unit(kotlin.Unit) TimeUnit(java.util.concurrent.TimeUnit) NotNull(org.jetbrains.annotations.NotNull) ProjectBundle(com.intellij.openapi.project.ProjectBundle) StorageUtilKt(com.intellij.configurationStore.StorageUtilKt) EmptyModuleType(com.intellij.openapi.module.EmptyModuleType) ModuleType(com.intellij.openapi.module.ModuleType) JavaModuleType(com.intellij.openapi.module.JavaModuleType) Executor(com.intellij.execution.Executor) ExtensionPointName(com.intellij.openapi.extensions.ExtensionPointName) LanguageLevel(com.intellij.pom.java.LanguageLevel) DebuggerView(com.intellij.debugger.ui.DebuggerView) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) CommandLineState(com.intellij.execution.configurations.CommandLineState) ProgramRunner(com.intellij.execution.runners.ProgramRunner) EmptyModuleType(com.intellij.openapi.module.EmptyModuleType) JavaModuleType(com.intellij.openapi.module.JavaModuleType) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) ExternalSystemTaskNotificationListener(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener) PsiBundle(com.intellij.psi.PsiBundle) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) Alarm(com.intellij.util.Alarm) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) SimpleJavaSdkType(com.intellij.openapi.projectRoots.SimpleJavaSdkType) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) File(java.io.File)

Aggregations

OSProcessHandler (com.intellij.execution.process.OSProcessHandler)55 ExecutionException (com.intellij.execution.ExecutionException)25 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)24 ProcessEvent (com.intellij.execution.process.ProcessEvent)24 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)23 NotNull (org.jetbrains.annotations.NotNull)18 Key (com.intellij.openapi.util.Key)14 ProcessHandler (com.intellij.execution.process.ProcessHandler)6 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 File (java.io.File)6 Module (com.intellij.openapi.module.Module)5 Sdk (com.intellij.openapi.projectRoots.Sdk)5 IOException (java.io.IOException)5 ProgramRunner (com.intellij.execution.runners.ProgramRunner)4 Nullable (org.jetbrains.annotations.Nullable)4 Executor (com.intellij.execution.Executor)3 RunContentExecutor (com.intellij.execution.RunContentExecutor)3 KillableColoredProcessHandler (com.intellij.execution.process.KillableColoredProcessHandler)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3