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 17 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 Inger
Matthew Kuperus Heun Matthew Kuperus Heun
Matthew Watson Matthew Watson
Michael Bayne
Michael Davey Michael Davey
Michael J. Sikorsky Michael J. Sikorsky
Michael McCallum Michael McCallum


+ 3
- 0
WHATSNEW View File

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


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

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




+ 4
- 0
contributors.xml View File

@@ -772,6 +772,10 @@
<first>Matthew</first> <first>Matthew</first>
<last>Watson</last> <last>Watson</last>
</name> </name>
<name>
<first>Michael</first>
<last>Bayne</last>
</name>
<name> <name>
<first>Michael</first> <first>Michael</first>
<last>Davey</last> <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 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> <td align="center" valign="top">No, default is the project's basedir.</td>
</tr> </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> </table>
<h3>Examples</h3> <h3>Examples</h3>
<pre> &lt;patch patchfile=&quot;module.1.0-1.1.patch&quot;/&gt;</pre> <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 boolean havePatchfile = false;
private Commandline cmd = new Commandline(); 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 file to patch; optional if it can be inferred from
* the diff file * the diff file
@@ -142,6 +147,19 @@ public class Patch extends Task {
this.directory = directory; 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 * execute patch
* @throws BuildException when it all goes a bit pear shaped * @throws BuildException when it all goes a bit pear shaped
@@ -152,7 +170,7 @@ public class Patch extends Task {
getLocation()); getLocation());
} }
Commandline toExecute = (Commandline) cmd.clone(); Commandline toExecute = (Commandline) cmd.clone();
toExecute.setExecutable("patch");
toExecute.setExecutable(PATCH);


if (originalFile != null) { if (originalFile != null) {
toExecute.createArgument().setFile(originalFile); toExecute.createArgument().setFile(originalFile);
@@ -179,7 +197,16 @@ public class Patch extends Task {


log(toExecute.describeCommand(), Project.MSG_VERBOSE); log(toExecute.describeCommand(), Project.MSG_VERBOSE);
try { 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) { } catch (IOException e) {
throw new BuildException(e, getLocation()); throw new BuildException(e, getLocation());
} }


Loading…
Cancel
Save