both capturing process classes to listen to the progress manager and be cancellable

This commit is contained in:
irengrig
2016-01-13 21:44:25 +01:00
parent 7b26e4eb36
commit 32c619bc77
@@ -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
*