You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2019/02/17 20:33:42 UTC
[incubator-netbeans] branch master updated: [NETBEANS-2038] Do not
dump ambiguous output when a build is cancelled.
This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new e8db731 [NETBEANS-2038] Do not dump ambiguous output when a build is cancelled.
e8db731 is described below
commit e8db731de796ab9ac7c3e025bca1e7f45c1b8c09
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Sat Feb 16 22:32:04 2019 -0800
[NETBEANS-2038] Do not dump ambiguous output when a build is cancelled.
---
.../execute/EscapeProcessingOutputStream.java | 24 +++++-----
.../gradle/execute/GradleDaemonExecutor.java | 55 ++++++++++++----------
2 files changed, 44 insertions(+), 35 deletions(-)
diff --git a/groovy/gradle/src/org/netbeans/modules/gradle/execute/EscapeProcessingOutputStream.java b/groovy/gradle/src/org/netbeans/modules/gradle/execute/EscapeProcessingOutputStream.java
index d0b070d..d4f6d22 100644
--- a/groovy/gradle/src/org/netbeans/modules/gradle/execute/EscapeProcessingOutputStream.java
+++ b/groovy/gradle/src/org/netbeans/modules/gradle/execute/EscapeProcessingOutputStream.java
@@ -23,16 +23,18 @@ import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
*
* @author Laszlo Kishalmi
*/
class EscapeProcessingOutputStream extends OutputStream {
-
+
boolean esc;
boolean csi;
- ByteBuffer buffer = new ByteBuffer();
+ final AtomicBoolean closed = new AtomicBoolean();
+ final ByteBuffer buffer = new ByteBuffer();
final EscapeProcessor processor;
public EscapeProcessingOutputStream(EscapeProcessor processor) {
@@ -41,9 +43,8 @@ class EscapeProcessingOutputStream extends OutputStream {
@Override
public void write(int b) throws IOException {
- if (buffer == null) {
- throw new IOException("Write attempt on a closed stream."); //NOI18N
- }
+ // Simply ignore writing on a closed stream.
+ if (closed.get()) return;
if (b == 0x1B) {
esc = true; //Entering EscapeProcessingMode
processBulk(); //Process the Buffer collected so far
@@ -72,8 +73,9 @@ class EscapeProcessingOutputStream extends OutputStream {
@Override
public void close() throws IOException {
- flush();
- buffer = null;
+ if (closed.compareAndSet(false, true)) {
+ flush();
+ }
}
@Override
@@ -83,7 +85,7 @@ class EscapeProcessingOutputStream extends OutputStream {
}
}
-
+
private void processCommand(char command) {
String buf = buffer.read();
String[] sargs = buf.split(";");
@@ -105,18 +107,18 @@ class EscapeProcessingOutputStream extends OutputStream {
processor.processText(out);
}
}
-
+
private static class ByteBuffer {
private int pos = 0;
private byte[] buf = new byte[1024];
-
+
public void put(int b) {
if (pos == buf.length) {
buf = Arrays.copyOf(buf, buf.length + 1024);
}
buf[pos++] = (byte) b;
}
-
+
public String read() {
String ret = new String(buf, 0, pos, StandardCharsets.UTF_8);
pos = 0;
diff --git a/groovy/gradle/src/org/netbeans/modules/gradle/execute/GradleDaemonExecutor.java b/groovy/gradle/src/org/netbeans/modules/gradle/execute/GradleDaemonExecutor.java
index a6ac52b..c85a270 100644
--- a/groovy/gradle/src/org/netbeans/modules/gradle/execute/GradleDaemonExecutor.java
+++ b/groovy/gradle/src/org/netbeans/modules/gradle/execute/GradleDaemonExecutor.java
@@ -69,6 +69,9 @@ public final class GradleDaemonExecutor extends AbstractGradleExecutor {
private static final Logger LOGGER = Logger.getLogger(GradleDaemonExecutor.class.getName());
private final ProgressHandle handle;
+ private OutputStream outStream;
+ private OutputStream errStream;
+ private boolean cancelling;
@SuppressWarnings("LeakingThisInConstructor")
public GradleDaemonExecutor(RunConfig config) {
@@ -97,7 +100,7 @@ public final class GradleDaemonExecutor extends AbstractGradleExecutor {
try {
taskSemaphore.wait();
} catch (InterruptedException ex) {
- LOGGER.log(Level.FINE, "interrupted", ex);
+ LOGGER.log(Level.FINE, "interrupted", ex); //NOI18N
}
}
}
@@ -106,8 +109,6 @@ public final class GradleDaemonExecutor extends AbstractGradleExecutor {
final InputOutput ioput = getInputOutput();
actionStatesAtStart();
handle.start();
- OutputStream outStream = null;
- OutputStream errStream = null;
try {
BuildExecutionSupport.registerRunningItem(item);
@@ -167,14 +168,15 @@ public final class GradleDaemonExecutor extends AbstractGradleExecutor {
buildLauncher.run();
StatusDisplayer.getDefault().setStatusText(Bundle.BUILD_SUCCESS(getProjectName()));
} catch (BuildCancelledException ex) {
- try {
- IOColorPrint.print(io, "\nBUILD ABORTED\n", IOColors.getColor(io, IOColors.OutputType.ERROR)); //NOI18N
- } catch (IOException iex) {
- }
+ showAbort();
} catch (UncheckedException | BuildException ex) {
- StatusDisplayer.getDefault().setStatusText(Bundle.BUILD_FAILED(getProjectName()));
- //TODO: Handle Cancelled builds
- // We just swallow BUILD FAILED exception silently
+ if (!cancelling) {
+ StatusDisplayer.getDefault().setStatusText(Bundle.BUILD_FAILED(getProjectName()));
+ } else {
+ // This can happen if cancelling a Gradle build which is running
+ // an external aplication
+ showAbort();
+ }
} finally {
BuildExecutionSupport.registerFinishedItem(item);
ioput.getOut().close();
@@ -182,18 +184,7 @@ public final class GradleDaemonExecutor extends AbstractGradleExecutor {
if (pconn != null) {
pconn.close();
}
- if (outStream != null) {
- try {
- outStream.close();
- } catch (IOException iox) {
- }
- }
- if (errStream != null) {
- try {
- errStream.close();
- } catch (IOException iox) {
- }
- }
+ closeOutErr();
checkForExternalModifications();
handle.finish();
markFreeTab();
@@ -229,7 +220,7 @@ public final class GradleDaemonExecutor extends AbstractGradleExecutor {
String relRoot = projectPath.relativize(rootPath).toString();
relRoot = relRoot.isEmpty() ? "." : relRoot;
- commandLine.append(relRoot).append("/gradlew");
+ commandLine.append(relRoot).append("/gradlew"); //NOI18N
} else {
File gradleDistribution = RunUtils.evaluateGradleDistribution(null, false);
if (gradleDistribution != null) {
@@ -254,7 +245,20 @@ public final class GradleDaemonExecutor extends AbstractGradleExecutor {
io.getOut().print(commandLine);
}
} catch (IOException ex) {
- //TODO: Shall not happen...
+ // Shall not happen...
+ }
+ }
+
+ private synchronized void closeOutErr() {
+ if (outStream != null) try {outStream.close();} catch (IOException ex) {}
+ if (errStream != null) try {errStream.close();} catch (IOException ex) {}
+ }
+
+ @NbBundle.Messages("TXT_BUILD_ABORTED=\nBUILD ABORTED\n")
+ private void showAbort() {
+ try {
+ IOColorPrint.print(io, Bundle.TXT_BUILD_ABORTED(), IOColors.getColor(io, IOColors.OutputType.LOG_DEBUG));
+ } catch (IOException ex) {
}
}
@@ -264,6 +268,9 @@ public final class GradleDaemonExecutor extends AbstractGradleExecutor {
if (cancelTokenSource != null) {
handle.switchToIndeterminate();
handle.setDisplayName(Bundle.LBL_ABORTING_BUILD());
+ // Closing out and err streams to prevent ambigous output NETBEANS-2038
+ closeOutErr();
+ cancelling = true;
cancelTokenSource.cancel();
}
return true;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists