* Added <condition> file selector, which allows a set of nested conditions to be used to select files. * Added <file-test> condition, which evaluates a set of nested selectors against a file. * FileSelector doesn't extend DataType any more. * Got rid of the @ant:data-type tags from the file selectors, cause they ain't. * Renamed <condition> nested element in <filtered-path> -> <filter>. * Renamed <is-empty> selector -> <is-empty-folder> * Fixed NPE using <name> selector in a path. * Fixed error messages. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271684 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -21,7 +21,6 @@ import org.apache.myrmidon.framework.DataType; | |||||
| * @ant:role shorthand="v-file-selector" | * @ant:role shorthand="v-file-selector" | ||||
| */ | */ | ||||
| public interface FileSelector | public interface FileSelector | ||||
| extends DataType | |||||
| { | { | ||||
| /** | /** | ||||
| * Accepts a file. | * Accepts a file. | ||||
| @@ -31,7 +31,7 @@ public class FilteredFileList | |||||
| /** | /** | ||||
| * Sets the selector to use to filter with. | * Sets the selector to use to filter with. | ||||
| */ | */ | ||||
| public void setCondition( final AndFileSelector selector ) | |||||
| public void setFilter( final AndFileSelector selector ) | |||||
| { | { | ||||
| m_selector = selector; | m_selector = selector; | ||||
| } | } | ||||
| @@ -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.no-destination.error=No destination directory specified for {0} task. | ||||
| copyfilestask.copy-file.error=Could not copy "{0}" to "{1}". | 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. | filteredfilelist.no-selector.error=No filter criteria specified. | ||||
| notfileselector.no-selector.error=No selector specified. | |||||
| @@ -133,5 +133,6 @@ public abstract class AbstractNameFileSelector | |||||
| * Returns the name to match against. | * Returns the name to match against. | ||||
| */ | */ | ||||
| protected abstract String getNameForMatch( final String path, | protected abstract String getNameForMatch( final String path, | ||||
| final FileObject file ); | |||||
| final FileObject file ) | |||||
| throws TaskException; | |||||
| } | } | ||||
| @@ -20,7 +20,6 @@ import org.apache.myrmidon.api.TaskException; | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| * | * | ||||
| * @ant:data-type name="and-selector" | |||||
| * @ant:type type="v-file-selector" name="and" | * @ant:type type="v-file-selector" name="and" | ||||
| */ | */ | ||||
| public class AndFileSelector | public class AndFileSelector | ||||
| @@ -15,7 +15,6 @@ import org.apache.aut.vfs.FileObject; | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| * | * | ||||
| * @ant:data-type name="basename-selector" | |||||
| * @ant:type type="v-file-selector" name="basename" | * @ant:type type="v-file-selector" name="basename" | ||||
| */ | */ | ||||
| public class BaseNameFileSelector | public class BaseNameFileSelector | ||||
| @@ -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 <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @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 ); | |||||
| } | |||||
| } | |||||
| @@ -19,7 +19,6 @@ import org.apache.myrmidon.api.TaskException; | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| * | * | ||||
| * @ant:data-type name="exists-selector" | |||||
| * @ant:type type="v-file-selector" name="exists" | * @ant:type type="v-file-selector" name="exists" | ||||
| */ | */ | ||||
| public class ExistenceFileSelector | public class ExistenceFileSelector | ||||
| @@ -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 <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @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 ); | |||||
| } | |||||
| } | |||||
| @@ -20,8 +20,7 @@ import org.apache.myrmidon.api.TaskException; | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
| * @version $Revision$ $Date$ | * @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 | public class IsEmptyFolderSelector | ||||
| implements FileSelector | implements FileSelector | ||||
| @@ -20,7 +20,6 @@ import org.apache.myrmidon.api.TaskException; | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| * | * | ||||
| * @ant:data-type name="is-file-selector" | |||||
| * @ant:type type="v-file-selector" name="is-file" | * @ant:type type="v-file-selector" name="is-file" | ||||
| */ | */ | ||||
| public class IsFileSelector | public class IsFileSelector | ||||
| @@ -20,7 +20,6 @@ import org.apache.myrmidon.api.TaskException; | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| * | * | ||||
| * @ant:data-type name="is-folder-selector" | |||||
| * @ant:type type="v-file-selector" name="is-folder" | * @ant:type type="v-file-selector" name="is-folder" | ||||
| */ | */ | ||||
| public class IsFolderSelector | public class IsFolderSelector | ||||
| @@ -8,6 +8,9 @@ | |||||
| package org.apache.antlib.vfile.selectors; | package org.apache.antlib.vfile.selectors; | ||||
| import org.apache.aut.vfs.FileObject; | 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. | * A file selector that selects files based on their name. | ||||
| @@ -15,18 +18,26 @@ import org.apache.aut.vfs.FileObject; | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| * | * | ||||
| * @ant:data-type name="name-selector" | |||||
| * @ant:type type="v-file-selector" name="name" | * @ant:type type="v-file-selector" name="name" | ||||
| */ | */ | ||||
| public class NameFileSelector | public class NameFileSelector | ||||
| extends AbstractNameFileSelector | extends AbstractNameFileSelector | ||||
| { | { | ||||
| private final static Resources REZ | |||||
| = ResourceManager.getPackageResources( NameFileSelector.class ); | |||||
| /** | /** | ||||
| * Returns the name to match against. | * Returns the name to match against. | ||||
| */ | */ | ||||
| protected String getNameForMatch( final String path, | protected String getNameForMatch( final String path, | ||||
| final FileObject file ) | final FileObject file ) | ||||
| throws TaskException | |||||
| { | { | ||||
| if( path == null ) | |||||
| { | |||||
| final String message = REZ.getString( "namefileselector.no-path.error" ); | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| return path; | return path; | ||||
| } | } | ||||
| } | } | ||||
| @@ -11,6 +11,8 @@ import org.apache.antlib.vfile.FileSelector; | |||||
| import org.apache.aut.vfs.FileObject; | import org.apache.aut.vfs.FileObject; | ||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| import org.apache.myrmidon.api.TaskException; | 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. | * A file selector that negates a nested file selector. | ||||
| @@ -18,12 +20,14 @@ import org.apache.myrmidon.api.TaskException; | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| * | * | ||||
| * @ant:data-type name="not-selector" | |||||
| * @ant:type type="v-file-selector" name="not" | * @ant:type type="v-file-selector" name="not" | ||||
| */ | */ | ||||
| public class NotFileSelector | public class NotFileSelector | ||||
| implements FileSelector | implements FileSelector | ||||
| { | { | ||||
| private final static Resources REZ | |||||
| = ResourceManager.getPackageResources( NotFileSelector.class ); | |||||
| private FileSelector m_selector; | private FileSelector m_selector; | ||||
| /** | /** | ||||
| @@ -44,7 +48,8 @@ public class NotFileSelector | |||||
| { | { | ||||
| if( m_selector == null ) | 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 ); | return !m_selector.accept( file, path, context ); | ||||
| } | } | ||||
| @@ -20,7 +20,6 @@ import org.apache.myrmidon.api.TaskException; | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| * | * | ||||
| * @ant:data-type name="or-selector" | |||||
| * @ant:type type="v-file-selector" name="or" | * @ant:type type="v-file-selector" name="or" | ||||
| */ | */ | ||||
| public class OrFileSelector | public class OrFileSelector | ||||
| @@ -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 <name> file selector here. | |||||
| filetestcondition.no-file.error=No file specified. | |||||
| @@ -15,7 +15,6 @@ import org.apache.aut.vfs.FileObject; | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| * | * | ||||
| * @ant:data-type name="url-selector" | |||||
| * @ant:type type="v-file-selector" name="url" | * @ant:type type="v-file-selector" name="url" | ||||
| */ | */ | ||||
| public class UrlFileSelector | public class UrlFileSelector | ||||
| @@ -167,7 +167,7 @@ | |||||
| <p>Selects files that exist.</p> | <p>Selects files that exist.</p> | ||||
| <h3><code><is-empty></code></h3> | |||||
| <h3><code><is-empty-folder></code></h3> | |||||
| <p>Selects empty folders, that is, folders that have no children.</p> | <p>Selects empty folders, that is, folders that have no children.</p> | ||||