From 6035bbf18dc7df5472368d91d69de03b1819c800 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
<cvs cvsRoot=":pserver:anoncvs@jakarta.apache.org:/home/cvspublic"
@@ -2362,23 +2356,6 @@ necessary.
Description
Required
-
- dir
- the directory in which the command should be executed.
- Yes
-
-
- os
- list of Operating Systems on which the command may be
- executed.
- No
-
-
- output
- the file to which the output of the patch command
- should be redirected.
- No
-
patchfile
the file that includes the diff output
@@ -2417,12 +2394,6 @@ necessary.
slashes from filenames.
No
-
- failonerror
- Stop the buildprocess if the command exits with a
- returncode other than 0.
- No
-
Examples
<patch patchfile="module.1.0-1.1.patch" />
diff --git a/src/main/org/apache/tools/ant/taskdefs/Cvs.java b/src/main/org/apache/tools/ant/taskdefs/Cvs.java
index 32f1e070b..f340dceff 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Cvs.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Cvs.java
@@ -55,6 +55,7 @@
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.*;
+import org.apache.tools.ant.types.Commandline;
import java.io.*;
/**
@@ -65,42 +66,58 @@ import java.io.*;
* @author Wolfgang Werner wwerner@picturesafe.de
*/
-public class Cvs extends Exec {
+public class Cvs extends Task {
+ private Commandline cmd = new Commandline();
private String cvsRoot;
private String pack;
- private String tag;
- private String date;
private String command = "checkout";
private boolean quiet = false;
private boolean noexec = false;
+ private File dest;
public void execute() throws BuildException {
// XXX: we should use JCVS (www.ice.com/JCVS) instead of command line
// execution so that we don't rely on having native CVS stuff around (SM)
+
+ // We can't do it ourselves as jCVS is GPLed, a third party task
+ // outside of jakarta repositories would be possible though (SB).
- StringBuffer sb=new StringBuffer();
- sb.append(" cvs ");
+ Commandline toExecute = new Commandline();
+
+ toExecute.setExecutable("cvs");
if (cvsRoot != null) {
- sb.append("-d ").append(cvsRoot).append(" ");
+ toExecute.addValue("-d");
+ toExecute.addValue(cvsRoot);
}
-
- sb.append(noexec ? "-n " : "")
- .append(quiet ? "-q " : "")
- .append(command).append(" ");
-
- if (tag!=null)
- sb.append("-r ").append(tag).append(" ");
-
- if (date!=null)
- sb.append("-D ").append(date).append(" ");
+ if (noexec) {
+ toExecute.addValue("-n");
+ }
+ if (quiet) {
+ toExecute.addValue("-q");
+ }
+ toExecute.addValue(command);
+ toExecute.addLine(cmd.getCommandline());
if (pack != null) {
- sb.append(pack);
+ toExecute.addValue(pack);
}
- run(sb.toString());
+ Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
+ Project.MSG_WARN),
+ null);
+
+ exe.setAntRun(project);
+ if (dest == null) dest = project.getBaseDir();
+ exe.setWorkingDirectory(dest);
+
+ exe.setCommandline(toExecute.getCommandline());
+ try {
+ exe.execute();
+ } catch (IOException e) {
+ throw new BuildException(e, location);
+ }
}
public void setCvsRoot(String root) {
@@ -113,8 +130,8 @@ public class Cvs extends Exec {
this.cvsRoot = root;
}
- public void setDest(String dest) {
- setDir(dest);
+ public void setDest(File dest) {
+ this.dest = dest;
}
public void setPackage(String p) {
@@ -123,19 +140,18 @@ public class Cvs extends Exec {
public void setTag(String p) {
// Check if not real tag => set it to null
- if (p != null) {
- if (p.trim().equals(""))
- p = null;
- }
-
- this.tag = p;
+ if (p != null && p.trim().length() > 0) {
+ cmd.addValue("-r");
+ cmd.addValue(p);
+ }
}
public void setDate(String p) {
- if( p != null && p.trim().length()==0 )
- p = null;
- this.date = p;
+ if(p != null && p.trim().length() > 0) {
+ cmd.addValue("-D");
+ cmd.addValue(p);
+ }
}
public void setCommand(String c) {
diff --git a/src/main/org/apache/tools/ant/taskdefs/Patch.java b/src/main/org/apache/tools/ant/taskdefs/Patch.java
index a2e8df5c2..c31487f6d 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Patch.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Patch.java
@@ -55,22 +55,20 @@
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.*;
+import org.apache.tools.ant.types.Commandline;
import java.io.File;
+import java.io.IOException;
/**
* Task as a layer on top of patch. Patch applies a diff file to an original.
*
- * @author Stefan Bodewig stefan.bodewig@megabit.net
+ * @author Stefan Bodewig
*/
-public class Patch extends Exec {
+public class Patch extends Task {
private File originalFile;
- private File patchFile;
- private boolean backup = false;
- private boolean ignoreWhitespace = false;
- private int strip = -1;
- private boolean quiet = false;
- private boolean reverse = false;
+ private boolean havePatchfile = false;
+ private Commandline cmd = new Commandline();
/**
* The file to patch.
@@ -83,21 +81,31 @@ public class Patch extends Exec {
* The file containing the diff output.
*/
public void setPatchfile(File file) {
- patchFile = file;
+ if (!file.exists()) {
+ throw new BuildException("patchfile "+file+" doesn\'t exist",
+ location);
+ }
+ cmd.addValue("-i");
+ cmd.addValue(file.getAbsolutePath());
+ havePatchfile = true;
}
/**
* Shall patch write backups.
*/
public void setBackups(boolean backups) {
- backup = backups;
+ if (backups) {
+ cmd.addValue("-b");
+ }
}
/**
* Ignore whitespace differences.
*/
public void setIgnorewhitespace(boolean ignore) {
- ignoreWhitespace = ignore;
+ if (ignore) {
+ cmd.addValue("-l");
+ }
}
/**
@@ -110,65 +118,48 @@ public class Patch extends Exec {
if (num < 0) {
throw new BuildException("strip has to be >= 0", location);
}
- strip = num;
+ cmd.addValue("-p"+num);
}
/**
* Work silently unless an error occurs.
*/
public void setQuiet(boolean q) {
- quiet = q;
+ if (q) {
+ cmd.addValue("-s");
+ }
}
/**
* Assume patch was created with old and new files swapped.
*/
public void setReverse(boolean r) {
- reverse = r;
- }
-
- public final void setCommand(String command) throws BuildException {
- throw new BuildException("Cannot set attribute command in patch task",
- location);
+ if (r) {
+ cmd.addValue("-R");
+ }
}
public void execute() throws BuildException {
- if (patchFile == null) {
+ if (!havePatchfile) {
throw new BuildException("patchfile argument is required",
location);
}
- if (!patchFile.exists()) {
- throw new BuildException("patchfile "+patchFile+" doesn\'t exist",
- location);
- }
- StringBuffer command = new StringBuffer("patch -i "+patchFile+" ");
+ cmd.setExecutable("patch");
- if (backup) {
- command.append("-b ");
- }
-
- if (ignoreWhitespace) {
- command.append("-l ");
- }
-
- if (strip >= 0) {
- command.append("-p"+strip+" ");
- }
-
- if (quiet) {
- command.append("-s ");
- }
-
- if (reverse) {
- command.append("-R ");
- }
-
if (originalFile != null) {
- command.append(originalFile);
- }
+ cmd.addValue(originalFile.getAbsolutePath());
+ }
- run(command.toString());
+ Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
+ Project.MSG_WARN),
+ null);
+ exe.setCommandline(cmd.getCommandline());
+ try {
+ exe.execute();
+ } catch (IOException e) {
+ throw new BuildException(e, location);
+ }
}
}// Patch