Browse Source

If a fileset defines a single file, allow the Copy and Move tasks to work with the toFile attribute.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269779 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
8cb8f75cdd
2 changed files with 25 additions and 2 deletions
  1. +3
    -1
      docs/manual/CoreTasks/copy.html
  2. +22
    -1
      src/main/org/apache/tools/ant/taskdefs/Copy.java

+ 3
- 1
docs/manual/CoreTasks/copy.html View File

@@ -39,7 +39,9 @@ To use a fileset, the <var>todir</var> attribute must be set.</p>
<td valign="top">The file to copy to.</td>
<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 nested filesets,
only <var>todir</var> is allowed.</td>
if the fileset size is greater than 1 or if the only entry in the fileset is a
directory or if the file attribute is already specified, only
<var>todir</var> is allowed</td>
</tr>
<tr>
<td valign="top">todir</td>


+ 22
- 1
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -74,6 +74,7 @@ import java.util.*;
* @author Glenn McAllister <a href="mailto:glennm@ca.ibm.com">glennm@ca.ibm.com</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <A href="gholam@xtra.co.nz">Michael McCallum</A>
* @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a>
*/
public class Copy extends Task {
protected File file = null; // the source file
@@ -287,7 +288,27 @@ public class Copy extends Task {
}
if (destFile != null && filesets.size() > 0) {
throw new BuildException("Cannot concatenate multple files into a single file.");
if (filesets.size() > 1) {
throw new BuildException(
"Cannot concatenate multiple files into a single file.");
} else {
FileSet fs = (FileSet) filesets.elementAt(0);
DirectoryScanner ds = fs.getDirectoryScanner(project);
String[] srcFiles = ds.getIncludedFiles();

if (srcFiles.length > 0) {
if (file == null) {
file = new File(srcFiles[0]);
filesets.removeElementAt(0);
} else {
throw new BuildException(
"Cannot concatenate multiple files into a single file.");
}
} else {
throw new BuildException(
"Cannot perform operation from directory to file.");
}
}
}

if (destFile != null) {


Loading…
Cancel
Save