From 32c619bc7799ed523eb505aa2b319911d1952a81 Mon Sep 17 00:00:00 2001 From: irengrig Date: Wed, 13 Jan 2016 21:41:11 +0100 Subject: [PATCH] both capturing process classes to listen to the progress manager and be cancellable --- .../process/CapturingProcessHandler.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/platform/platform-api/src/com/intellij/execution/process/CapturingProcessHandler.java b/platform/platform-api/src/com/intellij/execution/process/CapturingProcessHandler.java index d37946444b95..13331d11520f 100644 --- a/platform/platform-api/src/com/intellij/execution/process/CapturingProcessHandler.java +++ b/platform/platform-api/src/com/intellij/execution/process/CapturingProcessHandler.java @@ -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 *