Browse Source

add a fileOnError attribute to <patch>. PR 44772. Submitted by Michael Bayne.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@695779 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
e438a9bf89
5 changed files with 44 additions and 2 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +3
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +7
    -0
      docs/manual/CoreTasks/patch.html
  5. +29
    -2
      src/main/org/apache/tools/ant/taskdefs/Patch.java

+ 1
- 0
CONTRIBUTORS View File

@@ -187,6 +187,7 @@ Matthew Hawthorne
Matthew Inger
Matthew Kuperus Heun
Matthew Watson
Michael Bayne
Michael Davey
Michael J. Sikorsky
Michael McCallum


+ 3
- 0
WHATSNEW View File

@@ -353,6 +353,9 @@ Other changes:
set.
Bugzilla Report 45711.

* <patch> has a new optional failOnError attribute.
Bugzilla Report 44772.

Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================



+ 4
- 0
contributors.xml View File

@@ -772,6 +772,10 @@
<first>Matthew</first>
<last>Watson</last>
</name>
<name>
<first>Michael</first>
<last>Bayne</last>
</name>
<name>
<first>Michael</first>
<last>Davey</last>


+ 7
- 0
docs/manual/CoreTasks/patch.html View File

@@ -84,6 +84,13 @@
<td valign="top">The directory in which to run the patch command.</td>
<td align="center" valign="top">No, default is the project's basedir.</td>
</tr>
<tr>
<td valign="top">failonerror</td>
<td valign="top">Stop the buildprocess if the command exits with a
return code signaling failure. Defaults to false.
<em>since Ant 1.8.0</em></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>


+ 29
- 2
src/main/org/apache/tools/ant/taskdefs/Patch.java View File

@@ -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 <code>true</code>, stop the build process if the patch command
* exits with an error status.
* @param value <code>true</code> if it should halt, otherwise
* <code>false</code>. The default is <code>false</code>.
* @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());
}


Loading…
Cancel
Save