diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java b/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java index 524568cd38..aca6d1ac68 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java @@ -75,7 +75,8 @@ * match="pattern" * replace="pattern" * flags="options"? - * byline="true|false"? > + * byline="true|false"? + * failOnError="true|false"? > * regexp? * substitution? * fileset* @@ -101,6 +102,10 @@ * "true" indicates to perform replacement on a line by line basis * "false" indicates to perform replacement on the whole file at once. * + * failOnError --> Should this task fail if an error occurs (default is false) + * "true" indicates that this task should fail if an error occurs + * "false" indicates that this task should continue if an error occurs + * * Example: * * The following call could be used to replace an old property name in a ".properties" @@ -123,6 +128,7 @@ public class ReplaceRegExp extends Task { private Union resources; private RegularExpression regex; private Substitution subs; + private boolean failonerror = false; private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); @@ -315,6 +321,15 @@ public void setPreserveLastModified(boolean b) { preserveLastModified = b; } + /** + * If false, note errors but continue. + * + * @param failonerror true or false + */ + public void setFailOnError(boolean failonerror) { + this.failonerror = failonerror; + } + /** * Invoke a regular expression (r) on a string (input) using * substitutions (s) for a matching regex. @@ -481,13 +496,17 @@ public void execute() throws BuildException { log("An error occurred processing file: '" + file.getAbsolutePath() + "': " + e.toString(), Project.MSG_ERR); - throw new BuildException("An error occurred processing file: '" + file.getAbsolutePath() + "'", - e, getLocation()); + if (failonerror) { + throw new BuildException("An error occurred processing file: '" + file.getAbsolutePath() + "'", + e, getLocation()); + } } } else if (file != null) { log("The following file is missing: '" + file.getAbsolutePath() + "'", Project.MSG_ERR); - throw new BuildException("The following file is missing: '" + file.getAbsolutePath() + "'"); + if (failonerror) { + throw new BuildException("The following file is missing: '" + file.getAbsolutePath() + "'"); + } } if (resources != null) { @@ -501,13 +520,17 @@ public void execute() throws BuildException { log("An error occurred processing file: '" + f.getAbsolutePath() + "': " + e.toString(), Project.MSG_ERR); - throw new BuildException("An error occurred processing file: '" + f.getAbsolutePath() + "'", - e, getLocation()); + if (failonerror) { + throw new BuildException("An error occurred processing file: '" + f.getAbsolutePath() + "'", + e, getLocation()); + } } } else { log("The following file is missing: '" + f.getAbsolutePath() + "'", Project.MSG_ERR); - throw new BuildException("The following file is missing: '" + f.getAbsolutePath() + "'"); + if (failonerror) { + throw new BuildException("The following file is missing: '" + f.getAbsolutePath() + "'"); + } } } }