Browse Source

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
master
Stefan Bodewig 15 years ago
parent
commit
3a912beff7
4 changed files with 62 additions and 8 deletions
  1. +3
    -0
      WHATSNEW
  2. +6
    -3
      docs/manual/Tasks/copy.html
  3. +17
    -5
      src/main/org/apache/tools/ant/taskdefs/Copy.java
  4. +36
    -0
      src/tests/antunit/taskdefs/copy-test.xml

+ 3
- 0
WHATSNEW View File

@@ -166,6 +166,9 @@ Other changes:
the imported resource. This means that several kinds of different build
files can import each other.

* <copy tofile=""> now also works for non-filesystem resources.
Bugzilla Report 49756.

Changes from Ant 1.8.0 TO Ant 1.8.1
===================================



+ 6
- 3
docs/manual/Tasks/copy.html View File

@@ -73,12 +73,15 @@ operation as <a href="../Types/filterset.html">filtersets</a>.
<td valign="top">The file to copy to.</td>
<td valign="top" align="center" rowspan="2">With the <code>file</code>
attribute, either <code>tofile</code> or <code>todir</code> can be used.<br/>
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 <code>dir</code> attribute is
specified in the <code>&lt;fileset&gt;</code>, or if the
<code>file</code> attribute is also specified, then only
<code>todir</code> is allowed.</td>
<code>todir</code> is allowed.<br/>
<em>Prior to Ant 1.8.2</em> the <code>tofile</code> attribute
only supported filesystem resources top copy from.</td>
</tr>
<tr>
<td valign="top">todir</td>


+ 17
- 5
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -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(


+ 36
- 0
src/tests/antunit/taskdefs/copy-test.xml View File

@@ -403,4 +403,40 @@ public class NullByteStreamResource extends Resource {
</copy>
</target>

<target name="testCopyWithResourceAndFile"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49756"
>
<mkdir dir="${input}"/>
<au:assertFileDoesntExist file="${input}/somefile"/>
<copy tofile="${input}/somefile">
<first>
<union>
<restrict>
<exists/>
<fileset file="${input}/somefile"/>
</restrict>
<string value="default contents"/>
</union>
</first>
</copy>
<au:assertFileExists file="${input}/somefile"/>
<au:assertResourceContains resource="${input}/somefile"
value="default contents"/>
<delete file="${input}/somefile"/>
<touch file="${input}/somefile"/>
<copy tofile="${input}/somefile">
<first>
<union>
<restrict>
<exists/>
<fileset file="${input}/somefile"/>
</restrict>
<string value="default contents"/>
</union>
</first>
</copy>
<au:assertFileExists file="${input}/somefile"/>
<au:assertResourceDoesntContain resource="${input}/somefile"
value="default contents"/>
</target>
</project>

Loading…
Cancel
Save