diff --git a/WHATSNEW b/WHATSNEW index 166269275..82fb20035 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -342,6 +342,9 @@ Other changes: For more details see docs/manual/inputhandler.html. +* has a new attribute that selects the directory in which to + run the command. + Changes from Ant 1.4 to Ant 1.4.1 =========================================== diff --git a/docs/manual/CoreTasks/patch.html b/docs/manual/CoreTasks/patch.html index 30621d0b4..12083a6b9 100644 --- a/docs/manual/CoreTasks/patch.html +++ b/docs/manual/CoreTasks/patch.html @@ -55,6 +55,11 @@ slashes from filenames. No + + dir + The directory in which to run the patch command. + No, default is the project's basedir. +

Examples

  <patch patchfile="module.1.0-1.1.patch"/>
@@ -69,7 +74,7 @@ the diff output looked like

the leading a/ will be stripped.
-

Copyright © 2001 Apache Software Foundation. All rights +

Copyright © 2001-2002 Apache Software Foundation. All rights Reserved.

diff --git a/src/main/org/apache/tools/ant/taskdefs/Patch.java b/src/main/org/apache/tools/ant/taskdefs/Patch.java index c54e8fb95..34db7aab2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Patch.java +++ b/src/main/org/apache/tools/ant/taskdefs/Patch.java @@ -73,6 +73,7 @@ import java.io.IOException; public class Patch extends Task { private File originalFile; + private File directory; private boolean havePatchfile = false; private Commandline cmd = new Commandline(); @@ -145,12 +146,21 @@ public class Patch extends Task { } } + /** + * The directory to run the patch command in, defaults to the + * project's base directory. + * + * @since Ant 1.5 + */ + public void setDir(File directory) throws BuildException { + this.directory = directory; + } + public void execute() throws BuildException { if (!havePatchfile) { throw new BuildException("patchfile argument is required", location); } - Commandline toExecute = (Commandline) cmd.clone(); toExecute.setExecutable("patch"); @@ -161,7 +171,21 @@ public class Patch extends Task { Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN), null); - exe.setCommandline(toExecute.getCommandline()); + + if (directory != null) { + if (directory.exists() && directory.isDirectory()) { + exe.setWorkingDirectory(directory); + } else if (!directory.isDirectory()) { + throw new BuildException(directory + " is not a directory.", + location); + } else { + throw new BuildException("directory " + directory + + " doesn\'t exist", location); + } + } else { + exe.setWorkingDirectory(getProject().getBaseDir()); + } + try { exe.execute(); } catch (IOException e) {