Browse Source

add basedir attribute to <resourcelist>

https://bz.apache.org/bugzilla/show_bug.cgi?id=62379
master
Stefan Bodewig 7 years ago
parent
commit
2495b9a97e
4 changed files with 54 additions and 0 deletions
  1. +5
    -0
      WHATSNEW
  2. +9
    -0
      manual/Types/resources.html
  3. +22
    -0
      src/main/org/apache/tools/ant/types/resources/ResourceList.java
  4. +18
    -0
      src/tests/antunit/taskdefs/copy-test.xml

+ 5
- 0
WHATSNEW View File

@@ -43,6 +43,11 @@ Other changes:
availableProcessors, freeMemory, maxMemory and totalMemory methods
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
=====================================



+ 9
- 0
manual/Types/resources.html View File

@@ -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" align="center">No, default is platform default</td>
</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>
</blockquote>



+ 22
- 0
src/main/org/apache/tools/ant/types/resources/ResourceList.java View File

@@ -19,6 +19,7 @@ package org.apache.tools.ant.types.resources;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -49,6 +50,7 @@ public class ResourceList extends DataType implements ResourceCollection {
private final Union cachedResources = new Union();
private volatile boolean cached = false;
private String encoding = null;
private File baseDir;

public ResourceList() {
cachedResources.setCache(true);
@@ -99,6 +101,21 @@ public class ResourceList extends DataType implements ResourceCollection {
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
* instance.
@@ -250,6 +267,11 @@ public class ResourceList extends DataType implements ResourceCollection {
// resource
}
}
if (baseDir != null) {
FileResource fr = new FileResource(baseDir, expandedLine);
fr.setProject(getProject());
return fr;
}
return new FileResource(getProject(), expandedLine);
}
}

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

@@ -484,4 +484,22 @@ public class NullByteStreamResource extends Resource {
</copy>
<au:assertFileExists file="${output}/filea"/>
</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>

Loading…
Cancel
Save