use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class DebuggerManagerImpl method attachVirtualMachine.
@Override
@Nullable
public DebuggerSession attachVirtualMachine(@NotNull DebugEnvironment environment) throws ExecutionException {
ApplicationManager.getApplication().assertIsDispatchThread();
DebugProcessEvents debugProcess = new DebugProcessEvents(myProject);
DebuggerSession session = DebuggerSession.create(environment.getSessionName(), debugProcess, environment);
ExecutionResult executionResult = session.getProcess().getExecutionResult();
if (executionResult == null) {
return null;
}
session.getContextManager().addListener(mySessionListener);
getContextManager().setState(DebuggerContextUtil.createDebuggerContext(session, session.getContextManager().getContext().getSuspendContext()), session.getState(), DebuggerSession.Event.CONTEXT, null);
final ProcessHandler processHandler = executionResult.getProcessHandler();
synchronized (mySessions) {
mySessions.put(processHandler, session);
}
if (!(processHandler instanceof RemoteDebugProcessHandler)) {
// add listener only to non-remote process handler:
// on Unix systems destroying process does not cause VMDeathEvent to be generated,
// so we need to call debugProcess.stop() explicitly for graceful termination.
// RemoteProcessHandler on the other hand will call debugProcess.stop() as a part of destroyProcess() and detachProcess() implementation,
// so we shouldn't add the listener to avoid calling stop() twice
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
ProcessHandler processHandler = event.getProcessHandler();
final DebugProcessImpl debugProcess = getDebugProcess(processHandler);
if (debugProcess != null) {
// if current thread is a "debugger manager thread", stop will execute synchronously
// it is KillableColoredProcessHandler responsibility to terminate VM
debugProcess.stop(willBeDestroyed && !(processHandler instanceof KillableColoredProcessHandler && ((KillableColoredProcessHandler) processHandler).shouldKillProcessSoftly()));
// if processWillTerminate() is called from AWT thread debugProcess.waitFor() will block it and the whole app will hang
if (!DebuggerManagerThreadImpl.isManagerThread()) {
if (SwingUtilities.isEventDispatchThread()) {
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
debugProcess.waitFor(10000);
}, "Waiting For Debugger Response", false, debugProcess.getProject());
} else {
debugProcess.waitFor(10000);
}
}
}
}
});
}
myDispatcher.getMulticaster().sessionCreated(session);
if (debugProcess.isDetached() || debugProcess.isDetaching()) {
session.dispose();
return null;
}
if (environment.isRemote()) {
// optimization: that way BatchEvaluator will not try to lookup the class file in remote VM
// which is an expensive operation when executed first time
debugProcess.putUserData(BatchEvaluator.REMOTE_SESSION_KEY, Boolean.TRUE);
}
return session;
}
use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class ExternalJavacManager method forkJavac.
public boolean forkJavac(final String javaHome, final int heapSize, List<String> vmOptions, List<String> options, Collection<File> platformCp, Collection<File> classpath, Collection<File> modulePath, Collection<File> sourcePath, Collection<File> files, Map<File, Set<File>> outs, final DiagnosticOutputConsumer diagnosticSink, OutputFileConsumer outputSink, final JavaCompilingTool compilingTool, final CanceledStatus cancelStatus) {
final ExternalJavacMessageHandler rh = new ExternalJavacMessageHandler(diagnosticSink, outputSink, getEncodingName(options));
final JavacRemoteProto.Message.Request request = JavacProtoUtil.createCompilationRequest(options, files, classpath, platformCp, modulePath, sourcePath, outs);
final UUID uuid = UUID.randomUUID();
final JavacProcessDescriptor processDescriptor = new JavacProcessDescriptor(uuid, rh, request);
synchronized (myMessageHandlers) {
myMessageHandlers.put(uuid, processDescriptor);
}
try {
final ExternalJavacProcessHandler processHandler = launchExternalJavacProcess(uuid, javaHome, heapSize, myListenPort, myWorkingDir, vmOptions, compilingTool);
processHandler.addProcessListener(new ProcessAdapter() {
public void onTextAvailable(ProcessEvent event, Key outputType) {
final String text = event.getText();
if (!StringUtil.isEmptyOrSpaces(text)) {
String prefix = null;
if (outputType == ProcessOutputTypes.STDOUT) {
prefix = STDOUT_LINE_PREFIX;
} else if (outputType == ProcessOutputTypes.STDERR) {
prefix = STDERR_LINE_PREFIX;
}
if (prefix != null) {
diagnosticSink.outputLineAvailable(prefix + ": " + text);
}
}
}
});
processHandler.startNotify();
while (!processDescriptor.waitFor(300L)) {
if (processHandler.isProcessTerminated() && processDescriptor.channel == null && processHandler.getExitCode() != 0) {
// process terminated abnormally and no communication took place
processDescriptor.setDone();
break;
}
if (cancelStatus.isCanceled()) {
processDescriptor.cancelBuild();
}
}
return rh.isTerminatedSuccessfully();
} catch (Throwable e) {
LOG.info(e);
diagnosticSink.report(new PlainMessageDiagnostic(Diagnostic.Kind.ERROR, e.getMessage()));
} finally {
unregisterMessageHandler(uuid);
}
return false;
}
use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class LogConsoleBase method attachStopLogConsoleTrackingListener.
public void attachStopLogConsoleTrackingListener(final ProcessHandler process) {
if (process != null) {
final ProcessAdapter stopListener = new ProcessAdapter() {
@Override
public void processTerminated(final ProcessEvent event) {
process.removeProcessListener(this);
stopRunning(true);
}
};
process.addProcessListener(stopListener);
}
}
use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class TerminateRemoteProcessDialog method show.
public static GeneralSettings.ProcessCloseConfirmation show(Project project, String sessionName, ProcessHandler processHandler) {
//noinspection deprecation
if (processHandler.isSilentlyDestroyOnClose() || Boolean.TRUE.equals(processHandler.getUserData(ProcessHandler.SILENTLY_DESTROY_ON_CLOSE))) {
return GeneralSettings.ProcessCloseConfirmation.TERMINATE;
}
boolean canDisconnect = !Boolean.TRUE.equals(processHandler.getUserData(RunContentManagerImpl.ALWAYS_USE_DEFAULT_STOPPING_BEHAVIOUR_KEY));
GeneralSettings.ProcessCloseConfirmation confirmation = GeneralSettings.getInstance().getProcessCloseConfirmation();
if (confirmation != GeneralSettings.ProcessCloseConfirmation.ASK) {
if (confirmation == GeneralSettings.ProcessCloseConfirmation.DISCONNECT && !canDisconnect) {
confirmation = GeneralSettings.ProcessCloseConfirmation.TERMINATE;
}
return confirmation;
}
List<String> options = new ArrayList<>(3);
options.add(ExecutionBundle.message("button.terminate"));
if (canDisconnect) {
options.add(ExecutionBundle.message("button.disconnect"));
}
options.add(CommonBundle.getCancelButtonText());
DialogWrapper.DoNotAskOption.Adapter doNotAskOption = new DialogWrapper.DoNotAskOption.Adapter() {
@Override
public void rememberChoice(boolean isSelected, int exitCode) {
if (isSelected) {
GeneralSettings.ProcessCloseConfirmation confirmation = getConfirmation(exitCode, canDisconnect);
if (confirmation != null) {
GeneralSettings.getInstance().setProcessCloseConfirmation(confirmation);
}
}
}
};
AtomicBoolean alreadyGone = new AtomicBoolean(false);
Runnable dialogRemover = Messages.createMessageDialogRemover(project);
ProcessAdapter listener = new ProcessAdapter() {
public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
alreadyGone.set(true);
dialogRemover.run();
}
};
processHandler.addProcessListener(listener);
boolean defaultDisconnect = processHandler.detachIsDefault();
int exitCode = Messages.showDialog(project, ExecutionBundle.message("terminate.process.confirmation.text", sessionName), ExecutionBundle.message("process.is.running.dialog.title", sessionName), ArrayUtil.toStringArray(options), canDisconnect && defaultDisconnect ? 1 : 0, Messages.getWarningIcon(), doNotAskOption);
processHandler.removeProcessListener(listener);
if (alreadyGone.get()) {
return GeneralSettings.ProcessCloseConfirmation.DISCONNECT;
}
return getConfirmation(exitCode, canDisconnect);
}
use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class MavenConsoleImpl method attachToProcess.
public void attachToProcess(ProcessHandler processHandler) {
myConsoleView.attachToProcess(processHandler);
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
ensureAttachedToToolWindow();
}
});
}
Aggregations