diff --git a/docs/manual/CoreTasks/copy.html b/docs/manual/CoreTasks/copy.html index 7c06147f0..544ab3c3d 100644 --- a/docs/manual/CoreTasks/copy.html +++ b/docs/manual/CoreTasks/copy.html @@ -39,7 +39,9 @@ To use a fileset, the todir attribute must be set.

The file to copy to. With the file attribute, either tofile or todir can be used. With nested filesets, - only todir is allowed. + 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 + todir is allowed todir diff --git a/src/main/org/apache/tools/ant/taskdefs/Copy.java b/src/main/org/apache/tools/ant/taskdefs/Copy.java index 89c680b66..aba77260d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copy.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copy.java @@ -74,6 +74,7 @@ import java.util.*; * @author Glenn McAllister glennm@ca.ibm.com * @author Stefan Bodewig * @author Michael McCallum + * @author Magesh Umasankar */ 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) {