diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSelector.java index 7ad5932d2..71c743c89 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSelector.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSelector.java @@ -21,7 +21,6 @@ import org.apache.myrmidon.framework.DataType; * @ant:role shorthand="v-file-selector" */ public interface FileSelector - extends DataType { /** * Accepts a file. diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FilteredFileList.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FilteredFileList.java index 8bd99bd46..36e82ad84 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FilteredFileList.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FilteredFileList.java @@ -31,7 +31,7 @@ public class FilteredFileList /** * Sets the selector to use to filter with. */ - public void setCondition( final AndFileSelector selector ) + public void setFilter( final AndFileSelector selector ) { m_selector = selector; } diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/Resources.properties b/proposal/myrmidon/src/java/org/apache/antlib/vfile/Resources.properties index ad2489458..2f0741bb0 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/Resources.properties +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/Resources.properties @@ -8,10 +8,4 @@ copyfilestask.no-destination.error=No destination file or directory specified fo copyfilestask.no-destination.error=No destination directory specified for {0} task. copyfilestask.copy-file.error=Could not copy "{0}" to "{1}". -nameselector.too-many-patterns.error=Too many name patterns specified. -nameselector.no-pattern.error=No name pattern specified. -nameselector.bad-pattern.error=Invalid name pattern "{0}". - filteredfilelist.no-selector.error=No filter criteria specified. - -notfileselector.no-selector.error=No selector specified. diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/AbstractNameFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/AbstractNameFileSelector.java index c57797b98..d15892034 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/AbstractNameFileSelector.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/AbstractNameFileSelector.java @@ -133,5 +133,6 @@ public abstract class AbstractNameFileSelector * Returns the name to match against. */ protected abstract String getNameForMatch( final String path, - final FileObject file ); + final FileObject file ) + throws TaskException; } diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/AndFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/AndFileSelector.java index 0d1d93b08..56a4d22f5 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/AndFileSelector.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/AndFileSelector.java @@ -20,7 +20,6 @@ import org.apache.myrmidon.api.TaskException; * @author Adam Murdoch * @version $Revision$ $Date$ * - * @ant:data-type name="and-selector" * @ant:type type="v-file-selector" name="and" */ public class AndFileSelector diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/BaseNameFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/BaseNameFileSelector.java index f06c5acf3..0b62bb9f3 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/BaseNameFileSelector.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/BaseNameFileSelector.java @@ -15,7 +15,6 @@ import org.apache.aut.vfs.FileObject; * @author Adam Murdoch * @version $Revision$ $Date$ * - * @ant:data-type name="basename-selector" * @ant:type type="v-file-selector" name="basename" */ public class BaseNameFileSelector diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/ConditionSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/ConditionSelector.java new file mode 100644 index 000000000..8c013ce4e --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/ConditionSelector.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.antlib.vfile.selectors; + +import org.apache.myrmidon.framework.Condition; +import org.apache.myrmidon.framework.conditions.AndCondition; +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.api.TaskException; +import org.apache.antlib.vfile.FileSelector; +import org.apache.aut.vfs.FileObject; + +/** + * A file selector that evaluates a set of nested {@link Condition} elements. + * + * @author Adam Murdoch + * @version $Revision$ $Date$ + * + * @ant:type type="v-file-selector" name="condition" + */ +public class ConditionSelector + implements FileSelector +{ + private AndCondition m_condition = new AndCondition(); + + /** + * Adds a condition. + */ + public void add( final Condition condition ) + { + m_condition.add( condition ); + } + + /** + * Accepts a file. + */ + public boolean accept( final FileObject file, + final String path, + final TaskContext context ) + throws TaskException + { + return m_condition.evaluate( context ); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/ExistenceFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/ExistenceFileSelector.java index 2c0f9cbf1..21424888f 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/ExistenceFileSelector.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/ExistenceFileSelector.java @@ -19,7 +19,6 @@ import org.apache.myrmidon.api.TaskException; * @author Adam Murdoch * @version $Revision$ $Date$ * - * @ant:data-type name="exists-selector" * @ant:type type="v-file-selector" name="exists" */ public class ExistenceFileSelector diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/FileTestCondition.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/FileTestCondition.java new file mode 100644 index 000000000..17e801be8 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/FileTestCondition.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.antlib.vfile.selectors; + +import org.apache.myrmidon.framework.Condition; +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.api.TaskException; +import org.apache.aut.vfs.FileObject; +import org.apache.antlib.vfile.FileSelector; +import org.apache.avalon.excalibur.i18n.ResourceManager; +import org.apache.avalon.excalibur.i18n.Resources; + +/** + * A condition that applies a set of file selectors to a file. + * + * @author Adam Murdoch + * @version $Revision$ $Date$ + * + * @ant:type type="condition" name="file-test" + */ +public class FileTestCondition + implements Condition +{ + private final static Resources REZ + = ResourceManager.getPackageResources( FileTestCondition.class ); + + private FileObject m_file; + private AndFileSelector m_selector = new AndFileSelector(); + + /** + * Sets the file to test. + */ + public void setFile( final FileObject file ) + { + m_file = file; + } + + /** + * Adds a selector. + */ + public void add( final FileSelector selector ) + { + m_selector.add( selector ); + } + + /** + * Evaluates this condition. + */ + public boolean evaluate( final TaskContext context ) + throws TaskException + { + if( m_file == null ) + { + final String message = REZ.getString( "filetestcondition.no-file.error" ); + throw new TaskException( message ); + } + return m_selector.accept( m_file, null, context ); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsEmptyFolderSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsEmptyFolderSelector.java index 9a1b4e295..8522533fa 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsEmptyFolderSelector.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsEmptyFolderSelector.java @@ -20,8 +20,7 @@ import org.apache.myrmidon.api.TaskException; * @author Adam Murdoch * @version $Revision$ $Date$ * - * @ant:data-type name="is-empty-folder-selector" - * @ant:type type="v-file-selector" name="is-empty" + * @ant:type type="v-file-selector" name="is-empty-folder" */ public class IsEmptyFolderSelector implements FileSelector diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsFileSelector.java index 51a4913f5..9022dbcb5 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsFileSelector.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsFileSelector.java @@ -20,7 +20,6 @@ import org.apache.myrmidon.api.TaskException; * @author Adam Murdoch * @version $Revision$ $Date$ * - * @ant:data-type name="is-file-selector" * @ant:type type="v-file-selector" name="is-file" */ public class IsFileSelector diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsFolderSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsFolderSelector.java index 50b07c443..abb01348a 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsFolderSelector.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsFolderSelector.java @@ -20,7 +20,6 @@ import org.apache.myrmidon.api.TaskException; * @author Adam Murdoch * @version $Revision$ $Date$ * - * @ant:data-type name="is-folder-selector" * @ant:type type="v-file-selector" name="is-folder" */ public class IsFolderSelector diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/NameFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/NameFileSelector.java index a3e1de741..d6958c354 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/NameFileSelector.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/NameFileSelector.java @@ -8,6 +8,9 @@ package org.apache.antlib.vfile.selectors; import org.apache.aut.vfs.FileObject; +import org.apache.myrmidon.api.TaskException; +import org.apache.avalon.excalibur.i18n.ResourceManager; +import org.apache.avalon.excalibur.i18n.Resources; /** * A file selector that selects files based on their name. @@ -15,18 +18,26 @@ import org.apache.aut.vfs.FileObject; * @author Adam Murdoch * @version $Revision$ $Date$ * - * @ant:data-type name="name-selector" * @ant:type type="v-file-selector" name="name" */ public class NameFileSelector extends AbstractNameFileSelector { + private final static Resources REZ + = ResourceManager.getPackageResources( NameFileSelector.class ); + /** * Returns the name to match against. */ protected String getNameForMatch( final String path, final FileObject file ) + throws TaskException { + if( path == null ) + { + final String message = REZ.getString( "namefileselector.no-path.error" ); + throw new TaskException( message ); + } return path; } } diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/NotFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/NotFileSelector.java index 7202d3e4b..d367fa01c 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/NotFileSelector.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/NotFileSelector.java @@ -11,6 +11,8 @@ import org.apache.antlib.vfile.FileSelector; import org.apache.aut.vfs.FileObject; import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskException; +import org.apache.avalon.excalibur.i18n.ResourceManager; +import org.apache.avalon.excalibur.i18n.Resources; /** * A file selector that negates a nested file selector. @@ -18,12 +20,14 @@ import org.apache.myrmidon.api.TaskException; * @author Adam Murdoch * @version $Revision$ $Date$ * - * @ant:data-type name="not-selector" * @ant:type type="v-file-selector" name="not" */ public class NotFileSelector implements FileSelector { + private final static Resources REZ + = ResourceManager.getPackageResources( NotFileSelector.class ); + private FileSelector m_selector; /** @@ -44,7 +48,8 @@ public class NotFileSelector { if( m_selector == null ) { - throw new TaskException( "notfileselector.no-selector.error" ); + final String message = REZ.getString( "notfileselector.no-selector.error" ); + throw new TaskException( message ); } return !m_selector.accept( file, path, context ); } diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/OrFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/OrFileSelector.java index 8a420f092..4b3373e22 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/OrFileSelector.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/OrFileSelector.java @@ -20,7 +20,6 @@ import org.apache.myrmidon.api.TaskException; * @author Adam Murdoch * @version $Revision$ $Date$ * - * @ant:data-type name="or-selector" * @ant:type type="v-file-selector" name="or" */ public class OrFileSelector diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/Resources.properties b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/Resources.properties new file mode 100644 index 000000000..55e91a60f --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/Resources.properties @@ -0,0 +1,9 @@ +nameselector.too-many-patterns.error=Too many name patterns specified. +nameselector.no-pattern.error=No name pattern specified. +nameselector.bad-pattern.error=Invalid name pattern "{0}". + +notfileselector.no-selector.error=No selector specified. + +namefileselector.no-path.error=Cannot use the file selector here. + +filetestcondition.no-file.error=No file specified. diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/UrlFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/UrlFileSelector.java index 7a6b6271b..ccd900b6a 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/UrlFileSelector.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/UrlFileSelector.java @@ -15,7 +15,6 @@ import org.apache.aut.vfs.FileObject; * @author Adam Murdoch * @version $Revision$ $Date$ * - * @ant:data-type name="url-selector" * @ant:type type="v-file-selector" name="url" */ public class UrlFileSelector diff --git a/proposal/myrmidon/src/xdocs/vfs.xml b/proposal/myrmidon/src/xdocs/vfs.xml index 4704ed118..50fc5ca70 100644 --- a/proposal/myrmidon/src/xdocs/vfs.xml +++ b/proposal/myrmidon/src/xdocs/vfs.xml @@ -167,7 +167,7 @@

Selects files that exist.

-

<is-empty>

+

<is-empty-folder>

Selects empty folders, that is, folders that have no children.