| @@ -69,6 +69,11 @@ Other changes: | |||||
| task. | task. | ||||
| Bugzilla Report 65089 | Bugzilla Report 65089 | ||||
| * added new disardOutput and discardError properties to redirector | |||||
| and the exec, apply and java tasks which can be used to completely | |||||
| discard any (error) output. This is a platform independent | |||||
| alternative to directiong output to any kind of null device. | |||||
| Changes from Ant 1.10.8 TO Ant 1.10.9 | Changes from Ant 1.10.8 TO Ant 1.10.9 | ||||
| ===================================== | ===================================== | ||||
| @@ -258,6 +258,27 @@ standard input.</p> | |||||
| <td>Whether to bypass timestamp comparisons for target files. <em>Since Ant 1.6.3</em>.</td> | <td>Whether to bypass timestamp comparisons for target files. <em>Since Ant 1.6.3</em>.</td> | ||||
| <td>No; default is <q>false</q></td> | <td>No; default is <q>false</q></td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td>discardOutput</td> | |||||
| <td>Whether output should completely be discarded. This setting is | |||||
| incompatible with any setting that redirects output to files or | |||||
| properties.<br/> | |||||
| If you set this to <q>true</q> error output will be discared as | |||||
| well unless you redirect error output to files, properties or | |||||
| enable <q>logError</q>. | |||||
| <em>Since Ant 1.10.10</em> | |||||
| </td> | |||||
| <td>No; defaults to <q>false</q></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td>discardError</td> | |||||
| <td>Whether error output should completely be discarded. This | |||||
| setting is incompatible with any setting that redirects error | |||||
| output to files or properties as well as <q>logError</q>. | |||||
| <em>Since Ant 1.10.10</em> | |||||
| </td> | |||||
| <td>No; defaults to <q>false</q></td> | |||||
| </tr> | |||||
| </table> | </table> | ||||
| <h3>Parameters specified as nested elements</h3> | <h3>Parameters specified as nested elements</h3> | ||||
| <h4>fileset</h4> | <h4>fileset</h4> | ||||
| @@ -262,6 +262,27 @@ standard input.</p> | |||||
| when resolving the location of the executable. <em>since Ant 1.6.3</em></td> | when resolving the location of the executable. <em>since Ant 1.6.3</em></td> | ||||
| <td>No; default is <q>false</q></td> | <td>No; default is <q>false</q></td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td>discardOutput</td> | |||||
| <td>Whether output should completely be discarded. This setting is | |||||
| incompatible with any setting that redirects output to files or | |||||
| properties.<br/> | |||||
| If you set this to <q>true</q> error output will be discared as | |||||
| well unless you redirect error output to files, properties or | |||||
| enable <q>logError</q>. | |||||
| <em>Since Ant 1.10.10</em> | |||||
| </td> | |||||
| <td>No; defaults to <q>false</q></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td>discardError</td> | |||||
| <td>Whether error output should completely be discarded. This | |||||
| setting is incompatible with any setting that redirects error | |||||
| output to files or properties as well as <q>logError</q>. | |||||
| <em>Since Ant 1.10.10</em> | |||||
| </td> | |||||
| <td>No; defaults to <q>false</q></td> | |||||
| </tr> | |||||
| </table> | </table> | ||||
| <h3>Examples</h3> | <h3>Examples</h3> | ||||
| <pre> | <pre> | ||||
| @@ -218,6 +218,27 @@ because it tries to read from the standard input.</p> | |||||
| forked JVM will be the same as those of the JVM running Ant. <em>since Ant 1.7</em></td> | forked JVM will be the same as those of the JVM running Ant. <em>since Ant 1.7</em></td> | ||||
| <td>No; default is <q>false</q>, ignored if <var>fork</var> is <q>false</q></td> | <td>No; default is <q>false</q>, ignored if <var>fork</var> is <q>false</q></td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td>discardOutput</td> | |||||
| <td>Whether output should completely be discarded. This setting is | |||||
| incompatible with any setting that redirects output to files or | |||||
| properties.<br/> | |||||
| If you set this to <q>true</q> error output will be discared as | |||||
| well unless you redirect error output to files, properties or | |||||
| enable <q>logError</q>. | |||||
| <em>Since Ant 1.10.10</em> | |||||
| </td> | |||||
| <td>No; defaults to <q>false</q></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td>discardError</td> | |||||
| <td>Whether error output should completely be discarded. This | |||||
| setting is incompatible with any setting that redirects error | |||||
| output to files or properties as well as <q>logError</q>. | |||||
| <em>Since Ant 1.10.10</em> | |||||
| </td> | |||||
| <td>No; defaults to <q>false</q></td> | |||||
| </tr> | |||||
| </table> | </table> | ||||
| <h3>Parameters specified as nested elements</h3> | <h3>Parameters specified as nested elements</h3> | ||||
| <h4>arg and jvmarg</h4> | <h4>arg and jvmarg</h4> | ||||
| @@ -129,6 +129,27 @@ specify source (input) and destination (output/error) files.</p> | |||||
| </td> | </td> | ||||
| <td>No; default is <q>false</q></td> | <td>No; default is <q>false</q></td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td>discardOutput</td> | |||||
| <td>Whether output should completely be discarded. This setting is | |||||
| incompatible with any setting that redirects output to files or | |||||
| properties.<br/> | |||||
| If you set this to <q>true</q> error output will be discared as | |||||
| well unless you redirect error output to files, properties or | |||||
| enable <q>logError</q>. | |||||
| <em>Since Ant 1.10.10</em> | |||||
| </td> | |||||
| <td>No; defaults to <q>false</q></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td>discardError</td> | |||||
| <td>Whether error output should completely be discarded. This | |||||
| setting is incompatible with any setting that redirects error | |||||
| output to files or properties as well as <q>logError</q>. | |||||
| <em>Since Ant 1.10.10</em> | |||||
| </td> | |||||
| <td>No; defaults to <q>false</q></td> | |||||
| </tr> | |||||
| </table> | </table> | ||||
| <h3>Parameters specified as nested elements</h3> | <h3>Parameters specified as nested elements</h3> | ||||
| <h4>inputmapper</h4> | <h4>inputmapper</h4> | ||||
| @@ -380,6 +380,36 @@ public class ExecTask extends Task { | |||||
| incompatibleWithSpawn |= append; | incompatibleWithSpawn |= append; | ||||
| } | } | ||||
| /** | |||||
| * Whether output should be discarded. | |||||
| * | |||||
| * <p>Defaults to false.</p> | |||||
| * | |||||
| * @param discard | |||||
| * if true output streams are discarded. | |||||
| * | |||||
| * @since Ant 1.10.10 | |||||
| * @see #setDiscardError | |||||
| */ | |||||
| public void setDiscardOutput(final boolean discard) { | |||||
| redirector.setDiscardOutput(discard); | |||||
| } | |||||
| /** | |||||
| * Whether error output should be discarded. | |||||
| * | |||||
| * <p>Defaults to false.</p> | |||||
| * | |||||
| * @param discard | |||||
| * if true error streams are discarded. | |||||
| * | |||||
| * @since Ant 1.10.10 | |||||
| * @see #setDiscardOutput | |||||
| */ | |||||
| public void setDiscardError(final boolean discard) { | |||||
| redirector.setDiscardError(discard); | |||||
| } | |||||
| /** | /** | ||||
| * Add a <code>RedirectorElement</code> to this task. | * Add a <code>RedirectorElement</code> to this task. | ||||
| * | * | ||||
| @@ -707,6 +707,36 @@ public class Java extends Task { | |||||
| incompatibleWithSpawn |= append; | incompatibleWithSpawn |= append; | ||||
| } | } | ||||
| /** | |||||
| * Whether output should be discarded. | |||||
| * | |||||
| * <p>Defaults to false.</p> | |||||
| * | |||||
| * @param discard | |||||
| * if true output streams are discarded. | |||||
| * | |||||
| * @since Ant 1.10.10 | |||||
| * @see #setDiscardError | |||||
| */ | |||||
| public void setDiscardOutput(final boolean discard) { | |||||
| redirector.setDiscardOutput(discard); | |||||
| } | |||||
| /** | |||||
| * Whether error output should be discarded. | |||||
| * | |||||
| * <p>Defaults to false.</p> | |||||
| * | |||||
| * @param discard | |||||
| * if true error streams are discarded. | |||||
| * | |||||
| * @since Ant 1.10.10 | |||||
| * @see #setDiscardOutput | |||||
| */ | |||||
| public void setDiscardError(final boolean discard) { | |||||
| redirector.setDiscardError(discard); | |||||
| } | |||||
| /** | /** | ||||
| * Set the timeout in milliseconds after which the process will be killed. | * Set the timeout in milliseconds after which the process will be killed. | ||||
| * | * | ||||
| @@ -45,6 +45,7 @@ import org.apache.tools.ant.util.KeepAliveOutputStream; | |||||
| import org.apache.tools.ant.util.LazyFileOutputStream; | import org.apache.tools.ant.util.LazyFileOutputStream; | ||||
| import org.apache.tools.ant.util.LeadPipeInputStream; | import org.apache.tools.ant.util.LeadPipeInputStream; | ||||
| import org.apache.tools.ant.util.LineOrientedOutputStreamRedirector; | import org.apache.tools.ant.util.LineOrientedOutputStreamRedirector; | ||||
| import org.apache.tools.ant.util.NullOutputStream; | |||||
| import org.apache.tools.ant.util.OutputStreamFunneler; | import org.apache.tools.ant.util.OutputStreamFunneler; | ||||
| import org.apache.tools.ant.util.ReaderInputStream; | import org.apache.tools.ant.util.ReaderInputStream; | ||||
| import org.apache.tools.ant.util.TeeOutputStream; | import org.apache.tools.ant.util.TeeOutputStream; | ||||
| @@ -197,6 +198,11 @@ public class Redirector { | |||||
| /** Is the output binary or can we safely split it into lines? */ | /** Is the output binary or can we safely split it into lines? */ | ||||
| private boolean outputIsBinary = false; | private boolean outputIsBinary = false; | ||||
| /** Flag which indicates if error and output files are to be discarded. */ | |||||
| private boolean discardOut = false; | |||||
| private boolean discardErr = false; | |||||
| /** | /** | ||||
| * Create a redirector instance for the given task | * Create a redirector instance for the given task | ||||
| * | * | ||||
| @@ -442,6 +448,40 @@ public class Redirector { | |||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Whether output should be discarded. | |||||
| * | |||||
| * <p>Defaults to false.</p> | |||||
| * | |||||
| * @param discard | |||||
| * if true output streams are discarded. | |||||
| * | |||||
| * @since Ant 1.10.10 | |||||
| * @see #setDiscardError | |||||
| */ | |||||
| public void setDiscardOutput(final boolean discard) { | |||||
| synchronized (outMutex) { | |||||
| discardOut = discard; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Whether error output should be discarded. | |||||
| * | |||||
| * <p>Defaults to false.</p> | |||||
| * | |||||
| * @param discard | |||||
| * if true error streams are discarded. | |||||
| * | |||||
| * @since Ant 1.10.10 | |||||
| * @see #setDiscardOutput | |||||
| */ | |||||
| public void setDiscardError(final boolean discard) { | |||||
| synchronized (errMutex) { | |||||
| discardErr = discard; | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * If true, (error and non-error) output will be "teed", redirected as | * If true, (error and non-error) output will be "teed", redirected as | ||||
| * specified while being sent to Ant's logging mechanism as if no | * specified while being sent to Ant's logging mechanism as if no | ||||
| @@ -694,7 +734,17 @@ public class Redirector { | |||||
| /** outStreams */ | /** outStreams */ | ||||
| private void outStreams() { | private void outStreams() { | ||||
| if (out != null && out.length > 0) { | |||||
| final boolean haveOutputFiles = out != null && out.length > 0; | |||||
| if (discardOut) { | |||||
| if (haveOutputFiles || outputProperty != null) { | |||||
| throw new BuildException("Cant discard output when output or outputProperty" | |||||
| + " are set"); | |||||
| } | |||||
| managingTask.log("Discarding output", Project.MSG_VERBOSE); | |||||
| outputStream = NullOutputStream.INSTANCE; | |||||
| return; | |||||
| } | |||||
| if (haveOutputFiles) { | |||||
| final String logHead = "Output " | final String logHead = "Output " | ||||
| + ((appendOut) ? "appended" : "redirected") + " to "; | + ((appendOut) ? "appended" : "redirected") + " to "; | ||||
| outputStream = foldFiles(out, logHead, Project.MSG_VERBOSE, | outputStream = foldFiles(out, logHead, Project.MSG_VERBOSE, | ||||
| @@ -716,7 +766,17 @@ public class Redirector { | |||||
| } | } | ||||
| private void errorStreams() { | private void errorStreams() { | ||||
| if (error != null && error.length > 0) { | |||||
| final boolean haveErrorFiles = error != null && error.length > 0; | |||||
| if (discardErr) { | |||||
| if (haveErrorFiles || errorProperty != null || logError) { | |||||
| throw new BuildException("Cant discard error output when error, errorProperty" | |||||
| + " or logError are set"); | |||||
| } | |||||
| managingTask.log("Discarding error output", Project.MSG_VERBOSE); | |||||
| errorStream = NullOutputStream.INSTANCE; | |||||
| return; | |||||
| } | |||||
| if (haveErrorFiles) { | |||||
| final String logHead = "Error " | final String logHead = "Error " | ||||
| + ((appendErr) ? "appended" : "redirected") + " to "; | + ((appendErr) ? "appended" : "redirected") + " to "; | ||||
| errorStream = foldFiles(error, logHead, Project.MSG_VERBOSE, | errorStream = foldFiles(error, logHead, Project.MSG_VERBOSE, | ||||
| @@ -0,0 +1,53 @@ | |||||
| /* | |||||
| * Licensed to the Apache Software Foundation (ASF) under one or more | |||||
| * contributor license agreements. See the NOTICE file distributed with | |||||
| * this work for additional information regarding copyright ownership. | |||||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | |||||
| * (the "License"); you may not use this file except in compliance with | |||||
| * the License. You may obtain a copy of the License at | |||||
| * | |||||
| * https://www.apache.org/licenses/LICENSE-2.0 | |||||
| * | |||||
| * Unless required by applicable law or agreed to in writing, software | |||||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| * See the License for the specific language governing permissions and | |||||
| * limitations under the License. | |||||
| * | |||||
| */ | |||||
| package org.apache.tools.ant.util; | |||||
| import java.io.OutputStream; | |||||
| /** | |||||
| * OutputStream that completely discards all data written to it. | |||||
| * | |||||
| * @since Ant 1.10.10 | |||||
| */ | |||||
| public class NullOutputStream extends OutputStream { | |||||
| /** | |||||
| * Shared instance which is safe to use concurrently as the stream | |||||
| * doesn't hold any state at all. | |||||
| */ | |||||
| public static NullOutputStream INSTANCE = new NullOutputStream(); | |||||
| /** | |||||
| * Doesn't do anything. | |||||
| */ | |||||
| @Override | |||||
| public void write(byte[] b) { } | |||||
| /** | |||||
| * Doesn't do anything. | |||||
| */ | |||||
| @Override | |||||
| public void write(byte[] b, int off, int len) { } | |||||
| /** | |||||
| * Doesn't do anything. | |||||
| */ | |||||
| @Override | |||||
| public void write(int i) { } | |||||
| } | |||||
| @@ -707,4 +707,31 @@ public class Hello { | |||||
| </au:assertTrue> | </au:assertTrue> | ||||
| </target> | </target> | ||||
| <target name="test-discard-output" depends="setUp" if="test.can.run"> | |||||
| <exec executable="sh" discardOutput="true"> | |||||
| <arg value="parrot.sh" /> | |||||
| <arg value="${ant.file}" /> | |||||
| </exec> | |||||
| <au:assertLogDoesntContain text="${ant.file} out" /> | |||||
| <au:assertLogDoesntContain text="${ant.file} err" /> | |||||
| </target> | |||||
| <target name="test-discard-output-only" depends="setUp" if="test.can.run"> | |||||
| <exec executable="sh" discardOutput="true" logError="true"> | |||||
| <arg value="parrot.sh" /> | |||||
| <arg value="${ant.file}" /> | |||||
| </exec> | |||||
| <au:assertLogDoesntContain text="${ant.file} out" /> | |||||
| <au:assertLogContains text="${ant.file} err" /> | |||||
| </target> | |||||
| <target name="test-discard-error" depends="setUp" if="test.can.run"> | |||||
| <exec executable="sh" discardError="true"> | |||||
| <arg value="parrot.sh" /> | |||||
| <arg value="${ant.file}" /> | |||||
| </exec> | |||||
| <au:assertLogContains text="${ant.file} out" /> | |||||
| <au:assertLogDoesntContain text="${ant.file} err" /> | |||||
| </target> | |||||
| </project> | </project> | ||||