contain white space and commas git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276138 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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 <code><target></code> (i.e., as children of | |||
<code><project></code>). | |||
FileLists can appear inside tasks that support this feature or as stand-alone | |||
types. | |||
</p> | |||
<table border="1" cellpadding="2" cellspacing="0"> | |||
<tr> | |||
@@ -33,11 +32,30 @@ same level as <code><target></code> (i.e., as children of | |||
</tr> | |||
<tr> | |||
<td valign="top">files</td> | |||
<td valign="top">The list of file names.</td> | |||
<td valign="top" align="center">Yes</td> | |||
<td valign="top">The list of file names. This is a list of | |||
file name separated by whitespace, or by commas.</td> | |||
<td valign="top" align="center"> | |||
Yes, unless there is a nested file element</td> | |||
</tr> | |||
</table> | |||
<h4>Nested Element: file</h4> | |||
<p> | |||
This represents a file name. The nested element allows filenames containing | |||
white space and commas. | |||
</p> | |||
<p><em>Since ant 1.7</em></p> | |||
<table border="1" cellpadding="2" cellspacing="0"> | |||
<tr> | |||
<td valign="top"><b>Attribute</b></td> | |||
<td valign="top"><b>Description</b></td> | |||
<td align="center" valign="top"><b>Required</b></td> | |||
</tr> | |||
<tr> | |||
<td valign="top">name</td> | |||
<td valign="top">The name of the file.</td> | |||
<td valign="top" align="center">Yes</td> | |||
</tr> | |||
</table> | |||
<h4>Examples</h4> | |||
<blockquote><pre> | |||
<filelist | |||
@@ -67,6 +85,17 @@ actually exist. | |||
<p>Same files as the example above.</p> | |||
<blockquote><pre> | |||
<filelist | |||
id="docfiles" | |||
dir="${doc.src}"> | |||
<file name="foo.xml"/> | |||
<file name="bar.xml"/> | |||
</filelist> | |||
</pre></blockquote> | |||
<p>Same files as the example above.</p> | |||
<hr> | |||
<p align="center">Copyright © 2001-2002,2004 The Apache Software Foundation. All rights | |||
Reserved.</p> | |||
@@ -0,0 +1,37 @@ | |||
<project name="test"> | |||
<target name="simple"> | |||
<filelist id="filelist" | |||
dir="${basedir}" | |||
files="a"/> | |||
<pathconvert targetos="unix" refid="filelist" | |||
property="property"> | |||
<map from="${basedir}" to="/abc"/> | |||
</pathconvert> | |||
<echo>${property}</echo> | |||
</target> | |||
<target name="double"> | |||
<filelist id="filelist" | |||
dir="${basedir}" | |||
files="a b"/> | |||
<pathconvert targetos="unix" refid="filelist" | |||
property="property"> | |||
<map from="${basedir}" to="/abc"/> | |||
</pathconvert> | |||
<echo>${property}</echo> | |||
</target> | |||
<target name="nested"> | |||
<filelist id="filelist" | |||
dir="${basedir}"> | |||
<file name="a"/> | |||
<file name="b"/> | |||
</filelist> | |||
<pathconvert targetos="unix" refid="filelist" | |||
property="property"> | |||
<map from="${basedir}" to="/abc"/> | |||
</pathconvert> | |||
<echo>${property}</echo> | |||
</target> | |||
</project> |
@@ -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()); | |||
} | |||
} |
@@ -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. | |||
* | |||
* <p>This doesn't actually test much, mainly reference handling. | |||
* Adapted from FileSetTest.</p> | |||
* | |||
* @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a> | |||
* 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"); | |||
} | |||
} |