diff --git a/docs/index.html b/docs/index.html index b3b8b945c..1888a91e6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -846,6 +846,7 @@ same patterns as the example before.
id
other.shared.sources
get the same
permissions.
Copies a file or directory to a new file or directory. Files are +only copied if the source file is newer than the destination file, +or when the destination file does not exist. However, you can explicitly +overwrite files with the overwrite attribute.
+FileSets are used to select files to copy. +To use a fileset, the todir attribute must be set.
+Attribute | +Description | +Required | +
file | +the file to copy | +One of file or + dir are required, or at least one nested fileset element. | +
dir | +the directory to copy | +|
tofile | +the file to copy to | +With the file attribute, + either tofile or todir can be used. With the dir + attribute and nested filesets, only todir is allowed. | +
todir | +the directory to copy to | +|
overwrite | +overwrite existing files even if the destination + files are newer (default is no) | +No | +
filtering | +indicates whether token filtering should take place during + the copy (default is no) | +No | +
flatten | +ignore directory structure of source directory, + copy all files into a single directory, specified by the todir + attribute (default is false) | +No | +
Copy a single file
++ <copy file="myfile.txt" tofile="mycopy.txt" /> ++
Copy a file to a directory
++ <copy file="myfile.txt" todir="../some/dir/tree" /> ++
Copy a directory to another directory
++ <copy dir="src_dir" todir="../new/dir" /> ++
Copy a set of files to a directory
++ <copy todir="../dest/dir" > + <fileset dir="src_dir" > + <exclude name="**/*.java" /> + </fileset> + </copy> + + <copy todir="../dest/dir" > + <fileset dir="src_dir" excludes="**/*.java" /> + </copy> ++
This task has been deprecated. Use the Copy task instead.
Copies a directory tree from the source to the destination.
It is possible to refine the set of files that are being copied. This can be
@@ -1277,6 +1363,8 @@ recursively. All java files are copied, except for the files under the myp
directory.
This task has been deprecated. Use the Copy task instead.
Copies a file from the source to the destination. The file is only copied if the source file is newer than the destination file, or when the destination file @@ -1396,21 +1484,9 @@ repository pointed to by the cvsRoot attribute, and stores the files in "${
Deletes either a single file or -all files in a specified directory and its sub-directories.
-It is possible to refine the set of files that are being deleted. This can be -done with the includes, includesfile, excludes, excludesfile and defaultexcludes -attributes. With the includes or includesfile attribute you specify the files you want to -have included in the deletion process by using patterns. The exclude or excludesfile attribute is used to specify -the files you want to have excluded from the deletion process. This is also done with patterns. And -finally with the defaultexcludes attribute, you can specify whether you -want to use default exclusions or not. See the section on directory based tasks, on how the -inclusion/exclusion of files works, and how to write patterns.
-This task forms an implicit FileSet and
-supports all attributes of <fileset>
as well as the
-nested <include>
, <exclude>
and
-<patternset>
elements.
Deletes either a single file, all files in a specified directory and its +sub-directories, or a set of files specified by one or more FileSets. +When specifying a set of files, empty directories are not removed.
dir | The directory to delete files from. | ||
verbose | +Show name of each deleted file ("true"/"false"). + Default is "false" when omitted. | +No | +|
includes | -Comma separated list of patterns of files that must be + | Deprecated. Comma separated list of patterns of files that must be deleted. All files are in the current directory and any sub-directories are deleted when omitted. | No |
includesfile | -the name of a file. Each line of this file is + | Deprecated. The name of a file. Each line of this file is taken to be an include pattern | No |
excludes | -Comma separated list of patterns of files that must be + | Deprecated. Comma separated list of patterns of files that must be excluded from the deletion list. No files (except default excludes) are excluded when omitted. | No |
excludesfile | -the name of a file. Each line of this file is + | Deprecated. The name of a file. Each line of this file is taken to be an exclude pattern | No |
defaultexcludes | -Indicates whether default excludes should be used or not + | Deprecated. Indicates whether default excludes should be used or not ("yes"/"no"). Default excludes are used when omitted. | No |
verbose | -Show name of each deleted file ("true"/"false"). - Default is "false" when omitted. | -No | -
<delete file="/lib/ant.jar" />
deletes the file /lib/ant.jar
.
<delete dir="lib" />
deletes all files in the /lib
directory.
<delete dir="." - includes="**/*.bak" - /> +<delete> + <fileset dir="." includes="**/*.bak" /> + </delete>deletes all files with the extension "
.bak
" from the current directory and any sub-directories.
Deltree
+Deprecated
+This task has been deprecated. Use the Delete task instead.
Description
Deletes a directory with all its files and subdirectories.
Parameters
@@ -3135,6 +3213,88 @@ necessary.<mkdir dir="${dist}/lib" />creates a directory
${dist}/lib
.
+Move
+Description
+Moves a file or directory to a new file or directory, or sets of files to +a new directory. By default, the +destination file is overwritten if it already exists. When overwrite is +turned off, then files are only moved if the source file is newer than +the destination file, or when the destination file does not exist.
+FileSets are used to select sets of files +to move to the todir directory.
+Parameters
+
Attribute | +Description | +Required | +
file | +the file to move | +One of file or + dir are required, or at least one nested fileset element | +
dir | +the directory to move | +|
tofile | +the file to move to | +With the file attribute, + either tofile or todir can be used. With the dir + attribute or a nested fileset, only todir is allowed. | +
todir | +the directory to move to | +|
overwrite | +overwrite existing files even if the destination + files are newer (default is "true") | +No | +
filtering | +indicates whether token filtering should take place during + the move. See the filter task for a description of + how filters work. | +No | +
flatten | +ignore directory structure of source directory, + copy all files into a single directory, specified by the todir + attribute (default is "false"). | +No | +
Move a single file (rename a file)
++ <move file="file.orig" tofile="file.moved" /> ++
Move a single file to a directory
++ <move file="file.orig" todir="dir/to/move/to" /> ++
Move a directory to a new directory
++ <move dir="src/dir" todir="new/dir/to/move/to" /> ++
Note that the directory src/dir will be removed.
+Move a set of files to a new directory
++ <move todir="some/new/dir" > + <fileset dir="my/src/dir" > + <include name="**/*.jar" /> + <exclude name="**/ant.jar" /> + </fileset> + </move> ++
Applies a diff file to originals. @@ -3272,6 +3432,8 @@ JVM that I tested, the home directory on Windows is "C:\". Different implementations may use other values for the home directory on Windows.
This task has been deprecated. Use the Move task instead.
Renames a given file.
This implementation is based on Arnout Kuiper's initial design + * document, the following mailing list discussions, and the + * copyfile/copydir tasks.
+ * + * @author Glenn McAllister glennm@ca.ibm.com + */ +public class Copy extends Task { + protected File file = null; // the source file + protected File dir = null; // the source directory + protected File destFile = null; // the destination file + protected File destDir = null; // the destination directory + protected Vector filesets = new Vector(); + + protected boolean filtering = false; + protected boolean forceOverwrite = false; + protected boolean flatten = false; + protected int verbosity = Project.MSG_VERBOSE; + + protected Hashtable fileCopyMap = new Hashtable(); + + /** + * Sets a single source file to copy. + */ + public void setFile(File file) { + this.file = file; + } + + /** + * Sets a directory to copy. + */ + public void setDir(File dir) { + this.dir = dir; + } + + /** + * Sets the destination file. + */ + public void setTofile(File destFile) { + this.destFile = destFile; + } + + /** + * Sets the destination directory. + */ + public void setTodir(File destDir) { + this.destDir = destDir; + } + + /** + * Sets filtering. + */ + public void setFiltering(boolean filtering) { + this.filtering = filtering; + } + + /** + * Overwrite any existing destination file(s). + */ + public void setOverwrite(boolean overwrite) { + this.forceOverwrite = overwrite; + } + + /** + * When copying directory trees, the files can be "flattened" + * into a single directory. If there are multiple files with + * the same name in the source directory tree, only the first + * file will be copied into the "flattened" directory, unless + * the forceoverwrite attribute is true. + */ + public void setFlatten(boolean flatten) { + this.flatten = flatten; + } + + /** + * Used to force listing of all names of copied files. + */ + public void setVerbose(boolean verbose) { + if (verbose) { + this.verbosity = Project.MSG_INFO; + } else { + this.verbosity = Project.MSG_VERBOSE; + } + } + + /** + * Adds a set of files (nested fileset attribute). + */ + public void addFileset(FileSet set) { + filesets.addElement(set); + } + + /** + * Performs the copy operation. + */ + public void execute() throws BuildException { + // make sure we don't have an illegal set of options + validateAttributes(); + + // deal with the single file + if (file != null) { + if (destFile == null) { + destFile = new File(destDir, file.getName()); + } + + if (forceOverwrite || + (file.lastModified() > destFile.lastModified())) { + fileCopyMap.put(file.getAbsolutePath(), destFile.getAbsolutePath()); + } + } + + // deal with the directory + if (dir != null) { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(dir); + ds.scan(); // include EVERYTHING + + String[] srcFiles = ds.getIncludedFiles(); + scan(dir, destDir, srcFiles); // add to fileCopyMap + } + + // deal with the filesets + for (int i=0; iCurrently Delete extends MatchingTask. This is intend only + * to provide backwards compatibility for a release. The future position + * is to use nested filesets exclusively.
* * @author stefano@apache.org * @author Tom Dimock tad1@cornell.edu + * @author Glenn McAllister glennm@ca.ibm.com */ public class Delete extends MatchingTask { - private File delDir = null; + protected File file = null; + protected File dir = null; + protected Vector filesets = new Vector(); + protected boolean usedMatchingTask = false; + private int verbosity = Project.MSG_VERBOSE; - private File f = null; /** * Set the name of a single file to be removed. * * @param file the file to be deleted */ - public void setFile(String file) { - f = project.resolveFile(file); + public void setFile(File file) { + this.file = file; } /** @@ -81,8 +94,8 @@ public class Delete extends MatchingTask { * * @param dir the directory path. */ - public void setDir(String dir) { - delDir = project.resolveFile(dir); + public void setDir(File dir) { + this.dir = dir; } /** @@ -90,8 +103,8 @@ public class Delete extends MatchingTask { * * @param verbose "true" or "on" */ - public void setVerbose(String verbose) { - if ("true".equalsIgnoreCase(verbose.trim()) || "on".equalsIgnoreCase(verbose.trim())) { + public void setVerbose(boolean verbose) { + if (verbose) { this.verbosity = Project.MSG_INFO; } else { this.verbosity = Project.MSG_VERBOSE; @@ -99,60 +112,178 @@ public class Delete extends MatchingTask { } /** - * Make it so. Delete the file(s). - * - * @throws BuildException + * Adds a set of files (nested fileset attribute). */ - public void execute() throws BuildException { - if (f == null && delDir == null) { - throw new BuildException("Source files and directories are only deleted when the file or + * directory has been copied to the destination successfully. Filtering + * also works.
+ * + *This implementation is based on Arnout Kuiper's initial design + * document, the following mailing list discussions, and the + * copyfile/copydir tasks.
+ * + * @author Glenn McAllister glennm@ca.ibm.com + */ +public class Move extends Copy { + + public Move() { + super(); + forceOverwrite = true; + } + + public void execute() throws BuildException { + super.execute(); + + // take care of the source directory + if (dir != null && dir.exists()) { + deleteDir(dir); + } + } + +//************************************************************************ +// protected and private methods +//************************************************************************ + + protected void doFileOperations() { + if (fileCopyMap.size() > 0) { + log("Moving " + fileCopyMap.size() + " files to " + + destDir.getAbsolutePath() ); + + Enumeration e = fileCopyMap.keys(); + while (e.hasMoreElements()) { + String fromFile = (String) e.nextElement(); + String toFile = (String) fileCopyMap.get(fromFile); + + try { + log("Moving " + fromFile + " to " + toFile, verbosity); + project.copyFile(fromFile, + toFile, + filtering, + forceOverwrite); + File f = new File(fromFile); + if (!f.delete()) { + throw new BuildException("Unable to delete file " + f.getAbsolutePath()); + } + } catch (IOException ioe) { + String msg = "Failed to copy " + fromFile + " to " + toFile + + " due to " + ioe.getMessage(); + throw new BuildException(msg, ioe, location); + } + } + } + } + + protected void deleteDir(File d) { + String[] list = d.list(); + for (int i = 0; i < list.length; i++) { + String s = list[i]; + File f = new File(d, s); + if (f.isDirectory()) { + deleteDir(f); + } else { + throw new BuildException("UNEXPECTED ERROR - The file " + f.getAbsolutePath() + " should not exist!"); + } + } + log("Deleting directory " + d.getAbsolutePath(), verbosity); + if (!d.delete()) { + throw new BuildException("Unable to delete directory " + dir.getAbsolutePath()); + } + } + +} diff --git a/src/main/org/apache/tools/ant/taskdefs/Rename.java b/src/main/org/apache/tools/ant/taskdefs/Rename.java index 3dd31838b..714f1fce3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Rename.java +++ b/src/main/org/apache/tools/ant/taskdefs/Rename.java @@ -102,6 +102,8 @@ public class Rename extends Task { * thrown, if the rename operation fails. */ public void execute() throws BuildException { + log("DEPRECATED - The rename task is deprecated. Use move instead."); + if (dest == null) { throw new BuildException("dest attribute is required", location); } diff --git a/src/main/org/apache/tools/ant/taskdefs/defaults.properties b/src/main/org/apache/tools/ant/taskdefs/defaults.properties index 1745ec3ba..66476de66 100644 --- a/src/main/org/apache/tools/ant/taskdefs/defaults.properties +++ b/src/main/org/apache/tools/ant/taskdefs/defaults.properties @@ -4,6 +4,8 @@ javac=org.apache.tools.ant.taskdefs.Javac chmod=org.apache.tools.ant.taskdefs.Chmod deltree=org.apache.tools.ant.taskdefs.Deltree delete=org.apache.tools.ant.taskdefs.Delete +copy=org.apache.tools.ant.taskdefs.Copy +move=org.apache.tools.ant.taskdefs.Move jar=org.apache.tools.ant.taskdefs.Jar copydir=org.apache.tools.ant.taskdefs.Copydir copyfile=org.apache.tools.ant.taskdefs.Copyfile