Browse Source

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 <spierre@rational.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267743 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
5ddfc9ea91
2 changed files with 40 additions and 1 deletions
  1. +30
    -0
      docs/index.html
  2. +10
    -1
      src/main/org/apache/tools/ant/taskdefs/Exec.java

+ 30
- 0
docs/index.html View File

@@ -900,6 +900,12 @@ preferred over the <i>checkout</i> command, because of speed.</p>
<td valign="top">report only, don't change any files.</td>
<td align="center" valign="top">No, default &quot;false&quot;</td>
</tr>
<tr>
<td valign="top">failonerror</td>
<td valign="top">Stop the buildprocess if the command exits with a
returncode other than 0.</td>
<td align="center" valign="top">No</td>
</tr>
</table>
<h3>Examples</h3>
<pre> &lt;cvs cvsRoot=&quot;:pserver:anoncvs@jakarta.apache.org:/home/cvspublic&quot;
@@ -1067,6 +1073,12 @@ systems.</p>
redirected.</td>
<td align="center" valign="top">Yes</td>
</tr>
<tr>
<td valign="top">failonerror</td>
<td valign="top">Stop the buildprocess if the command exits with a
returncode other than 0.</td>
<td align="center" valign="top">No</td>
</tr>
</table>
<h3>Examples</h3>
<blockquote>
@@ -1569,6 +1581,12 @@ the one that is currently running Ant.</p>
disabled)</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">failonerror</td>
<td valign="top">Stop the buildprocess if the command exits with a
returncode other than 0. Only available if fork is true.</td>
<td align="center" valign="top">No</td>
</tr>
</table>
<h3>Examples</h3>
<pre> &lt;java classname=&quot;test.Main&quot; /&gt;</pre>
@@ -2077,6 +2095,12 @@ instead.</p>
<td align="center" valign="top">1.2</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">failonerror</td>
<td valign="top">Stop the buildprocess if the command exits with a
returncode other than 0.</td>
<td align="center" valign="top">No</td>
</tr>
</table>

<h3>Parameters specified as nested elements</h3>
@@ -2284,6 +2308,12 @@ necessary.</p>
slashes from filenames.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">failonerror</td>
<td valign="top">Stop the buildprocess if the command exits with a
returncode other than 0.</td>
<td align="center" valign="top">No</td>
</tr>
</table>
<h3>Examples</h3>
<pre> &lt;patch patchfile=&quot;module.1.0-1.1.patch&quot; /&gt;</pre>


+ 10
- 1
src/main/org/apache/tools/ant/taskdefs/Exec.java View File

@@ -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);


Loading…
Cancel
Save