Move tasks. Now you can only copy or move entire directories with nested FileSets. Prompted by a patch submitted by Nico Seessle. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268061 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -136,7 +136,9 @@ | |||||
| <!-- =================================================================== --> | <!-- =================================================================== --> | ||||
| <target name="main" depends="jar" description="Creates the binary structure"> | <target name="main" depends="jar" description="Creates the binary structure"> | ||||
| <mkdir dir="${bin.dir}"/> | <mkdir dir="${bin.dir}"/> | ||||
| <copy dir="${src.bin.dir}" todir="${bin.dir}"/> | |||||
| <copy todir="${bin.dir}"> | |||||
| <fileset dir="${src.bin.dir}"/> | |||||
| </copy> | |||||
| <chmod perm="+x"> | <chmod perm="+x"> | ||||
| <fileset dir="${bin.dir}"> | <fileset dir="${bin.dir}"> | ||||
| <patternset refid="chmod.patterns"/> | <patternset refid="chmod.patterns"/> | ||||
| @@ -173,13 +175,23 @@ | |||||
| <mkdir dir="${ant.dist.dir}/docs/api"/> | <mkdir dir="${ant.dist.dir}/docs/api"/> | ||||
| <mkdir dir="${ant.dist.dir}/src"/> | <mkdir dir="${ant.dist.dir}/src"/> | ||||
| <copy dir="${src.dir}" todir="${ant.dist.dir}/src"/> | |||||
| <copy dir="${lib.dir}" todir="${ant.dist.dir}/lib"/> | |||||
| <copy todir="${ant.dist.dir}/src"> | |||||
| <fileset dir="${src.dir}"/> | |||||
| </copy> | |||||
| <copy todir="${ant.dist.dir}/lib"> | |||||
| <fileset dir="${lib.dir}"/> | |||||
| </copy> | |||||
| <copy file="build.xml" tofile="${ant.dist.dir}/lib/build.xml"/> | <copy file="build.xml" tofile="${ant.dist.dir}/lib/build.xml"/> | ||||
| <copy dir="src/bin" todir="${ant.dist.dir}/bin"/> | |||||
| <copy dir="${docs.dir}" todir="${ant.dist.dir}/docs"/> | |||||
| <copy dir="${build.javadocs}" todir="${ant.dist.dir}/docs/api"/> | |||||
| <copy todir="${ant.dist.dir}/bin"> | |||||
| <fileset dir="src/bin"/> | |||||
| </copy> | |||||
| <copy todir="${ant.dist.dir}/docs"> | |||||
| <fileset dir="${docs.dir}"/> | |||||
| </copy> | |||||
| <copy todir="${ant.dist.dir}/docs/api"> | |||||
| <fileset dir="${build.javadocs}"/> | |||||
| </copy> | |||||
| <fixcrlf srcdir="${ant.dist.dir}/bin" includes="ant,antRun" cr="remove"/> | <fixcrlf srcdir="${ant.dist.dir}/bin" includes="ant,antRun" cr="remove"/> | ||||
| <fixcrlf srcdir="${ant.dist.dir}/bin" includes="*.bat" cr="add"/> | <fixcrlf srcdir="${ant.dist.dir}/bin" includes="*.bat" cr="add"/> | ||||
| @@ -215,14 +227,20 @@ | |||||
| <!-- =================================================================== --> | <!-- =================================================================== --> | ||||
| <target name="bootstrap" depends="main" description="Installs the ant.jar library and binary files into ant.home"> | <target name="bootstrap" depends="main" description="Installs the ant.jar library and binary files into ant.home"> | ||||
| <echo message="copying bootstrapped files into bin and lib"/> | <echo message="copying bootstrapped files into bin and lib"/> | ||||
| <copy dir="${lib.dir}" todir="lib"/> | |||||
| <copy dir="${bin.dir}" todir="bin"/> | |||||
| <copy todir="lib"> | |||||
| <fileset dir="${lib.dir}"/> | |||||
| </copy> | |||||
| <copy todir="bin"> | |||||
| <fileset dir="${bin.dir}"/> | |||||
| </copy> | |||||
| </target> | </target> | ||||
| <target name="install" depends="dist" if="ant.install"> | <target name="install" depends="dist" if="ant.install"> | ||||
| <echo message="installing full copy of ant into ${ant.install}"/> | <echo message="installing full copy of ant into ${ant.install}"/> | ||||
| <mkdir dir="${ant.install}"/> | <mkdir dir="${ant.install}"/> | ||||
| <copy dir="${ant.dist.dir}" todir="${ant.install}"/> | |||||
| <copy todir="${ant.install}"> | |||||
| <fileset dir="${ant.dist.dir}"/> | |||||
| </copy> | |||||
| <chmod perm="+x"> | <chmod perm="+x"> | ||||
| <fileset dir="${ant.install}/bin"> | <fileset dir="${ant.install}/bin"> | ||||
| <patternset refid="chmod.patterns"/> | <patternset refid="chmod.patterns"/> | ||||
| @@ -235,8 +253,12 @@ | |||||
| <target name="mininstall" depends="main" if="ant.install"> | <target name="mininstall" depends="main" if="ant.install"> | ||||
| <echo message="copy minimal ant installation into ${ant.install}"/> | <echo message="copy minimal ant installation into ${ant.install}"/> | ||||
| <mkdir dir="${ant.install}"/> | <mkdir dir="${ant.install}"/> | ||||
| <copy dir="${lib.dir}" todir="${ant.install}/lib"/> | |||||
| <copy dir="${bin.dir}" todir="${ant.install}/bin"/> | |||||
| <copy todir="${ant.install}/lib"> | |||||
| <fileset dir="${lib.dir}"/> | |||||
| </copy> | |||||
| <copy todir="${ant.install}/bin"> | |||||
| <fileset dir="${bin.dir}"/> | |||||
| </copy> | |||||
| <chmod perm="+x"> | <chmod perm="+x"> | ||||
| <fileset dir="${ant.install}/bin"> | <fileset dir="${ant.install}/bin"> | ||||
| <patternset refid="chmod.patterns"/> | <patternset refid="chmod.patterns"/> | ||||
| @@ -1176,7 +1176,7 @@ permissions.</p> | |||||
| <hr> | <hr> | ||||
| <h2><a name="copy">Copy</a></h2> | <h2><a name="copy">Copy</a></h2> | ||||
| <h3>Description</h3> | <h3>Description</h3> | ||||
| <p>Copies a file or directory to a new file or directory. Files are | |||||
| <p>Copies a file or Fileset to a new file or directory. Files are | |||||
| only copied if the source file is newer than the destination file, | only copied if the source file is newer than the destination file, | ||||
| or when the destination file does not exist. However, you can explicitly | or when the destination file does not exist. However, you can explicitly | ||||
| overwrite files with the <var>overwrite</var> attribute.</p> | overwrite files with the <var>overwrite</var> attribute.</p> | ||||
| @@ -1192,19 +1192,15 @@ To use a fileset, the <var>todir</var> attribute must be set.</p> | |||||
| <tr> | <tr> | ||||
| <td valign="top">file</td> | <td valign="top">file</td> | ||||
| <td valign="top">the file to copy</td> | <td valign="top">the file to copy</td> | ||||
| <td valign="top" align="center" rowspan="2">One of <var>file</var> or | |||||
| <var>dir</var> are required, or at least one nested fileset element.</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">dir</td> | |||||
| <td valign="top">the directory to copy</td> | |||||
| <td valign="top" align="center">One of either <var>file</var> or | |||||
| at least one nested fileset element.</td> | |||||
| </tr> | </tr> | ||||
| <tr> | <tr> | ||||
| <td valign="top">tofile</td> | <td valign="top">tofile</td> | ||||
| <td valign="top">the file to copy to</td> | <td valign="top">the file to copy to</td> | ||||
| <td valign="top" align="center" rowspan="2">With the <var>file</var> attribute, | <td valign="top" align="center" rowspan="2">With the <var>file</var> attribute, | ||||
| either <var>tofile</var> or <var>todir</var> can be used. With the <var>dir</var> | |||||
| attribute and nested filesets, only <var>todir</var> is allowed.</td> | |||||
| either <var>tofile</var> or <var>todir</var> can be used. With nested filesets, | |||||
| only <var>todir</var> is allowed.</td> | |||||
| </tr> | </tr> | ||||
| <tr> | <tr> | ||||
| <td valign="top">todir</td> | <td valign="top">todir</td> | ||||
| @@ -1241,7 +1237,9 @@ To use a fileset, the <var>todir</var> attribute must be set.</p> | |||||
| </pre> | </pre> | ||||
| <p><b>Copy a directory to another directory</b></p> | <p><b>Copy a directory to another directory</b></p> | ||||
| <pre> | <pre> | ||||
| <copy dir="src_dir" todir="../new/dir" /> | |||||
| <copy todir="../new/dir"> | |||||
| <fileset dir="src_dir"/> | |||||
| </copy> | |||||
| </pre> | </pre> | ||||
| <p><b>Copy a set of files to a directory</b></p> | <p><b>Copy a set of files to a directory</b></p> | ||||
| <pre> | <pre> | ||||
| @@ -74,7 +74,6 @@ import java.util.*; | |||||
| */ | */ | ||||
| public class Copy extends Task { | public class Copy extends Task { | ||||
| protected File file = null; // the source file | protected File file = null; // the source file | ||||
| protected File dir = null; // the source directory | |||||
| protected File destFile = null; // the destination file | protected File destFile = null; // the destination file | ||||
| protected File destDir = null; // the destination directory | protected File destDir = null; // the destination directory | ||||
| protected Vector filesets = new Vector(); | protected Vector filesets = new Vector(); | ||||
| @@ -93,13 +92,6 @@ public class Copy extends Task { | |||||
| this.file = file; | this.file = file; | ||||
| } | } | ||||
| /** | |||||
| * Sets a directory to copy. | |||||
| */ | |||||
| public void setDir(File dir) { | |||||
| this.dir = dir; | |||||
| } | |||||
| /** | /** | ||||
| * Sets the destination file. | * Sets the destination file. | ||||
| */ | */ | ||||
| @@ -176,16 +168,6 @@ public class Copy extends Task { | |||||
| } | } | ||||
| } | } | ||||
| // 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 | // deal with the filesets | ||||
| for (int i=0; i<filesets.size(); i++) { | for (int i=0; i<filesets.size(); i++) { | ||||
| FileSet fs = (FileSet) filesets.elementAt(i); | FileSet fs = (FileSet) filesets.elementAt(i); | ||||
| @@ -209,8 +191,8 @@ public class Copy extends Task { | |||||
| * of attributes. | * of attributes. | ||||
| */ | */ | ||||
| protected void validateAttributes() throws BuildException { | protected void validateAttributes() throws BuildException { | ||||
| if (file == null && dir == null && filesets.size() == 0) { | |||||
| throw new BuildException("Specify at least one source - a file, a dir, or a fileset."); | |||||
| if (file == null && filesets.size() == 0) { | |||||
| throw new BuildException("Specify at least one source - a file or a fileset."); | |||||
| } | } | ||||
| if (destFile != null && destDir != null) { | if (destFile != null && destDir != null) { | ||||
| @@ -221,8 +203,8 @@ public class Copy extends Task { | |||||
| throw new BuildException("One of destfile or destdir must be set."); | throw new BuildException("One of destfile or destdir must be set."); | ||||
| } | } | ||||
| if (dir != null && destFile != null) { | |||||
| throw new BuildException("Cannot copy a directory into a file."); | |||||
| if (file != null && destFile != null && file.exists() && file.isDirectory()) { | |||||
| throw new BuildException("Use the dir attribute to copy directories."); | |||||
| } | } | ||||
| if (destFile != null && filesets.size() > 0) { | if (destFile != null && filesets.size() > 0) { | ||||
| @@ -86,11 +86,6 @@ public class Move extends Copy { | |||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| super.execute(); | super.execute(); | ||||
| // take care of the source directory | |||||
| if (dir != null && dir.exists()) { | |||||
| deleteDir(dir); | |||||
| } | |||||
| } | } | ||||
| //************************************************************************ | //************************************************************************ | ||||
| @@ -139,7 +134,7 @@ public class Move extends Copy { | |||||
| } | } | ||||
| log("Deleting directory " + d.getAbsolutePath(), verbosity); | log("Deleting directory " + d.getAbsolutePath(), verbosity); | ||||
| if (!d.delete()) { | if (!d.delete()) { | ||||
| throw new BuildException("Unable to delete directory " + dir.getAbsolutePath()); | |||||
| throw new BuildException("Unable to delete directory " + d.getAbsolutePath()); | |||||
| } | } | ||||
| } | } | ||||