diff --git a/docs/manual/CoreTypes/filelist.html b/docs/manual/CoreTypes/filelist.html index 2029c7962..0630a8d39 100644 --- a/docs/manual/CoreTypes/filelist.html +++ b/docs/manual/CoreTypes/filelist.html @@ -16,9 +16,8 @@ specifying files that may or may not exist. Multiple files are specified as a list of files, relative to the specified directory, with no support for wildcard expansion (filenames with wildcards will be included in the list unchanged). -FileLists can appear inside tasks that support this feature or at the -same level as <target> (i.e., as children of -<project>). +FileLists can appear inside tasks that support this feature or as stand-alone +types.

@@ -33,11 +32,30 @@ same level as <target> (i.e., as children of - - + +
filesThe list of file names.YesThe list of file names. This is a list of + file name separated by whitespace, or by commas. + Yes, unless there is a nested file element
- +

Nested Element: file

+

+ This represents a file name. The nested element allows filenames containing + white space and commas. +

+

Since ant 1.7

+ + + + + + + + + + + +
AttributeDescriptionRequired
nameThe name of the file.Yes

Examples

 <filelist 
@@ -67,6 +85,17 @@ actually exist.
 
 

Same files as the example above.

+
+<filelist 
+    id="docfiles" 
+    dir="${doc.src}">
+    <file name="foo.xml"/>
+    <file name="bar.xml"/>
+</filelist>
+
+ +

Same files as the example above.

+

Copyright © 2001-2002,2004 The Apache Software Foundation. All rights Reserved.

diff --git a/src/etc/testcases/types/filelist.xml b/src/etc/testcases/types/filelist.xml new file mode 100644 index 000000000..9a9cc2216 --- /dev/null +++ b/src/etc/testcases/types/filelist.xml @@ -0,0 +1,37 @@ + + + + + + + ${property} + + + + + + + + ${property} + + + + + + + + + + + ${property} + + + diff --git a/src/main/org/apache/tools/ant/types/FileList.java b/src/main/org/apache/tools/ant/types/FileList.java index 2181f9e09..ba1464456 100644 --- a/src/main/org/apache/tools/ant/types/FileList.java +++ b/src/main/org/apache/tools/ant/types/FileList.java @@ -159,4 +159,39 @@ public class FileList extends DataType { } } + /** + * Inner class corresponding to the <file> nested element. + */ + public static class FileName { + private String name; + + /** + * The name attribute of the file element. + * + * @param name the name of a file to add to the file list. + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the name of the file for this element. + */ + public String getName() { + return name; + } + } + + /** + * Add a nested <file> nested element. + * + * @param name a configured file element with a name. + */ + public void addConfiguredFile(FileName name) { + if (name.getName() == null) { + throw new BuildException( + "No name specified in nested file element"); + } + filenames.addElement(name.getName()); + } } diff --git a/src/testcases/org/apache/tools/ant/types/FileListTest.java b/src/testcases/org/apache/tools/ant/types/FileListTest.java index 0e11363c2..119683e8e 100644 --- a/src/testcases/org/apache/tools/ant/types/FileListTest.java +++ b/src/testcases/org/apache/tools/ant/types/FileListTest.java @@ -17,8 +17,9 @@ package org.apache.tools.ant.types; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileTest; import junit.framework.TestCase; import junit.framework.AssertionFailedError; @@ -26,27 +27,19 @@ import junit.framework.AssertionFailedError; import java.io.File; /** - * JUnit 3 testcases for org.apache.tools.ant.types.FileList. - * - *

This doesn't actually test much, mainly reference handling. - * Adapted from FileSetTest.

- * - * @author Craeg Strong + * Some tests for filelist. */ -public class FileListTest extends TestCase { - - private Project project; +public class FileListTest extends BuildFileTest { public FileListTest(String name) { super(name); } public void setUp() { - project = new Project(); - project.setBasedir("."); + configureProject("src/etc/testcases/types/filelist.xml"); } - + public void testEmptyElementIfIsReference() { FileList f = new FileList(); f.setDir(project.resolveFile(".")); @@ -144,4 +137,16 @@ public class FileListTest extends TestCase { File dir = f1.getDir(project); assertEquals("Dir is basedir", dir, project.getBaseDir()); } + + public void testSimple() { + expectLog("simple", "/abc/a"); + } + + public void testDouble() { + expectLog("double", "/abc/a:/abc/b"); + } + + public void testNested() { + expectLog("nested", "/abc/a:/abc/b"); + } }