https://bz.apache.org/bugzilla/show_bug.cgi?id=62379master
@@ -43,6 +43,11 @@ Other changes: | |||||
availableProcessors, freeMemory, maxMemory and totalMemory methods | availableProcessors, freeMemory, maxMemory and totalMemory methods | ||||
of the Java Runtime class. | of the Java Runtime class. | ||||
* <resourcelist> has a new basedir attribute that can be used to | |||||
resolve relative names and provides a root for the FileResources | |||||
generated. | |||||
Bugzilla Report 62379 | |||||
Changes from Ant 1.9.10 TO Ant 1.9.11 | Changes from Ant 1.9.10 TO Ant 1.9.11 | ||||
===================================== | ===================================== | ||||
@@ -1334,6 +1334,15 @@ collection. <strong>Since Ant 1.9.5</strong>.</p> | |||||
<td valign="top">The encoding of the nested resources</td> | <td valign="top">The encoding of the nested resources</td> | ||||
<td valign="top" align="center">No, default is platform default</td> | <td valign="top" align="center">No, default is platform default</td> | ||||
</tr> | </tr> | ||||
<tr> | |||||
<td valign="top">basedir</td> | |||||
<td valign="top">Base directory that is used to resolve | |||||
relative file names against. Is also used to provide a base | |||||
directory to the FileResources created by this resource | |||||
collection. <em>Since Ant 1.9.12</em> | |||||
</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
</table> | </table> | ||||
</blockquote> | </blockquote> | ||||
@@ -19,6 +19,7 @@ package org.apache.tools.ant.types.resources; | |||||
import java.io.BufferedInputStream; | import java.io.BufferedInputStream; | ||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
import java.io.File; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStreamReader; | import java.io.InputStreamReader; | ||||
import java.io.Reader; | import java.io.Reader; | ||||
@@ -49,6 +50,7 @@ public class ResourceList extends DataType implements ResourceCollection { | |||||
private final Union cachedResources = new Union(); | private final Union cachedResources = new Union(); | ||||
private volatile boolean cached = false; | private volatile boolean cached = false; | ||||
private String encoding = null; | private String encoding = null; | ||||
private File baseDir; | |||||
public ResourceList() { | public ResourceList() { | ||||
cachedResources.setCache(true); | cachedResources.setCache(true); | ||||
@@ -99,6 +101,21 @@ public class ResourceList extends DataType implements ResourceCollection { | |||||
this.encoding = encoding; | this.encoding = encoding; | ||||
} | } | ||||
/** | |||||
* Basedir to use for file resources read from nested resources - | |||||
* this allows the resources contained inside this collection to | |||||
* be considered relative to a certain base directory. | |||||
* | |||||
* @param basedir the basedir | |||||
* @since Ant 1.9.12 | |||||
*/ | |||||
public final void setBasedir(File baseDir) { | |||||
if (isReference()) { | |||||
throw tooManyAttributes(); | |||||
} | |||||
this.baseDir = baseDir; | |||||
} | |||||
/** | /** | ||||
* Makes this instance in effect a reference to another ResourceList | * Makes this instance in effect a reference to another ResourceList | ||||
* instance. | * instance. | ||||
@@ -250,6 +267,11 @@ public class ResourceList extends DataType implements ResourceCollection { | |||||
// resource | // resource | ||||
} | } | ||||
} | } | ||||
if (baseDir != null) { | |||||
FileResource fr = new FileResource(baseDir, expandedLine); | |||||
fr.setProject(getProject()); | |||||
return fr; | |||||
} | |||||
return new FileResource(getProject(), expandedLine); | return new FileResource(getProject(), expandedLine); | ||||
} | } | ||||
} | } |
@@ -484,4 +484,22 @@ public class NullByteStreamResource extends Resource { | |||||
</copy> | </copy> | ||||
<au:assertFileExists file="${output}/filea"/> | <au:assertFileExists file="${output}/filea"/> | ||||
</target> | </target> | ||||
<target name="testCopyOfResourceListDoesntFlatten" | |||||
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=62379"> | |||||
<mkdir dir="${input}/dir"/> | |||||
<touch file="${input}/a"/> | |||||
<touch file="${input}/b"/> | |||||
<touch file="${input}/c"/> | |||||
<echo file="${input}/dir/c">Testfile</echo> | |||||
<mkdir dir="${output}"/> | |||||
<copy todir="${output}"> | |||||
<resourcelist basedir="${input}"> | |||||
<string value="${input}/dir/c"/> | |||||
</resourcelist> | |||||
</copy> | |||||
<au:assertFileDoesntExist file="${output}/c"/> | |||||
<au:assertFileExists file="${output}/dir/c"/> | |||||
<au:assertFilesMatch expected="${input}/dir/c" actual="${output}/dir/c"/> | |||||
</target> | |||||
</project> | </project> |