- add a quiet attribute to the copy task to not print warning messages Thanks to Timoteo Ohara git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1150331 13f79535-47bb-0310-9956-ffa450edef68master
@@ -341,6 +341,7 @@ Thomas Quas | |||||
Tim Drury | Tim Drury | ||||
Tim Fennell | Tim Fennell | ||||
Tim Stephenson | Tim Stephenson | ||||
Timoteo Ohara | |||||
Timothy Gerard Endres | Timothy Gerard Endres | ||||
Tom Ball | Tom Ball | ||||
Tom Brus | Tom Brus | ||||
@@ -59,6 +59,10 @@ Fixed bugs: | |||||
OutOfMemoryException while unzipping large archives. | OutOfMemoryException while unzipping large archives. | ||||
Bugzilla Report 42969. | Bugzilla Report 42969. | ||||
* quiet attribute added to the copy and move tasks, to be used together | |||||
with failonerror=true, so warnings won't get logged | |||||
Bugzilla Report 48789. | |||||
Other changes: | Other changes: | ||||
-------------- | -------------- | ||||
@@ -1375,6 +1375,10 @@ | |||||
<first>Tim</first> | <first>Tim</first> | ||||
<last>Fennell</last> | <last>Fennell</last> | ||||
</name> | </name> | ||||
<name> | |||||
<first>Timoteo</first> | |||||
<last>Ohara</last> | |||||
</name> | |||||
<name> | <name> | ||||
<first>Timothy</first> | <first>Timothy</first> | ||||
<middle>Gerard</middle> | <middle>Gerard</middle> | ||||
@@ -131,6 +131,15 @@ operation as <a href="../Types/filterset.html">filtersets</a>. | |||||
</td> | </td> | ||||
<td valign="top" align="center">No; defaults to true.</td> | <td valign="top" align="center">No; defaults to true.</td> | ||||
</tr> | </tr> | ||||
<tr> | |||||
<td valign="top">quiet</td> | |||||
<td valign="top">If true and failonerror is false, then do not log a | |||||
warning message when the file to copy does not exist or one of the nested | |||||
filesets points to a directory that doesn't exist or an error occurs | |||||
while copying. <em>since Ant 1.8.3</em>. | |||||
</td> | |||||
<td valign="top" align="center">No; defaults to false.</td> | |||||
</tr> | |||||
<tr> | <tr> | ||||
<td valign="top">verbose</td> | <td valign="top">verbose</td> | ||||
<td valign="top">Log the files that are being copied.</td> | <td valign="top">Log the files that are being copied.</td> | ||||
@@ -121,6 +121,15 @@ there is a directory by the same name in <i>todir</i>, the action will fail. | |||||
</td> | </td> | ||||
<td valign="top" align="center">No; defaults to true.</td> | <td valign="top" align="center">No; defaults to true.</td> | ||||
</tr> | </tr> | ||||
<tr> | |||||
<td valign="top">quiet</td> | |||||
<td valign="top">If true and failonerror is false, then do not log a | |||||
warning message when the file to copy does not exist or one of the nested | |||||
filesets points to a directory that doesn't exist or an error occurs | |||||
while copying. <em>since Ant 1.8.3</em>. | |||||
</td> | |||||
<td valign="top" align="center">No; defaults to false.</td> | |||||
</tr> | |||||
<tr> | <tr> | ||||
<td valign="top">verbose</td> | <td valign="top">verbose</td> | ||||
<td valign="top">Log the files that are being moved.</td> | <td valign="top">Log the files that are being moved.</td> | ||||
@@ -102,6 +102,7 @@ public class Copy extends Task { | |||||
private String outputEncoding = null; | private String outputEncoding = null; | ||||
private long granularity = 0; | private long granularity = 0; | ||||
private boolean force = false; | private boolean force = false; | ||||
private boolean quiet = false; | |||||
// used to store the single non-file resource to copy when the | // used to store the single non-file resource to copy when the | ||||
// tofile attribute has been used | // tofile attribute has been used | ||||
@@ -284,6 +285,18 @@ public class Copy extends Task { | |||||
this.includeEmpty = includeEmpty; | this.includeEmpty = includeEmpty; | ||||
} | } | ||||
/** | |||||
* Set quiet mode. Used to hide messages when a file or directory to be | |||||
* copied does not exist. | |||||
* | |||||
* @param quiet | |||||
* whether or not to display error messages when a file or | |||||
* directory does not exist. Default is false. | |||||
*/ | |||||
public void setQuiet(boolean quiet) { | |||||
this.quiet = quiet; | |||||
} | |||||
/** | /** | ||||
* Set method of handling mappers that return multiple | * Set method of handling mappers that return multiple | ||||
* mappings for a given source path. | * mappings for a given source path. | ||||
@@ -480,7 +493,9 @@ public class Copy extends Task { | |||||
.DOES_NOT_EXIST_POSTFIX)) { | .DOES_NOT_EXIST_POSTFIX)) { | ||||
throw e; | throw e; | ||||
} else { | } else { | ||||
log("Warning: " + getMessage(e), Project.MSG_ERR); | |||||
if (!quiet) { | |||||
log("Warning: " + getMessage(e), Project.MSG_ERR); | |||||
} | |||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
@@ -509,7 +524,9 @@ public class Copy extends Task { | |||||
String message = "Warning: Could not find resource " | String message = "Warning: Could not find resource " | ||||
+ r.toLongString() + " to copy."; | + r.toLongString() + " to copy."; | ||||
if (!failonerror) { | if (!failonerror) { | ||||
log(message, Project.MSG_ERR); | |||||
if (!quiet) { | |||||
log(message, Project.MSG_ERR); | |||||
} | |||||
} else { | } else { | ||||
throw new BuildException(message); | throw new BuildException(message); | ||||
} | } | ||||
@@ -550,7 +567,9 @@ public class Copy extends Task { | |||||
doFileOperations(); | doFileOperations(); | ||||
} catch (BuildException e) { | } catch (BuildException e) { | ||||
if (!failonerror) { | if (!failonerror) { | ||||
log("Warning: " + getMessage(e), Project.MSG_ERR); | |||||
if (!quiet) { | |||||
log("Warning: " + getMessage(e), Project.MSG_ERR); | |||||
} | |||||
} else { | } else { | ||||
throw e; | throw e; | ||||
} | } | ||||
@@ -569,7 +588,9 @@ public class Copy extends Task { | |||||
doResourceOperations(map); | doResourceOperations(map); | ||||
} catch (BuildException e) { | } catch (BuildException e) { | ||||
if (!failonerror) { | if (!failonerror) { | ||||
log("Warning: " + getMessage(e), Project.MSG_ERR); | |||||
if (!quiet) { | |||||
log("Warning: " + getMessage(e), Project.MSG_ERR); | |||||
} | |||||
} else { | } else { | ||||
throw e; | throw e; | ||||
} | } | ||||
@@ -615,7 +636,9 @@ public class Copy extends Task { | |||||
String message = "Warning: Could not find file " | String message = "Warning: Could not find file " | ||||
+ file.getAbsolutePath() + " to copy."; | + file.getAbsolutePath() + " to copy."; | ||||
if (!failonerror) { | if (!failonerror) { | ||||
log(message, Project.MSG_ERR); | |||||
if (!quiet) { | |||||
log(message, Project.MSG_ERR); | |||||
} | |||||
} else { | } else { | ||||
throw new BuildException(message); | throw new BuildException(message); | ||||
} | } | ||||
@@ -241,6 +241,13 @@ public class NullByteStreamResource extends Resource { | |||||
failonerror="false"/> | failonerror="false"/> | ||||
</target> | </target> | ||||
<target name="testQuiet"> | |||||
<mkdir dir="${output}"/> | |||||
<mkdir dir="${input}"/> | |||||
<copy file="${input}/not-there.txt" todir="${output}" failonerror="false" quiet="true" /> | |||||
<au:assertLogDoesntContain text="Could not find file" /> | |||||
</target> | |||||
<target name="testMissingFilesetRoot"> | <target name="testMissingFilesetRoot"> | ||||
<mkdir dir="${output}"/> | <mkdir dir="${output}"/> | ||||
<au:expectfailure expectedMessage="does not exist"> | <au:expectfailure expectedMessage="does not exist"> | ||||