git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@986290 13f79535-47bb-0310-9956-ffa450edef68master
@@ -166,6 +166,9 @@ Other changes: | |||||
the imported resource. This means that several kinds of different build | the imported resource. This means that several kinds of different build | ||||
files can import each other. | 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 | Changes from Ant 1.8.0 TO Ant 1.8.1 | ||||
=================================== | =================================== | ||||
@@ -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">The file to copy to.</td> | ||||
<td valign="top" align="center" rowspan="2">With the <code>file</code> | <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/> | 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 | is greater than 1, or if only the <code>dir</code> attribute is | ||||
specified in the <code><fileset></code>, or if the | specified in the <code><fileset></code>, or if the | ||||
<code>file</code> attribute is also specified, then only | <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> | ||||
<tr> | <tr> | ||||
<td valign="top">todir</td> | <td valign="top">todir</td> | ||||
@@ -102,6 +102,10 @@ public class Copy extends Task { | |||||
private long granularity = 0; | private long granularity = 0; | ||||
private boolean force = false; | 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. | * 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[] nonFiles = | ||||
(Resource[]) nonFileResources.toArray(new Resource[nonFileResources.size()]); | (Resource[]) nonFileResources.toArray(new Resource[nonFileResources.size()]); | ||||
// restrict to out-of-date resources | // restrict to out-of-date resources | ||||
Map map = scan(nonFiles, destDir); | Map map = scan(nonFiles, destDir); | ||||
if (singleResource != null) { | |||||
map.put(singleResource, | |||||
new String[] { destFile.getAbsolutePath() }); | |||||
} | |||||
try { | try { | ||||
doResourceOperations(map); | doResourceOperations(map); | ||||
} catch (BuildException e) { | } catch (BuildException e) { | ||||
@@ -568,6 +576,7 @@ public class Copy extends Task { | |||||
} finally { | } finally { | ||||
// clean up again, so this instance can be used a second | // clean up again, so this instance can be used a second | ||||
// time | // time | ||||
singleResource = null; | |||||
file = savedFile; | file = savedFile; | ||||
destFile = savedDestFile; | destFile = savedDestFile; | ||||
destDir = savedDestDir; | destDir = savedDestDir; | ||||
@@ -661,10 +670,9 @@ public class Copy extends Task { | |||||
"Cannot concatenate multiple files into a single file."); | "Cannot concatenate multiple files into a single file."); | ||||
} else { | } else { | ||||
ResourceCollection rc = (ResourceCollection) rcs.elementAt(0); | ResourceCollection rc = (ResourceCollection) rcs.elementAt(0); | ||||
if (!rc.isFilesystemOnly()) { | |||||
if (!rc.isFilesystemOnly() && !supportsNonFileResources()) { | |||||
throw new BuildException("Only FileSystem resources are" | throw new BuildException("Only FileSystem resources are" | ||||
+ " supported when concatenating" | |||||
+ " files."); | |||||
+ " supported."); | |||||
} | } | ||||
if (rc.size() == 0) { | if (rc.size() == 0) { | ||||
throw new BuildException(MSG_WHEN_COPYING_EMPTY_RC_TO_FILE); | 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(); | Resource res = (Resource) rc.iterator().next(); | ||||
FileProvider r = (FileProvider) res.as(FileProvider.class); | FileProvider r = (FileProvider) res.as(FileProvider.class); | ||||
if (file == null) { | if (file == null) { | ||||
file = r.getFile(); | |||||
if (r != null) { | |||||
file = r.getFile(); | |||||
} else { | |||||
singleResource = res; | |||||
} | |||||
rcs.removeElementAt(0); | rcs.removeElementAt(0); | ||||
} else { | } else { | ||||
throw new BuildException( | throw new BuildException( | ||||
@@ -403,4 +403,40 @@ public class NullByteStreamResource extends Resource { | |||||
</copy> | </copy> | ||||
</target> | </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> | </project> |