From e438a9bf89f863be3d231d0a1a275ca0b8550ed0 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 16 Sep 2008 09:01:21 +0000 Subject: [PATCH] add a fileOnError attribute to . PR 44772. Submitted by Michael Bayne. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@695779 13f79535-47bb-0310-9956-ffa450edef68 --- CONTRIBUTORS | 1 + WHATSNEW | 3 ++ contributors.xml | 4 +++ docs/manual/CoreTasks/patch.html | 7 +++++ .../org/apache/tools/ant/taskdefs/Patch.java | 31 +++++++++++++++++-- 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index e3d01844b..2bdf72f2e 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -187,6 +187,7 @@ Matthew Hawthorne Matthew Inger Matthew Kuperus Heun Matthew Watson +Michael Bayne Michael Davey Michael J. Sikorsky Michael McCallum diff --git a/WHATSNEW b/WHATSNEW index 4c982baa2..9c3925c94 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -353,6 +353,9 @@ Other changes: set. Bugzilla Report 45711. + * has a new optional failOnError attribute. + Bugzilla Report 44772. + Changes from Ant 1.7.0 TO Ant 1.7.1 ============================================= diff --git a/contributors.xml b/contributors.xml index 8f24c7c62..f78b0322d 100644 --- a/contributors.xml +++ b/contributors.xml @@ -772,6 +772,10 @@ Matthew Watson + + Michael + Bayne + Michael Davey diff --git a/docs/manual/CoreTasks/patch.html b/docs/manual/CoreTasks/patch.html index a7beb2ada..9e8a4cf85 100644 --- a/docs/manual/CoreTasks/patch.html +++ b/docs/manual/CoreTasks/patch.html @@ -84,6 +84,13 @@ The directory in which to run the patch command. No, default is the project's basedir. + + failonerror + Stop the buildprocess if the command exits with a + return code signaling failure. Defaults to false. + since Ant 1.8.0 + No +

Examples

  <patch patchfile="module.1.0-1.1.patch"/>
diff --git a/src/main/org/apache/tools/ant/taskdefs/Patch.java b/src/main/org/apache/tools/ant/taskdefs/Patch.java index 47fc11663..d5b7954a9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Patch.java +++ b/src/main/org/apache/tools/ant/taskdefs/Patch.java @@ -40,6 +40,11 @@ public class Patch extends Task { private boolean havePatchfile = false; private Commandline cmd = new Commandline(); + /** + * Halt on error return value from patch invocation. + */ + private boolean failOnError = false; + /** * The file to patch; optional if it can be inferred from * the diff file @@ -142,6 +147,19 @@ public class Patch extends Task { this.directory = directory; } + /** + * If true, stop the build process if the patch command + * exits with an error status. + * @param value true if it should halt, otherwise + * false. The default is false. + * @since Ant 1.8.0 + */ + public void setFailOnError(boolean value) { + failOnError = value; + } + + private static final String PATCH = "patch"; + /** * execute patch * @throws BuildException when it all goes a bit pear shaped @@ -152,7 +170,7 @@ public class Patch extends Task { getLocation()); } Commandline toExecute = (Commandline) cmd.clone(); - toExecute.setExecutable("patch"); + toExecute.setExecutable(PATCH); if (originalFile != null) { toExecute.createArgument().setFile(originalFile); @@ -179,7 +197,16 @@ public class Patch extends Task { log(toExecute.describeCommand(), Project.MSG_VERBOSE); try { - exe.execute(); + int returncode = exe.execute(); + if (Execute.isFailure(returncode)) { + String msg = "'" + PATCH + "' failed with exit code " + + returncode; + if (failOnError) { + throw new BuildException(msg); + } else { + log(msg, Project.MSG_ERR); + } + } } catch (IOException e) { throw new BuildException(e, getLocation()); }