donaldp 01/10/12 01:19:40
Modified: docs/manual/CoreTasks copy.html
src/main/org/apache/tools/ant/taskdefs Copy.java
Log:
If a fileset defines a single file, allow the Copy and Move tasks to work
with the toFile attribute.
Revision Changes Path
1.4 +3 -1 jakarta-ant/docs/manual/CoreTasks/copy.html
Index: copy.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/copy.html,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- copy.html 2001/08/30 13:23:13 1.3
+++ copy.html 2001/10/12 08:19:40 1.4
@@ -39,7 +39,9 @@
<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>
1.21 +22 -1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Copy.java
Index: Copy.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Copy.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- Copy.java 2001/08/18 14:59:39 1.20
+++ Copy.java 2001/10/12 08:19:40 1.21
@@ -74,6 +74,7 @@
* @author Glenn McAllister <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @author <A href="[EMAIL PROTECTED]">Michael McCallum</A>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
*/
public class Copy extends Task {
protected File file = null; // the source file
@@ -287,7 +288,27 @@
}
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) {