Browse Source

Add nested file element to file list to allow filenames to

contain white space and commas


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276138 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 21 years ago
parent
commit
dd0d33bb30
4 changed files with 125 additions and 19 deletions
  1. +35
    -6
      docs/manual/CoreTypes/filelist.html
  2. +37
    -0
      src/etc/testcases/types/filelist.xml
  3. +35
    -0
      src/main/org/apache/tools/ant/types/FileList.java
  4. +18
    -13
      src/testcases/org/apache/tools/ant/types/FileListTest.java

+ 35
- 6
docs/manual/CoreTypes/filelist.html View File

@@ -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>&lt;target&gt;</code> (i.e., as children of
<code>&lt;project&gt;</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>&lt;target&gt;</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>
&lt;filelist
@@ -67,6 +85,17 @@ actually exist.

<p>Same files as the example above.</p>

<blockquote><pre>
&lt;filelist
id=&quot;docfiles&quot;
dir=&quot;${doc.src}&quot;&gt;
&lt;file name="foo.xml"/&gt;
&lt;file name="bar.xml"/&gt;
&lt;/filelist&gt;
</pre></blockquote>

<p>Same files as the example above.</p>

<hr>
<p align="center">Copyright &copy; 2001-2002,2004 The Apache Software Foundation. All rights
Reserved.</p>


+ 37
- 0
src/etc/testcases/types/filelist.xml View File

@@ -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>

+ 35
- 0
src/main/org/apache/tools/ant/types/FileList.java View File

@@ -159,4 +159,39 @@ public class FileList extends DataType {
}
}

/**
* Inner class corresponding to the &lt;file&gt; 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 &lt;file&gt; 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());
}
}

+ 18
- 13
src/testcases/org/apache/tools/ant/types/FileListTest.java View File

@@ -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");
}
}

Loading…
Cancel
Save