Browse Source

type any

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@673467 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 17 years ago
parent
commit
835a8f0cc8
3 changed files with 36 additions and 10 deletions
  1. +4
    -1
      WHATSNEW
  2. +6
    -2
      src/main/org/apache/tools/ant/types/resources/selectors/Type.java
  3. +26
    -7
      src/tests/antunit/types/resources/selectors/test.xml

+ 4
- 1
WHATSNEW View File

@@ -85,7 +85,7 @@ Other changes:
* There is now a FileProvider interface for resources that act as a source
of filenames. This should be used by tasks that require resources
to provide filenames, rather than require that all resources
are instances or subclasses of FileResource
are instances or subclasses of FileResource.
Bugzilla report 43348
* Fixcrlf now gives better error messages on bad directory attributes.
@@ -98,6 +98,9 @@ Other changes:
list of the targets that have been specified on the command line
(the IDE, an <ant> task ...) when invoking the current project.

* The <type> resource selector has had an "any" type added for better
configurability.

Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================



+ 6
- 2
src/main/org/apache/tools/ant/types/resources/selectors/Type.java View File

@@ -29,6 +29,7 @@ public class Type implements ResourceSelector {

private static final String FILE_ATTR = "file";
private static final String DIR_ATTR = "dir";
private static final String ANY_ATTR = "any";

/** Static file type selector. */
public static final Type FILE = new Type(new FileDir(FILE_ATTR));
@@ -36,11 +37,14 @@ public class Type implements ResourceSelector {
/** Static dir type selector. */
public static final Type DIR = new Type(new FileDir(DIR_ATTR));

/** Static any type selector. Since Ant 1.8. */
public static final Type ANY = new Type(new FileDir(ANY_ATTR));

/**
* Implements the type attribute.
*/
public static class FileDir extends EnumeratedAttribute {
private static final String[] VALUES = new String[] {FILE_ATTR, DIR_ATTR};
private static final String[] VALUES = new String[] { FILE_ATTR, DIR_ATTR, ANY_ATTR };

/**
* Default constructor.
@@ -99,7 +103,7 @@ public class Type implements ResourceSelector {
throw new BuildException("The type attribute is required.");
}
int i = type.getIndex();
return r.isDirectory() ? i == 1 : i == 0;
return i == 2 || (r.isDirectory() ? i == 1 : i == 0);
}

}

+ 26
- 7
src/tests/antunit/types/resources/selectors/test.xml View File

@@ -15,10 +15,12 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<project default="all" xmlns:au="antlib:org.apache.ant.antunit"
<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"
xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors"
xmlns:rcmp="antlib:org.apache.tools.ant.types.resources.comparators">

<import file="../../../antunit-base.xml" />

<available property="jdk1.4+" classname="java.lang.CharSequence"/>
<condition property="some.regexp.support">
<or>
@@ -145,19 +147,36 @@
<target name="instanceof" depends="instanceoftype,testinstanceofclass" />

<target name="testtype">
<resources id="testtype">
<file file="${basedir}" />
<file file="${ant.file}" />
<resource directory="true" />
<resource directory="false" />
</resources>
<au:assertTrue>
<resourcecount when="equal" count="2">
<restrict>
<resources>
<file file="${basedir}" />
<file file="${ant.file}" />
<resource directory="true" />
<resource directory="false" />
</resources>
<resources refid="testtype" />
<rsel:type type="dir" />
</restrict>
</resourcecount>
</au:assertTrue>
<au:assertTrue>
<resourcecount when="equal" count="2">
<restrict>
<resources refid="testtype" />
<rsel:type type="file" />
</restrict>
</resourcecount>
</au:assertTrue>
<au:assertTrue>
<resourcecount when="equal" count="4">
<restrict>
<resources refid="testtype" />
<rsel:type type="any" />
</restrict>
</resourcecount>
</au:assertTrue>
</target>

<target name="testdate">


Loading…
Cancel
Save