use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class DefaultJavaProgramRunner method doExecute.
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment env) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
ExecutionResult executionResult;
boolean shouldAddDefaultActions = true;
if (state instanceof JavaCommandLine) {
final JavaParameters parameters = ((JavaCommandLine) state).getJavaParameters();
patch(parameters, env.getRunnerSettings(), env.getRunProfile(), true);
ProcessProxy proxy = ProcessProxyFactory.getInstance().createCommandLineProxy((JavaCommandLine) state);
executionResult = state.execute(env.getExecutor(), this);
if (proxy != null) {
ProcessHandler handler = executionResult != null ? executionResult.getProcessHandler() : null;
if (handler != null) {
proxy.attach(handler);
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
proxy.destroy();
}
});
} else {
proxy.destroy();
}
}
if (state instanceof JavaCommandLineState && !((JavaCommandLineState) state).shouldAddJavaProgramRunnerActions()) {
shouldAddDefaultActions = false;
}
} else {
executionResult = state.execute(env.getExecutor(), this);
}
if (executionResult == null) {
return null;
}
onProcessStarted(env.getRunnerSettings(), executionResult);
final RunContentBuilder contentBuilder = new RunContentBuilder(executionResult, env);
if (shouldAddDefaultActions) {
addDefaultActions(contentBuilder, executionResult);
}
return contentBuilder.showRunContent(env.getContentToReuse());
}
use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class RmiStubsGenerator method generateRmiStubs.
private ExitCode generateRmiStubs(final CompileContext context, Map<ModuleBuildTarget, Collection<ClassItem>> remoteClasses, ModuleChunk chunk, OutputConsumer outputConsumer) {
ExitCode exitCode = ExitCode.NOTHING_DONE;
final Collection<File> classpath = ProjectPaths.getCompilationClasspath(chunk, false);
final StringBuilder buf = new StringBuilder();
for (File file : classpath) {
if (buf.length() > 0) {
buf.append(File.pathSeparator);
}
buf.append(file.getPath());
}
final String classpathString = buf.toString();
final String rmicPath = getPathToRmic(chunk);
final RmicCompilerOptions options = getOptions(context);
final List<ModuleBuildTarget> targetsProcessed = new ArrayList<>(remoteClasses.size());
for (Map.Entry<ModuleBuildTarget, Collection<ClassItem>> entry : remoteClasses.entrySet()) {
try {
final ModuleBuildTarget target = entry.getKey();
final Collection<String> cmdLine = createStartupCommand(target, rmicPath, classpathString, options, entry.getValue());
final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmdLine));
final BaseOSProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmdLine, " "), null) {
@NotNull
@Override
protected Future<?> executeOnPooledThread(@NotNull Runnable task) {
return SharedThreadPool.getInstance().executeOnPooledThread(task);
}
};
final RmicOutputParser stdOutParser = new RmicOutputParser(context, getPresentableName());
final RmicOutputParser stdErrParser = new RmicOutputParser(context, getPresentableName());
handler.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
if (outputType == ProcessOutputTypes.STDOUT) {
stdOutParser.append(event.getText());
} else if (outputType == ProcessOutputTypes.STDERR) {
stdErrParser.append(event.getText());
}
}
@Override
public void processTerminated(ProcessEvent event) {
super.processTerminated(event);
}
});
handler.startNotify();
handler.waitFor();
targetsProcessed.add(target);
if (stdErrParser.isErrorsReported() || stdOutParser.isErrorsReported()) {
break;
} else {
final int exitValue = handler.getProcess().exitValue();
if (exitValue != 0) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "RMI stub generation failed"));
break;
}
}
} catch (IOException e) {
context.processMessage(new CompilerMessage(getPresentableName(), e));
break;
}
}
// registering generated files
final Map<File, File[]> fsCache = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
for (ModuleBuildTarget target : targetsProcessed) {
final Collection<ClassItem> items = remoteClasses.get(target);
for (ClassItem item : items) {
File[] children = fsCache.get(item.parentDir);
if (children == null) {
children = item.parentDir.listFiles();
if (children == null) {
children = EMPTY_FILE_ARRAY;
}
fsCache.put(item.parentDir, children);
}
final Collection<File> files = item.selectGeneratedFiles(children);
if (!files.isEmpty()) {
final Collection<String> sources = item.compiledClass.getSourceFilesPaths();
for (File generated : files) {
try {
outputConsumer.registerOutputFile(target, generated, sources);
} catch (IOException e) {
context.processMessage(new CompilerMessage(getPresentableName(), e));
}
}
}
}
}
return exitCode;
}
use of com.intellij.execution.process.ProcessAdapter 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.ProcessAdapter 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.ProcessAdapter 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);
}
});
}
Aggregations