From 5ddfc9ea915a39428fe1c7f01ee7a4e265123a68 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 7 Jul 2000 11:24:00 +0000 Subject: [PATCH] Added failonerror attribute to Exec. If this attribute is set to true, a BuildException will be thrown effectively ending the build process. Suggested by: Sebastien Pierre git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267743 13f79535-47bb-0310-9956-ffa450edef68 --- docs/index.html | 30 +++++++++++++++++++ .../org/apache/tools/ant/taskdefs/Exec.java | 11 ++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/docs/index.html b/docs/index.html index 51629d8e1..bb66caa97 100644 --- a/docs/index.html +++ b/docs/index.html @@ -900,6 +900,12 @@ preferred over the checkout command, because of speed.

report only, don't change any files. No, default "false" + + failonerror + Stop the buildprocess if the command exits with a + returncode other than 0. + No +

Examples

  <cvs cvsRoot=":pserver:anoncvs@jakarta.apache.org:/home/cvspublic"
@@ -1067,6 +1073,12 @@ systems.

redirected. Yes + + failonerror + Stop the buildprocess if the command exits with a + returncode other than 0. + No +

Examples

@@ -1569,6 +1581,12 @@ the one that is currently running Ant.

disabled) No + + failonerror + Stop the buildprocess if the command exits with a + returncode other than 0. Only available if fork is true. + No +

Examples

  <java classname="test.Main" />
@@ -2077,6 +2095,12 @@ instead.

1.2 No + + failonerror + Stop the buildprocess if the command exits with a + returncode other than 0. + No +

Parameters specified as nested elements

@@ -2284,6 +2308,12 @@ necessary.

slashes from filenames. No + + failonerror + Stop the buildprocess if the command exits with a + returncode other than 0. + No +

Examples

  <patch patchfile="module.1.0-1.1.patch" />
diff --git a/src/main/org/apache/tools/ant/taskdefs/Exec.java b/src/main/org/apache/tools/ant/taskdefs/Exec.java index af1629e25..7e1c69909 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Exec.java +++ b/src/main/org/apache/tools/ant/taskdefs/Exec.java @@ -70,6 +70,7 @@ public class Exec extends Task { private File dir; private String command; protected PrintWriter fos = null; + private boolean failOnError = false; private static final int BUFFER_SIZE = 512; @@ -138,7 +139,11 @@ public class Exec extends Task { // check its exit value err = proc.exitValue(); if (err != 0) { - log("Result: " + err, Project.MSG_ERR); + if (failOnError) { + throw new BuildException("Exec returned: "+err, location); + } else { + log("Result: " + err, Project.MSG_ERR); + } } } catch (IOException ioe) { throw new BuildException("Error exec: " + command, ioe, location); @@ -163,6 +168,10 @@ public class Exec extends Task { this.out = out; } + public void setFailonerror(String fail) { + failOnError = Project.toBoolean(fail); + } + protected void outputLog(String line, int messageLevel) { if (fos == null) { log(line, messageLevel);