git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267858 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -12,6 +12,10 @@ org.apache.tools.ant to org.apache.tools.ant.types. | |||||
| * the class attribute of <java> has been removed. | * the class attribute of <java> has been removed. | ||||
| * <patch> has lost some of its attributes. | |||||
| * <java> and <cvs> have lost some undocumented attributes. | |||||
| Other changes: | Other changes: | ||||
| -------------- | -------------- | ||||
| @@ -48,4 +52,4 @@ Fixed bugs: | |||||
| respect to the Project's basedir. | respect to the Project's basedir. | ||||
| * Project didn't interpret the basedir attribute correctly in all | * Project didn't interpret the basedir attribute correctly in all | ||||
| cases. | |||||
| cases. | |||||
| @@ -944,7 +944,7 @@ preferred over the <i>checkout</i> command, because of speed.</p> | |||||
| <tr> | <tr> | ||||
| <td valign="top">dest</td> | <td valign="top">dest</td> | ||||
| <td valign="top">the directory where the checked out files should be placed.</td> | <td valign="top">the directory where the checked out files should be placed.</td> | ||||
| <td align="center" valign="top">Yes</td> | |||||
| <td align="center" valign="top">No, default is project's basedir.</td> | |||||
| </tr> | </tr> | ||||
| <tr> | <tr> | ||||
| <td valign="top">package</td> | <td valign="top">package</td> | ||||
| @@ -971,12 +971,6 @@ preferred over the <i>checkout</i> command, because of speed.</p> | |||||
| <td valign="top">report only, don't change any files.</td> | <td valign="top">report only, don't change any files.</td> | ||||
| <td align="center" valign="top">No, default "false"</td> | <td align="center" valign="top">No, default "false"</td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td valign="top">failonerror</td> | |||||
| <td valign="top">Stop the buildprocess if the command exits with a | |||||
| returncode other than 0.</td> | |||||
| <td align="center" valign="top">No</td> | |||||
| </tr> | |||||
| </table> | </table> | ||||
| <h3>Examples</h3> | <h3>Examples</h3> | ||||
| <pre> <cvs cvsRoot=":pserver:anoncvs@jakarta.apache.org:/home/cvspublic" | <pre> <cvs cvsRoot=":pserver:anoncvs@jakarta.apache.org:/home/cvspublic" | ||||
| @@ -2362,23 +2356,6 @@ necessary.</p> | |||||
| <td valign="top"><b>Description</b></td> | <td valign="top"><b>Description</b></td> | ||||
| <td align="center" valign="top"><b>Required</b></td> | <td align="center" valign="top"><b>Required</b></td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td valign="top">dir</td> | |||||
| <td valign="top">the directory in which the command should be executed.</td> | |||||
| <td align="center" valign="top">Yes</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">os</td> | |||||
| <td valign="top">list of Operating Systems on which the command may be | |||||
| executed.</td> | |||||
| <td align="center" valign="top">No</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">output</td> | |||||
| <td valign="top">the file to which the output of the patch command | |||||
| should be redirected.</td> | |||||
| <td align="center" valign="top">No</td> | |||||
| </tr> | |||||
| <tr> | <tr> | ||||
| <td valign="top">patchfile</td> | <td valign="top">patchfile</td> | ||||
| <td valign="top">the file that includes the diff output</td> | <td valign="top">the file that includes the diff output</td> | ||||
| @@ -2417,12 +2394,6 @@ necessary.</p> | |||||
| slashes from filenames.</td> | slashes from filenames.</td> | ||||
| <td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td valign="top">failonerror</td> | |||||
| <td valign="top">Stop the buildprocess if the command exits with a | |||||
| returncode other than 0.</td> | |||||
| <td align="center" valign="top">No</td> | |||||
| </tr> | |||||
| </table> | </table> | ||||
| <h3>Examples</h3> | <h3>Examples</h3> | ||||
| <pre> <patch patchfile="module.1.0-1.1.patch" /></pre> | <pre> <patch patchfile="module.1.0-1.1.patch" /></pre> | ||||
| @@ -55,6 +55,7 @@ | |||||
| package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
| import org.apache.tools.ant.*; | import org.apache.tools.ant.*; | ||||
| import org.apache.tools.ant.types.Commandline; | |||||
| import java.io.*; | import java.io.*; | ||||
| /** | /** | ||||
| @@ -65,42 +66,58 @@ import java.io.*; | |||||
| * @author Wolfgang Werner <a href="mailto:wwerner@picturesafe.de">wwerner@picturesafe.de</a> | * @author Wolfgang Werner <a href="mailto:wwerner@picturesafe.de">wwerner@picturesafe.de</a> | ||||
| */ | */ | ||||
| public class Cvs extends Exec { | |||||
| public class Cvs extends Task { | |||||
| private Commandline cmd = new Commandline(); | |||||
| private String cvsRoot; | private String cvsRoot; | ||||
| private String pack; | private String pack; | ||||
| private String tag; | |||||
| private String date; | |||||
| private String command = "checkout"; | private String command = "checkout"; | ||||
| private boolean quiet = false; | private boolean quiet = false; | ||||
| private boolean noexec = false; | private boolean noexec = false; | ||||
| private File dest; | |||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| // XXX: we should use JCVS (www.ice.com/JCVS) instead of command line | // 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) | // 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) { | 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) { | 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) { | public void setCvsRoot(String root) { | ||||
| @@ -113,8 +130,8 @@ public class Cvs extends Exec { | |||||
| this.cvsRoot = root; | this.cvsRoot = root; | ||||
| } | } | ||||
| public void setDest(String dest) { | |||||
| setDir(dest); | |||||
| public void setDest(File dest) { | |||||
| this.dest = dest; | |||||
| } | } | ||||
| public void setPackage(String p) { | public void setPackage(String p) { | ||||
| @@ -123,19 +140,18 @@ public class Cvs extends Exec { | |||||
| public void setTag(String p) { | public void setTag(String p) { | ||||
| // Check if not real tag => set it to null | // 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) { | 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) { | public void setCommand(String c) { | ||||
| @@ -55,22 +55,20 @@ | |||||
| package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
| import org.apache.tools.ant.*; | import org.apache.tools.ant.*; | ||||
| import org.apache.tools.ant.types.Commandline; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.io.IOException; | |||||
| /** | /** | ||||
| * Task as a layer on top of patch. Patch applies a diff file to an original. | * Task as a layer on top of patch. Patch applies a diff file to an original. | ||||
| * | * | ||||
| * @author Stefan Bodewig <a href="mailto:stefan.bodewig@megabit.net">stefan.bodewig@megabit.net</a> | |||||
| * @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a> | |||||
| */ | */ | ||||
| public class Patch extends Exec { | |||||
| public class Patch extends Task { | |||||
| private File originalFile; | 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. | * The file to patch. | ||||
| @@ -83,21 +81,31 @@ public class Patch extends Exec { | |||||
| * The file containing the diff output. | * The file containing the diff output. | ||||
| */ | */ | ||||
| public void setPatchfile(File file) { | 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. | * Shall patch write backups. | ||||
| */ | */ | ||||
| public void setBackups(boolean backups) { | public void setBackups(boolean backups) { | ||||
| backup = backups; | |||||
| if (backups) { | |||||
| cmd.addValue("-b"); | |||||
| } | |||||
| } | } | ||||
| /** | /** | ||||
| * Ignore whitespace differences. | * Ignore whitespace differences. | ||||
| */ | */ | ||||
| public void setIgnorewhitespace(boolean ignore) { | public void setIgnorewhitespace(boolean ignore) { | ||||
| ignoreWhitespace = ignore; | |||||
| if (ignore) { | |||||
| cmd.addValue("-l"); | |||||
| } | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -110,65 +118,48 @@ public class Patch extends Exec { | |||||
| if (num < 0) { | if (num < 0) { | ||||
| throw new BuildException("strip has to be >= 0", location); | throw new BuildException("strip has to be >= 0", location); | ||||
| } | } | ||||
| strip = num; | |||||
| cmd.addValue("-p"+num); | |||||
| } | } | ||||
| /** | /** | ||||
| * Work silently unless an error occurs. | * Work silently unless an error occurs. | ||||
| */ | */ | ||||
| public void setQuiet(boolean q) { | public void setQuiet(boolean q) { | ||||
| quiet = q; | |||||
| if (q) { | |||||
| cmd.addValue("-s"); | |||||
| } | |||||
| } | } | ||||
| /** | /** | ||||
| * Assume patch was created with old and new files swapped. | * Assume patch was created with old and new files swapped. | ||||
| */ | */ | ||||
| public void setReverse(boolean r) { | 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 { | public void execute() throws BuildException { | ||||
| if (patchFile == null) { | |||||
| if (!havePatchfile) { | |||||
| throw new BuildException("patchfile argument is required", | throw new BuildException("patchfile argument is required", | ||||
| location); | 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) { | 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 | }// Patch | ||||