Browse Source

New dir attribute for <patch>

Submitted by:	Thanou Thirakul <thanou@intelliware.ca>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272581 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
c1c1f4fcff
3 changed files with 35 additions and 3 deletions
  1. +3
    -0
      WHATSNEW
  2. +6
    -1
      docs/manual/CoreTasks/patch.html
  3. +26
    -2
      src/main/org/apache/tools/ant/taskdefs/Patch.java

+ 3
- 0
WHATSNEW View File

@@ -342,6 +342,9 @@ Other changes:

For more details see docs/manual/inputhandler.html.

* <patch> has a new attribute that selects the directory in which to
run the command.

Changes from Ant 1.4 to Ant 1.4.1
===========================================



+ 6
- 1
docs/manual/CoreTasks/patch.html View File

@@ -55,6 +55,11 @@
slashes from filenames.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">dir</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>
</tr>
</table>
<h3>Examples</h3>
<pre> &lt;patch patchfile=&quot;module.1.0-1.1.patch&quot;/&gt;</pre>
@@ -69,7 +74,7 @@ the diff output looked like</p>
</pre>
the leading <i>a/</i> will be stripped.
<hr>
<p align="center">Copyright &copy; 2001 Apache Software Foundation. All rights
<p align="center">Copyright &copy; 2001-2002 Apache Software Foundation. All rights
Reserved.</p>

</body>


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

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


Loading…
Cancel
Save