From 3c1f0ee7fac7c29825376d64692126877ab51b3b Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 3 Mar 2014 17:12:23 +0000 Subject: [PATCH] add a 'binaryOutput' attribute to redirector to prevent Ant from corrupting, well, binary output. PRs 56156 and 55667 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1573617 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 7 +++++ manual/Types/redirector.html | 10 +++++++ .../apache/tools/ant/taskdefs/Redirector.java | 23 +++++++++++++-- .../tools/ant/types/RedirectorElement.java | 16 ++++++++++ src/tests/antunit/taskdefs/exec/exec-test.xml | 29 +++++++++++++++++++ 5 files changed, 83 insertions(+), 2 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 4246cc32e..879f243d2 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -111,6 +111,13 @@ Other changes: * changes to DOMElementWriter to make OutOfMemoryErrors less likely. Bugzilla Report 54147 + * has a new attribute binaryOutput that prevents Ant + from splitting the output into lines. This prevents binary output + from being corrupted but may lead to error and normal output being + mixed up. + Bugzilla Report 55667 + Bugzilla Report 56156 + Changes from Ant 1.9.2 TO Ant 1.9.3 =================================== diff --git a/manual/Types/redirector.html b/manual/Types/redirector.html index e3191cd0d..d0e368388 100644 --- a/manual/Types/redirector.html +++ b/manual/Types/redirector.html @@ -136,6 +136,16 @@ source (input) and destination (output/error) files. Since Apache Ant 1.6.2 No, default is true + + binaryOutput + When set to true Ant will not try to split the + output into lines - which it will usually do in order to separate + error from normal output. This setting will not prevent binary + output from getting corrupted if you also specify filter chains. + Since Ant 1.9.4. + + No, default is false +

Parameters specified as nested elements

inputmapper

diff --git a/src/main/org/apache/tools/ant/taskdefs/Redirector.java b/src/main/org/apache/tools/ant/taskdefs/Redirector.java index ed6b64a99..cec897561 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Redirector.java +++ b/src/main/org/apache/tools/ant/taskdefs/Redirector.java @@ -192,6 +192,9 @@ public class Redirector { /** Mutex for err */ private Object errMutex = new Object(); + /** Is the output binary or can we safely split it into lines? */ + private boolean outputIsBinary = false; + /** * Create a redirector instance for the given task * @@ -523,6 +526,18 @@ public class Redirector { } } + /** + * Whether to consider the output created by the process binary. + * + *

Binary output will not be split into lines which may make + * error and normal output look mixed up when they get written to + * the same stream.

+ * @since 1.9.4 + */ + public void setBinaryOutput(boolean b) { + outputIsBinary = b; + } + /** * Set a property from a ByteArrayOutputStream * @@ -722,8 +737,12 @@ public class Redirector { OutputStreamFunneler funneler = new OutputStreamFunneler( outputStream, funnelTimeout); try { - outputStream = new LineOrientedOutputStreamRedirector(funneler.getFunnelInstance()); - errorStream = new LineOrientedOutputStreamRedirector(funneler.getFunnelInstance()); + outputStream = funneler.getFunnelInstance(); + errorStream = funneler.getFunnelInstance(); + if (!outputIsBinary) { + outputStream = new LineOrientedOutputStreamRedirector(outputStream); + errorStream = new LineOrientedOutputStreamRedirector(errorStream); + } } catch (IOException eyeOhEx) { throw new BuildException( "error splitting output/error streams", eyeOhEx); diff --git a/src/main/org/apache/tools/ant/types/RedirectorElement.java b/src/main/org/apache/tools/ant/types/RedirectorElement.java index a611f59ec..9babead0e 100644 --- a/src/main/org/apache/tools/ant/types/RedirectorElement.java +++ b/src/main/org/apache/tools/ant/types/RedirectorElement.java @@ -104,6 +104,9 @@ public class RedirectorElement extends DataType { /** whether to log the inputstring */ private Boolean logInputString; + /** Is the output binary or can we safely split it into lines? */ + private boolean outputIsBinary = false; + /** * Add the input file mapper. * @param inputMapper Mapper. @@ -426,6 +429,18 @@ public class RedirectorElement extends DataType { return result; } + /** + * Whether to consider the output created by the process binary. + * + *

Binary output will not be split into lines which may make + * error and normal output look mixed up when they get written to + * the same stream.

+ * @since 1.9.4 + */ + public void setBinaryOutput(boolean b) { + outputIsBinary = b; + } + /** * Configure the specified Redirector. * @param redirector Redirector. @@ -530,6 +545,7 @@ public class RedirectorElement extends DataType { if (errorEncoding != null) { redirector.setErrorEncoding(errorEncoding); } + redirector.setBinaryOutput(outputIsBinary); } /** diff --git a/src/tests/antunit/taskdefs/exec/exec-test.xml b/src/tests/antunit/taskdefs/exec/exec-test.xml index f0ee949f5..25b00889c 100644 --- a/src/tests/antunit/taskdefs/exec/exec-test.xml +++ b/src/tests/antunit/taskdefs/exec/exec-test.xml @@ -678,4 +678,33 @@ public class Hello { + + 1 2 3 + 1${line.separator}2${line.separator}3 + + + + + + + + + + + + + 1 2 3 + + + + + + + + + + +