From 8cb8f75cddb280d3aed7aa489d8076277102fd27 Mon Sep 17 00:00:00 2001
From: Peter Donald
Date: Fri, 12 Oct 2001 08:19:40 +0000
Subject: [PATCH] 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
---
docs/manual/CoreTasks/copy.html | 4 +++-
.../org/apache/tools/ant/taskdefs/Copy.java | 23 ++++++++++++++++++-
2 files changed, 25 insertions(+), 2 deletions(-)
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) {