Browse Source

Changes to the VFS data types:

* Added FileSelector interface.

* <v-fileset> now takes file selectors, instead of include and exclude patterns.

* Added a bunch of file selector implementations:
  * <and>, <or>, <not> for combining selectors.
  * <name>, <basename>, <url> for testing bits of the file name against
    an Ant 1 style pattern, or a regular expression.
  * <is-file>, <is-folder>, <exists> for testing file type.

* Added <flat-fileset>, which combines nested file sets and paths into a
  single directory.  This allows explicit path -> fileset conversion.

* Added <filtered-path>, which applies selectors to nested file sets and paths.

* Added <list-fileset> debug task.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271577 13f79535-47bb-0310-9956-ffa450edef68
master
adammurdoch 23 years ago
parent
commit
dbab858d18
24 changed files with 792 additions and 15 deletions
  1. BIN
      proposal/myrmidon/lib/jakarta-oro-2.0.5.jar
  2. +136
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/AbstractNameFileSelector.java
  3. +57
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/AndFileSelector.java
  4. +32
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/BaseNameFileSelector.java
  5. +8
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/CopyFilesTask.java
  6. +2
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileList.java
  7. +22
    -11
      proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileSet.java
  8. +44
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/ExistenceFileSelector.java
  9. +1
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/FileList.java
  10. +36
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSelector.java
  11. +3
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSet.java
  12. +71
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/FilteredFileList.java
  13. +54
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/FlatFileSet.java
  14. +45
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/IsDirectorySelector.java
  15. +45
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/IsFileSelector.java
  16. +48
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFileSetTask.java
  17. +1
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFilesTask.java
  18. +32
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/NameFileSelector.java
  19. +50
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/NotFileSelector.java
  20. +58
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/OrFileSelector.java
  21. +1
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/PathFileList.java
  22. +10
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/Resources.properties
  23. +4
    -1
      proposal/myrmidon/src/java/org/apache/antlib/vfile/SingletonFileList.java
  24. +32
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/UrlFileSelector.java

BIN
proposal/myrmidon/lib/jakarta-oro-2.0.5.jar View File


+ 136
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/AbstractNameFileSelector.java View File

@@ -0,0 +1,136 @@
/*
* 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;

import org.apache.aut.vfs.FileObject;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.oro.text.GlobCompiler;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;

/**
* An abstract file selector that selects files based on name.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*/
public abstract class AbstractNameFileSelector
implements FileSelector
{
private final static Resources REZ
= ResourceManager.getPackageResources( AbstractNameFileSelector.class );

private Object m_type;
private String m_pattern;

private static final Object TYPE_GLOB = "glob";
private static final Object TYPE_REGEXP = "regexp";

/**
* Sets the GLOB pattern to match the name against.
*/
public void setPattern( final String pattern )
throws TaskException
{
setPattern( TYPE_GLOB, pattern );
}

/**
* Sets the Regexp pattern to match the file basename against.
*/
public void setRegexp( final String pattern )
throws TaskException
{
setPattern( TYPE_REGEXP, pattern );
}

/**
* Sets the pattern and type to match
*/
private void setPattern( final Object type, final String pattern )
throws TaskException
{
if( m_type != null )
{
final String message = REZ.getString( "nameselector.too-many-patterns.error" );
throw new TaskException( message );
}
m_type = type;
m_pattern = pattern;
}

/**
* Accepts the file.
*/
public boolean accept( final FileObject file,
final String path,
final TaskContext context )
throws TaskException
{
if( m_type == null )
{
final String message = REZ.getString( "nameselector.no-pattern.error" );
throw new TaskException( message );
}

// Create the pattern to match against
final Pattern pattern;
try
{
if( m_type == TYPE_GLOB )
{
pattern = createGlobPattern( m_pattern );
}
else
{
pattern = createRegexpPattern( m_pattern );
}
}
catch( MalformedPatternException e )
{
final String message = REZ.getString( "nameselector.bad-pattern.error", m_pattern );
throw new TaskException( message );
}

// Get the name to match against
final String name = getNameForMatch( path, file );

// Compare the name against the pattern
return new Perl5Matcher().matches( name, pattern );
}

/**
* Creates a GLOB pattern for matching the name against.
*/
protected Pattern createGlobPattern( final String pattern )
throws MalformedPatternException
{
// TODO - need to implement Ant-style patterns
return new GlobCompiler().compile( pattern );
}

/**
* Creates a Regexp pattern for matching the name against.
*/
protected Pattern createRegexpPattern( final String pattern )
throws MalformedPatternException
{
return new Perl5Compiler().compile( pattern );
}

/**
* Returns the name to match against.
*/
protected abstract String getNameForMatch( final String path,
final FileObject file );
}

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

@@ -0,0 +1,57 @@
/*
* 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;

import java.util.ArrayList;
import org.apache.aut.vfs.FileObject;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;

/**
* A file selector that performs an AND of nested selectors. Performs
* lazy evaluation. Returns true when no nested elements are supplied.
*
* @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
implements FileSelector
{
private final ArrayList m_selectors = new ArrayList();

/**
* Adds a nested selector.
*/
public void add( final FileSelector selector )
{
m_selectors.add( selector );
}

/**
* Accepts a file.
*/
public boolean accept( final FileObject file,
final String path,
final TaskContext context )
throws TaskException
{
for( int i = 0; i < m_selectors.size(); i++ )
{
final FileSelector fileSelector = (FileSelector)m_selectors.get(i );
if( ! fileSelector.accept( file, path, context ) )
{
return false;
}
}

return true;
}
}

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

@@ -0,0 +1,32 @@
/*
* 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;

import org.apache.aut.vfs.FileObject;

/**
* A file selector that selects files based on their base-name.
*
* @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
extends AbstractNameFileSelector
{
/**
* Returns the name to match against.
*/
protected String getNameForMatch( final String path,
final FileObject file )
{
return file.getName().getBaseName();
}
}

+ 8
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/CopyFilesTask.java View File

@@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import org.apache.aut.vfs.FileObject; import org.apache.aut.vfs.FileObject;
import org.apache.aut.vfs.FileSystemException; import org.apache.aut.vfs.FileSystemException;
import org.apache.aut.vfs.FileType;
import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources; import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.api.AbstractTask; import org.apache.myrmidon.api.AbstractTask;
@@ -22,6 +23,7 @@ import org.apache.myrmidon.api.TaskException;
* A task that copies files. * A task that copies files.
* *
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
*
* @ant:task name="v-copy" * @ant:task name="v-copy"
*/ */
public class CopyFilesTask public class CopyFilesTask
@@ -121,6 +123,12 @@ public class CopyFilesTask


// TODO - map destination name // TODO - map destination name


// TODO - maybe include empty dirs
if( srcFile.getType() != FileType.FILE )
{
continue;
}

// TODO - use scope here, to make sure that the result // TODO - use scope here, to make sure that the result
// is a descendent of the dest dir // is a descendent of the dest dir
final FileObject destFile = m_destDir.resolveFile( path ); final FileObject destFile = m_destDir.resolveFile( path );


+ 2
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileList.java View File

@@ -18,7 +18,9 @@ import org.apache.myrmidon.api.TaskException;
* A compound file list, which is made up of several other file lists. * A compound file list, which is made up of several other file lists.
* *
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
*
* @ant:data-type name="v-path" * @ant:data-type name="v-path"
* @ant:type type="v-path" name="v-path"
*/ */
public class DefaultFileList implements FileList public class DefaultFileList implements FileList
{ {


proposal/myrmidon/src/java/org/apache/antlib/vfile/PatternFileSet.java → proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileSet.java View File

@@ -15,23 +15,24 @@ import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources; import org.apache.avalon.excalibur.i18n.Resources;
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.myrmidon.framework.AbstractFileSet;


/** /**
* A file set, that contains those files under a directory that match * A file set, that contains those files under a directory that match
* a set of patterns.
* a set of selectors.
* *
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
*
* @ant:data-type name="v-fileset" * @ant:data-type name="v-fileset"
* @ant:type type="v-fileset" name="v-fileset"
*/ */
public class PatternFileSet
extends AbstractFileSet
public class DefaultFileSet
implements FileSet implements FileSet
{ {
private final static Resources REZ = private final static Resources REZ =
ResourceManager.getPackageResources( PatternFileSet.class );
ResourceManager.getPackageResources( DefaultFileSet.class );


private FileObject m_dir; private FileObject m_dir;
private final AndFileSelector m_selector = new AndFileSelector();


/** /**
* Sets the root directory. * Sets the root directory.
@@ -41,6 +42,14 @@ public class PatternFileSet
m_dir = dir; m_dir = dir;
} }


/**
* Adds a selector.
*/
public void add( final FileSelector selector )
{
m_selector.add( selector );
}

/** /**
* Returns the contents of the set. * Returns the contents of the set.
*/ */
@@ -59,7 +68,7 @@ public class PatternFileSet
final ArrayList stack = new ArrayList(); final ArrayList stack = new ArrayList();
final ArrayList pathStack = new ArrayList(); final ArrayList pathStack = new ArrayList();
stack.add( m_dir ); stack.add( m_dir );
pathStack.add( "." );
pathStack.add( "" );


while( stack.size() > 0 ) while( stack.size() > 0 )
{ {
@@ -72,17 +81,19 @@ public class PatternFileSet
for( int i = 0; i < children.length; i++ ) for( int i = 0; i < children.length; i++ )
{ {
FileObject child = children[ i ]; FileObject child = children[ i ];
String childPath = path + '/' + child.getName().getBaseName();
if( child.getType() == FileType.FILE )
String childPath = path + child.getName().getBaseName();

// Check whether to include the file in the result
if( m_selector.accept( child, childPath, context ) )
{ {
// A regular file - add it straight to the result
result.addElement( child, childPath ); result.addElement( child, childPath );
} }
else

if( child.getType() == FileType.FOLDER )
{ {
// A folder - push it on to the stack // A folder - push it on to the stack
stack.add( 0, child ); stack.add( 0, child );
pathStack.add( 0, childPath );
pathStack.add( 0, childPath + '/' );
} }
} }
} }

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

@@ -0,0 +1,44 @@
/*
* 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;

import org.apache.aut.vfs.FileObject;
import org.apache.aut.vfs.FileSystemException;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;

/**
* A file selector that only selects files that exist.
*
* @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
implements FileSelector
{
/**
* Accepts a file.
*/
public boolean accept( final FileObject file,
final String path,
final TaskContext context )
throws TaskException
{
try
{
return file.exists();
}
catch( FileSystemException e )
{
throw new TaskException( e.getMessage(), e );
}
}
}

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

@@ -16,6 +16,7 @@ import org.apache.myrmidon.framework.DataType;
* An ordered list of files. * An ordered list of files.
* *
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
*
* @ant:role shorthand="v-path" * @ant:role shorthand="v-path"
*/ */
public interface FileList public interface FileList


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

@@ -0,0 +1,36 @@
/*
* 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;

import org.apache.aut.vfs.FileObject;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.DataType;

/**
* Accepts files as part of a set.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant:role shorthand="v-file-selector"
*/
public interface FileSelector
extends DataType
{
/**
* Accepts a file.
*
* @param path The virtual path associated with the file. May be null
* if such a path is not available.
* @param file The file to select.
* @param context The context to perform the selection in.
*/
boolean accept( FileObject file, String path, TaskContext context )
throws TaskException;
}

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

@@ -16,6 +16,7 @@ import org.apache.myrmidon.framework.DataType;
* with it. * with it.
* *
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
*
* @ant:role shorthand="v-fileset" * @ant:role shorthand="v-fileset"
*/ */
public interface FileSet public interface FileSet
@@ -30,5 +31,6 @@ public interface FileSet
* @throws TaskException * @throws TaskException
* On error building the set. * On error building the set.
*/ */
FileSetResult getResult( TaskContext context ) throws TaskException;
FileSetResult getResult( TaskContext context )
throws TaskException;
} }

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

@@ -0,0 +1,71 @@
/*
* 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;

import java.util.ArrayList;
import org.apache.aut.vfs.FileObject;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;

/**
* A file-list which filters another.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant:data-type name="filtered-path"
* @ant:type type="v-path" name="filtered-path"
*/
public class FilteredFileList
implements FileList
{
private DefaultFileList m_fileList = new DefaultFileList();
private FileSelector m_selector;

/**
* Sets the selector to use to filter with.
*/
public void setCondition( final AndFileSelector selector )
{
m_selector = selector;
}

/**
* Sets the filelist to filter.
*/
public void add( final FileList fileList )
{
m_fileList.add( fileList );
}

/**
* Returns the files in the list.
*/
public FileObject[] listFiles( final TaskContext context )
throws TaskException
{
if( m_selector == null )
{
throw new TaskException( "filteredfilelist.no-selector.error" );
}

// Build the set of files
final ArrayList acceptedFiles = new ArrayList();
final FileObject[] files = m_fileList.listFiles( context );
for( int i = 0; i < files.length; i++ )
{
final FileObject file = files[ i ];
if( m_selector.accept( file, null, context ) )
{
acceptedFiles.add( file );
}
}

return (FileObject[])acceptedFiles.toArray( new FileObject[acceptedFiles.size() ] );
}
}

+ 54
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/FlatFileSet.java View File

@@ -0,0 +1,54 @@
/*
* 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;

import org.apache.aut.vfs.FileObject;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;

/**
* A file set that flattens its contents into a single directory.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant:data-type name="flat-fileset"
* @ant:type type="v-fileset" name="flat-fileset"
*/
public class FlatFileSet
implements FileSet
{
private DefaultFileList m_files = new DefaultFileList();

/**
* Adds a file list to this set.
*/
public void add( final FileList files )
{
m_files.add( files );
}

/**
* Returns the contents of the set.
*/
public FileSetResult getResult( final TaskContext context )
throws TaskException
{
DefaultFileSetResult result = new DefaultFileSetResult();
FileObject[] files = m_files.listFiles( context );
for( int i = 0; i < files.length; i++ )
{
final FileObject file = files[ i ];

// TODO - detect collisions
result.addElement( file, file.getName().getBaseName() );
}

return result;
}
}

+ 45
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/IsDirectorySelector.java View File

@@ -0,0 +1,45 @@
/*
* 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;

import org.apache.aut.vfs.FileObject;
import org.apache.aut.vfs.FileSystemException;
import org.apache.aut.vfs.FileType;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;

/**
* A file selector which only selects folders, not files.
*
* @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 IsDirectorySelector
implements FileSelector
{
/**
* Accepts a file.
*/
public boolean accept( final FileObject file,
final String path,
final TaskContext context )
throws TaskException
{
try
{
return ( file.exists() && file.getType() == FileType.FOLDER );
}
catch( FileSystemException e )
{
throw new TaskException( e.getMessage(), e );
}
}
}

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

@@ -0,0 +1,45 @@
/*
* 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;

import org.apache.aut.vfs.FileObject;
import org.apache.aut.vfs.FileSystemException;
import org.apache.aut.vfs.FileType;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;

/**
* A file selector which only selects files, not folders.
*
* @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
implements FileSelector
{
/**
* Accepts a file.
*/
public boolean accept( final FileObject file,
final String path,
final TaskContext context )
throws TaskException
{
try
{
return ( file.exists() && file.getType() == FileType.FILE );
}
catch( FileSystemException e )
{
throw new TaskException( e.getMessage(), e );
}
}
}

+ 48
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFileSetTask.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;

import org.apache.aut.vfs.FileObject;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;

/**
* A debug task, that lists the contents of a {@link FileSet}.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
* @ant:task name="v-list-fileset"
*/
public class ListFileSetTask
extends AbstractTask
{
private FileSet m_fileSet;

public void set( final FileSet fileSet )
{
m_fileSet = fileSet;
}

/**
* Execute task.
*/
public void execute()
throws TaskException
{
FileSetResult result = m_fileSet.getResult( getContext() );
final FileObject[] files = result.getFiles();
final String[] paths = result.getPaths();
for( int i = 0; i < files.length; i++ )
{
final FileObject file = files[ i ];
final String path = paths[ i ];
getLogger().info( path + " = " + file );
}
}
}

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

