diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 28eb009d1..643e5e07c 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -241,6 +241,7 @@ Stephen Goetze Steve Cohen Steve Loughran Steve Morin +Steve Wadsworth Steven E. Newton Takashi Okamoto Taoufik Romdhane diff --git a/WHATSNEW b/WHATSNEW index 32ef229b9..fe809e29c 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -29,6 +29,9 @@ Other changes: * add dtd to javadoc for junit. Bugzilla 40754. +* add quiet attribute to loadfile/resource. + Bugzilla 38249. + Changes from Ant 1.7.0Beta3 to Ant 1.7.0RC1 =========================================== diff --git a/contributors.xml b/contributors.xml index 8ee588813..0824884c9 100644 --- a/contributors.xml +++ b/contributors.xml @@ -960,6 +960,10 @@ Steve Morin + + Steve + Wadsworth + Steven E. diff --git a/docs/manual/CoreTasks/loadfile.html b/docs/manual/CoreTasks/loadfile.html index 711045a3f..97c12a195 100644 --- a/docs/manual/CoreTasks/loadfile.html +++ b/docs/manual/CoreTasks/loadfile.html @@ -59,6 +59,17 @@ current locale is used. Whether to halt the build on failure No, default "true" + + quiet + Do not display a diagnostic message (unless Ant has been + invoked with the -verbose or -debug + switches) or modify the exit status to reflect an error. Setting this to + "true" implies setting failonerror to "false". + Since Ant 1.7.0. + + No, default "false" + +

The LoadFile task supports nested diff --git a/docs/manual/CoreTasks/loadresource.html b/docs/manual/CoreTasks/loadresource.html index 627bc77ea..033d3ad4a 100755 --- a/docs/manual/CoreTasks/loadresource.html +++ b/docs/manual/CoreTasks/loadresource.html @@ -58,6 +58,15 @@ element resource collections. Whether to halt the build on failure No, default "true" + + quiet + Do not display a diagnostic message (unless Ant has been + invoked with the -verbose or -debug + switches) or modify the exit status to reflect an error. Setting this to + "true" implies setting failonerror to "false". + + No, default "false" +

The LoadResource task supports nested diff --git a/src/main/org/apache/tools/ant/taskdefs/LoadResource.java b/src/main/org/apache/tools/ant/taskdefs/LoadResource.java index dd2b68647..500b857a6 100755 --- a/src/main/org/apache/tools/ant/taskdefs/LoadResource.java +++ b/src/main/org/apache/tools/ant/taskdefs/LoadResource.java @@ -50,6 +50,12 @@ public class LoadResource extends Task { */ private boolean failOnError = true; + /** + * suppress error message if it goes pear-shaped, sets failOnError=false + */ + private boolean quiet = false; + + /** * Encoding to use for filenames, defaults to the platform's default * encoding. @@ -100,7 +106,18 @@ public class LoadResource extends Task { public final void setFailonerror(final boolean fail) { failOnError = fail; } - + + /** + * If true, suppress the load error report and set the + * the failonerror value to true. + * @param quiet The new Quiet value + */ + public void setQuiet(final boolean quiet) { + this.quiet = quiet; + if (quiet) { + this.failOnError = false; + } + } /** * read in a source file to a property @@ -116,12 +133,16 @@ public class LoadResource extends Task { if (property == null) { throw new BuildException("output property not defined"); } + if (quiet && failOnError) { + throw new BuildException("quiet and failonerror cannot both be " + + "set to true"); + } if (!src.isExists()) { String message = src + " doesn't exist"; if (failOnError) { throw new BuildException(message); } else { - log(message, Project.MSG_ERR); + log(message, quiet ? Project.MSG_WARN : Project.MSG_ERR); return; } } @@ -175,13 +196,14 @@ public class LoadResource extends Task { if (failOnError) { throw new BuildException(message, ioe, getLocation()); } else { - log(message, Project.MSG_ERR); + log(message, quiet ? Project.MSG_VERBOSE : Project.MSG_ERR); } } catch (final BuildException be) { if (failOnError) { throw be; } else { - log(be.getMessage(), Project.MSG_ERR); + log(be.getMessage(), + quiet ? Project.MSG_VERBOSE : Project.MSG_ERR); } } finally { FileUtils.close(is);