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