From 3a912beff76f60fca0e92f3c9a2170c1bd5da28a Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 17 Aug 2010 12:22:07 +0000 Subject: [PATCH] allow copy/@tofile to be used with non-file resources. PR 49756 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@986290 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 ++ docs/manual/Tasks/copy.html | 9 +++-- .../org/apache/tools/ant/taskdefs/Copy.java | 22 +++++++++--- src/tests/antunit/taskdefs/copy-test.xml | 36 +++++++++++++++++++ 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index e4e82b445..626b9328b 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -166,6 +166,9 @@ Other changes: the imported resource. This means that several kinds of different build files can import each other. + * now also works for non-filesystem resources. + Bugzilla Report 49756. + Changes from Ant 1.8.0 TO Ant 1.8.1 =================================== diff --git a/docs/manual/Tasks/copy.html b/docs/manual/Tasks/copy.html index 0378bfdff..9fde87f88 100644 --- a/docs/manual/Tasks/copy.html +++ b/docs/manual/Tasks/copy.html @@ -73,12 +73,15 @@ operation as filtersets. The file to copy to. With the file attribute, either tofile or todir can be used.
- With nested resource collection elements, if the collection - contains non-filesystem resources, the number of included files + + With nested resource collection elements, if the number of + included resources is greater than 1, or if only the dir attribute is specified in the <fileset>, or if the file attribute is also specified, then only - todir is allowed. + todir is allowed.
+ Prior to Ant 1.8.2 the tofile attribute + only supported filesystem resources top copy from. todir diff --git a/src/main/org/apache/tools/ant/taskdefs/Copy.java b/src/main/org/apache/tools/ant/taskdefs/Copy.java index 06dbfed91..8a65789da 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copy.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copy.java @@ -102,6 +102,10 @@ public class Copy extends Task { private long granularity = 0; private boolean force = false; + // used to store the single non-file resource to copy when the + // tofile attribute has been used + private Resource singleResource = null; + /** * Copy task constructor. */ @@ -550,11 +554,15 @@ public class Copy extends Task { } } - if (nonFileResources.size() > 0) { + if (nonFileResources.size() > 0 || singleResource != null) { Resource[] nonFiles = (Resource[]) nonFileResources.toArray(new Resource[nonFileResources.size()]); // restrict to out-of-date resources Map map = scan(nonFiles, destDir); + if (singleResource != null) { + map.put(singleResource, + new String[] { destFile.getAbsolutePath() }); + } try { doResourceOperations(map); } catch (BuildException e) { @@ -568,6 +576,7 @@ public class Copy extends Task { } finally { // clean up again, so this instance can be used a second // time + singleResource = null; file = savedFile; destFile = savedDestFile; destDir = savedDestDir; @@ -661,10 +670,9 @@ public class Copy extends Task { "Cannot concatenate multiple files into a single file."); } else { ResourceCollection rc = (ResourceCollection) rcs.elementAt(0); - if (!rc.isFilesystemOnly()) { + if (!rc.isFilesystemOnly() && !supportsNonFileResources()) { throw new BuildException("Only FileSystem resources are" - + " supported when concatenating" - + " files."); + + " supported."); } if (rc.size() == 0) { throw new BuildException(MSG_WHEN_COPYING_EMPTY_RC_TO_FILE); @@ -672,7 +680,11 @@ public class Copy extends Task { Resource res = (Resource) rc.iterator().next(); FileProvider r = (FileProvider) res.as(FileProvider.class); if (file == null) { - file = r.getFile(); + if (r != null) { + file = r.getFile(); + } else { + singleResource = res; + } rcs.removeElementAt(0); } else { throw new BuildException( diff --git a/src/tests/antunit/taskdefs/copy-test.xml b/src/tests/antunit/taskdefs/copy-test.xml index b47b758bd..be94552b2 100644 --- a/src/tests/antunit/taskdefs/copy-test.xml +++ b/src/tests/antunit/taskdefs/copy-test.xml @@ -403,4 +403,40 @@ public class NullByteStreamResource extends Resource {
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +