Browse Source

Added Condition <-> File Selector adaptors:

* 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-ffa450edef68
master
adammurdoch 23 years ago
parent
commit
bc7c6eddec
18 changed files with 145 additions and 22 deletions
  1. +0
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSelector.java
  2. +1
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/FilteredFileList.java
  3. +0
    -6
      proposal/myrmidon/src/java/org/apache/antlib/vfile/Resources.properties
  4. +2
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/AbstractNameFileSelector.java
  5. +0
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/AndFileSelector.java
  6. +0
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/BaseNameFileSelector.java
  7. +48
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/ConditionSelector.java
  8. +0
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/ExistenceFileSelector.java
  9. +64
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/FileTestCondition.java
  10. +1
    -2
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsEmptyFolderSelector.java
  11. +0
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsFileSelector.java
  12. +0
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsFolderSelector.java
  13. +12
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/NameFileSelector.java
  14. +7
    -2
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/NotFileSelector.java
  15. +0
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/OrFileSelector.java
  16. +9
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/Resources.properties
  17. +0
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/UrlFileSelector.java
  18. +1
    -1
      proposal/myrmidon/src/xdocs/vfs.xml

+ 0
- 1
proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSelector.java View File

@@ -21,7 +21,6 @@ import org.apache.myrmidon.framework.DataType;
* @ant:role shorthand="v-file-selector"
*/
public interface FileSelector
extends DataType
{
/**
* Accepts a file.


+ 1
- 1
proposal/myrmidon/src/java/org/apache/antlib/vfile/FilteredFileList.java View File

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


+ 0
- 6
proposal/myrmidon/src/java/org/apache/antlib/vfile/Resources.properties View File

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

+ 2
- 1
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/AbstractNameFileSelector.java View File

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

+ 0
- 1
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/AndFileSelector.java View File

@@ -20,7 +20,6 @@ import org.apache.myrmidon.api.TaskException;
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant:data-type name="and-selector"
* @ant:type type="v-file-selector" name="and"
*/
public class AndFileSelector


+ 0
- 1
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/BaseNameFileSelector.java View File

@@ -15,7 +15,6 @@ import org.apache.aut.vfs.FileObject;
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant:data-type name="basename-selector"
* @ant:type type="v-file-selector" name="basename"
*/
public class BaseNameFileSelector


+ 48
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/ConditionSelector.java View File

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

+ 0
- 1
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/ExistenceFileSelector.java View File

@@ -19,7 +19,6 @@ import org.apache.myrmidon.api.TaskException;
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant:data-type name="exists-selector"
* @ant:type type="v-file-selector" name="exists"
*/
public class ExistenceFileSelector


+ 64
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/FileTestCondition.java View File

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

+ 1
- 2
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsEmptyFolderSelector.java View File

@@ -20,8 +20,7 @@ import org.apache.myrmidon.api.TaskException;
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @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


+ 0
- 1
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsFileSelector.java View File

@@ -20,7 +20,6 @@ import org.apache.myrmidon.api.TaskException;
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant:data-type name="is-file-selector"
* @ant:type type="v-file-selector" name="is-file"
*/
public class IsFileSelector


+ 0
- 1
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/IsFolderSelector.java View File

@@ -20,7 +20,6 @@ import org.apache.myrmidon.api.TaskException;
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant:data-type name="is-folder-selector"
* @ant:type type="v-file-selector" name="is-folder"
*/
public class IsFolderSelector


+ 12
- 1
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/NameFileSelector.java View File

@@ -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 <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @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;
}
}

+ 7
- 2
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/NotFileSelector.java View File

@@ -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 <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @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 );
}


+ 0
- 1
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/OrFileSelector.java View File

@@ -20,7 +20,6 @@ import org.apache.myrmidon.api.TaskException;
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant:data-type name="or-selector"
* @ant:type type="v-file-selector" name="or"
*/
public class OrFileSelector


+ 9
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/Resources.properties View File

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

+ 0
- 1
proposal/myrmidon/src/java/org/apache/antlib/vfile/selectors/UrlFileSelector.java View File

@@ -15,7 +15,6 @@ import org.apache.aut.vfs.FileObject;
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant:data-type name="url-selector"
* @ant:type type="v-file-selector" name="url"
*/
public class UrlFileSelector


+ 1
- 1
proposal/myrmidon/src/xdocs/vfs.xml View File

@@ -167,7 +167,7 @@

<p>Selects files that exist.</p>

<h3><code>&lt;is-empty&gt;</code></h3>
<h3><code>&lt;is-empty-folder&gt;</code></h3>

<p>Selects empty folders, that is, folders that have no children.</p>



Loading…
Cancel
Save