mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
both capturing process classes to listen to the progress manager and be cancellable
This commit is contained in:
+22
-1
@@ -18,7 +18,9 @@ package com.intellij.execution.process;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -65,15 +67,34 @@ public class CapturingProcessHandler extends OSProcessHandler {
|
||||
|
||||
public ProcessOutput runProcess() {
|
||||
startNotify();
|
||||
if (waitFor()) {
|
||||
if (waitForProcessListeningProgress(this)) {
|
||||
myOutput.setExitCode(getProcess().exitValue());
|
||||
}
|
||||
else {
|
||||
LOG.info("runProcess: exit value unavailable");
|
||||
}
|
||||
|
||||
return myOutput;
|
||||
}
|
||||
|
||||
public static boolean waitForProcessListeningProgress(ProcessHandler handler) {
|
||||
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
if (indicator != null) {
|
||||
while (!handler.waitFor(300)) {
|
||||
if (indicator.isCanceled()) {
|
||||
handler.destroyProcess();
|
||||
throw new ProcessCanceledException();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!handler.waitFor()) {
|
||||
LOG.info("runProcess: exit value unavailable");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts process with specified timeout
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user