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();
}
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"));
}
});
}
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;
}
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;
}
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;
}
};
}
Aggregations