ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1573617 - in /ant/core/trunk: WHATSNEW manual/Types/redirector.html src/main/org/apache/tools/ant/taskdefs/Redirector.java src/main/org/apache/tools/ant/types/RedirectorElement.java src/tests/antunit/taskdefs/exec/exec-test.xml
Date Mon, 03 Mar 2014 17:12:24 GMT
Author: bodewig
Date: Mon Mar  3 17:12:23 2014
New Revision: 1573617

URL: http://svn.apache.org/r1573617
Log:
add a 'binaryOutput' attribute to redirector to prevent Ant from corrupting, well, binary
output.  PRs 56156 and 55667

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/manual/Types/redirector.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Redirector.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/RedirectorElement.java
    ant/core/trunk/src/tests/antunit/taskdefs/exec/exec-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1573617&r1=1573616&r2=1573617&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Mar  3 17:12:23 2014
@@ -111,6 +111,13 @@ Other changes:
  * changes to DOMElementWriter to make OutOfMemoryErrors less likely.
    Bugzilla Report 54147
 
+ * <redirector> 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
 ===================================
 

Modified: ant/core/trunk/manual/Types/redirector.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/manual/Types/redirector.html?rev=1573617&r1=1573616&r2=1573617&view=diff
==============================================================================
--- ant/core/trunk/manual/Types/redirector.html (original)
+++ ant/core/trunk/manual/Types/redirector.html Mon Mar  3 17:12:23 2014
@@ -136,6 +136,16 @@ source (input) and destination (output/e
     </td>
     <td align="center" valign="top">No, default is <code>true</code></td>
   </tr>
+  <tr>
+    <td valign="top">binaryOutput</td>
+    <td valign="top">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.
+      <i>Since Ant 1.9.4</i>.
+    </td>
+    <td align="center" valign="top">No, default is <code>false</code></td>
+  </tr>
 </table>
 <h3>Parameters specified as nested elements</h3>
 <h4>inputmapper</h4>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Redirector.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Redirector.java?rev=1573617&r1=1573616&r2=1573617&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Redirector.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Redirector.java Mon Mar  3 17:12:23
2014
@@ -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
      *
@@ -524,6 +527,18 @@ public class Redirector {
     }
 
     /**
+     * Whether to consider the output created by the process binary.
+     *
+     * <p>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.</p>
+     * @since 1.9.4
+     */
+    public void setBinaryOutput(boolean b) {
+        outputIsBinary = b;
+    }
+
+    /**
      * Set a property from a ByteArrayOutputStream
      *
      * @param baos
@@ -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);

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/RedirectorElement.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/RedirectorElement.java?rev=1573617&r1=1573616&r2=1573617&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/RedirectorElement.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/RedirectorElement.java Mon Mar  3 17:12:23
2014
@@ -104,6 +104,9 @@ public class RedirectorElement extends D
     /** 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   <code>Mapper</code>.
@@ -427,6 +430,18 @@ public class RedirectorElement extends D
     }
 
     /**
+     * Whether to consider the output created by the process binary.
+     *
+     * <p>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.</p>
+     * @since 1.9.4
+     */
+    public void setBinaryOutput(boolean b) {
+        outputIsBinary = b;
+    }
+
+    /**
      * Configure the specified <code>Redirector</code>.
      * @param redirector   <code>Redirector</code>.
      */
@@ -530,6 +545,7 @@ public class RedirectorElement extends D
         if (errorEncoding != null) {
             redirector.setErrorEncoding(errorEncoding);
         }
+        redirector.setBinaryOutput(outputIsBinary);
     }
 
     /**

Modified: ant/core/trunk/src/tests/antunit/taskdefs/exec/exec-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/exec/exec-test.xml?rev=1573617&r1=1573616&r2=1573617&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/exec/exec-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/exec/exec-test.xml Mon Mar  3 17:12:23 2014
@@ -678,4 +678,33 @@ public class Hello {
       <au:assertLogDoesntContain text="Hello 20"/>
     </target>
 
+    <target name="test-output-is-split-into-lines" if="cat.can.run" depends="setUp">
+        <echo file="${input}/redirector.in">1&#xa;2&#xd;&#xa;3</echo>
+        <echo file="${output}/expected">1${line.separator}2${line.separator}3</echo>
+        <exec executable="cat">
+            <redirector output="${output}/redirector.out"
+                        input="${input}/redirector.in"/>
+        </exec>
+        <au:assertTrue>
+            <resourcesmatch astext="true">
+                <file file="${output}/redirector.out" />
+                <file file="${output}/expected" />
+            </resourcesmatch>
+        </au:assertTrue>
+    </target>
+
+    <target name="test-binary-output-is-not-split-into-lines" if="cat.can.run" depends="setUp">
+        <echo file="${input}/redirector.in">1&#xa;2&#xd;&#xa;3</echo>
+        <exec executable="cat">
+            <redirector output="${output}/redirector.out" binaryOutput="true"
+                        input="${input}/redirector.in"/>
+        </exec>
+        <au:assertTrue>
+            <resourcesmatch astext="true">
+                <file file="${output}/redirector.out" />
+                <file file="${input}/redirector.in" />
+            </resourcesmatch>
+        </au:assertTrue>
+    </target>
+
 </project>



Mime
View raw message