@@ -17,7 +17,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:task name="v-list-files"
* @ant:task name="v-list-path"
*/ */
public class ListFilesTask public class ListFilesTask
extends AbstractTask extends AbstractTask


+ 32
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/NameFileSelector.java View File

@@ -0,0 +1,32 @@
/*
* 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;

import org.apache.aut.vfs.FileObject;

/**
* A file selector that selects files based on their name.
*
* @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
{
/**
* Returns the name to match against.
*/
protected String getNameForMatch( final String path,
final FileObject file )
{
return path;
}
}

+ 50
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/NotFileSelector.java View File

@@ -0,0 +1,50 @@
/*
* 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;

import org.apache.aut.vfs.FileObject;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;

/**
* A file selector that negates a nested file selector.
*
* @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 FileSelector m_selector;

/**
* Sets the nested selector.
*/
public void set( final FileSelector selector )
{
m_selector = selector;
}

/**
* Accepts a file.
*/
public boolean accept( final FileObject file,
final String path,
final TaskContext context )
throws TaskException
{
if( m_selector == null )
{
throw new TaskException( "notfileselector.no-selector.error" );
}
return ! m_selector.accept( file, path, context );
}
}

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

@@ -0,0 +1,58 @@
/*
* 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;

import java.util.ArrayList;
import org.apache.aut.vfs.FileObject;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;

/**
* A file selector that performs an OR of nested selectors. Performs
* lazy evaluation. Returns true when no nested elements are supplied.
*
* @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
implements FileSelector
{
private final ArrayList m_selectors = new ArrayList();

/**
* Adds a nested selector.
*/
public void add( final FileSelector selector )
{
m_selectors.add( selector );
}

/**
* Accepts a file.
*/
public boolean accept( final FileObject file,
final String path,
final TaskContext context )
throws TaskException
{
for( int i = 0; i < m_selectors.size(); i++ )
{
final FileSelector fileSelector = (FileSelector)m_selectors.get(i );
if( fileSelector.accept( file, path, context ) )
{
return true;
}
}

// Return true if there are no selectors, false if there are
return (m_selectors.size() == 0);
}
}

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

@@ -48,7 +48,7 @@ public class PathFileList implements FileList
String element = elements[ i ]; String element = elements[ i ];
try try
{ {
result[ i ] = fileSystemManager.resolveFile( element );
result[ i ] = fileSystemManager.resolveFile( context.getBaseDirectory(), element );
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {


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

@@ -1,7 +1,17 @@
bad-convert-string-to-file.error=Could not convert URI "{0}" into a file object. bad-convert-string-to-file.error=Could not convert URI "{0}" into a file object.

fileset.dir-not-set.error=Fileset root directory is not set. fileset.dir-not-set.error=Fileset root directory is not set.
fileset.list-files.error=Could not list the files in folder "{0}". fileset.list-files.error=Could not list the files in folder "{0}".

copyfilestask.no-source.error=No source files specified for {0} task. copyfilestask.no-source.error=No source files specified for {0} task.
copyfilestask.no-destination.error=No destination file or directory specified for {0} task. copyfilestask.no-destination.error=No destination file or directory specified for {0} task.
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.

notfileselector.no-selector.error=No selector specified.

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

@@ -15,9 +15,12 @@ import org.apache.myrmidon.api.TaskException;
* A file list that contains a single file. * A file list that contains a single file.
* *
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
*
* @ant:data-type name="v-file" * @ant:data-type name="v-file"
* @ant:type type="v-path" name="v-file"
*/ */
public class SingletonFileList implements FileList
public class SingletonFileList
implements FileList
{ {
private FileObject m_file; private FileObject m_file;




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

@@ -0,0 +1,32 @@
/*
* 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;

import org.apache.aut.vfs.FileObject;

/**
* A file selector that selects files based on their URL.
*
* @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
extends AbstractNameFileSelector
{
/**
* Returns the name to match against.
*/
protected String getNameForMatch( final String path,
final FileObject file )
{
return file.getName().getURI();
}
}

Loading…
Cancel
Save