diff --git a/proposal/myrmidon/lib/jakarta-oro-2.0.5.jar b/proposal/myrmidon/lib/jakarta-oro-2.0.5.jar new file mode 100644 index 000000000..6eafa4a78 Binary files /dev/null and b/proposal/myrmidon/lib/jakarta-oro-2.0.5.jar differ diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/AbstractNameFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/AbstractNameFileSelector.java new file mode 100644 index 000000000..22d10b883 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/AbstractNameFileSelector.java @@ -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 Adam Murdoch + * @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 ); +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/AndFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/AndFileSelector.java new file mode 100644 index 000000000..dd01cdc14 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/AndFileSelector.java @@ -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 Adam Murdoch + * @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; + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/BaseNameFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/BaseNameFileSelector.java new file mode 100644 index 000000000..fefd426b4 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/BaseNameFileSelector.java @@ -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 Adam Murdoch + * @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(); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/CopyFilesTask.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/CopyFilesTask.java index a28759b36..6cadccba7 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/CopyFilesTask.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/CopyFilesTask.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.Iterator; import org.apache.aut.vfs.FileObject; 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.Resources; import org.apache.myrmidon.api.AbstractTask; @@ -22,6 +23,7 @@ import org.apache.myrmidon.api.TaskException; * A task that copies files. * * @author Adam Murdoch + * * @ant:task name="v-copy" */ public class CopyFilesTask @@ -121,6 +123,12 @@ public class CopyFilesTask // 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 // is a descendent of the dest dir final FileObject destFile = m_destDir.resolveFile( path ); diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileList.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileList.java index b00df8b3f..d8d288a38 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileList.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileList.java @@ -18,7 +18,9 @@ import org.apache.myrmidon.api.TaskException; * A compound file list, which is made up of several other file lists. * * @author Adam Murdoch + * * @ant:data-type name="v-path" + * @ant:type type="v-path" name="v-path" */ public class DefaultFileList implements FileList { diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/PatternFileSet.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileSet.java similarity index 77% rename from proposal/myrmidon/src/java/org/apache/antlib/vfile/PatternFileSet.java rename to proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileSet.java index e624b107b..9fb1e4d6a 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/PatternFileSet.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileSet.java @@ -15,23 +15,24 @@ import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; import org.apache.myrmidon.api.TaskContext; 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 set of patterns. + * a set of selectors. * * @author Adam Murdoch + * * @ant:data-type name="v-fileset" + * @ant:type type="v-fileset" name="v-fileset" */ -public class PatternFileSet - extends AbstractFileSet +public class DefaultFileSet implements FileSet { private final static Resources REZ = - ResourceManager.getPackageResources( PatternFileSet.class ); + ResourceManager.getPackageResources( DefaultFileSet.class ); private FileObject m_dir; + private final AndFileSelector m_selector = new AndFileSelector(); /** * Sets the root directory. @@ -41,6 +42,14 @@ public class PatternFileSet m_dir = dir; } + /** + * Adds a selector. + */ + public void add( final FileSelector selector ) + { + m_selector.add( selector ); + } + /** * Returns the contents of the set. */ @@ -59,7 +68,7 @@ public class PatternFileSet final ArrayList stack = new ArrayList(); final ArrayList pathStack = new ArrayList(); stack.add( m_dir ); - pathStack.add( "." ); + pathStack.add( "" ); while( stack.size() > 0 ) { @@ -72,17 +81,19 @@ public class PatternFileSet for( int i = 0; i < children.length; 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 ); } - else + + if( child.getType() == FileType.FOLDER ) { // A folder - push it on to the stack stack.add( 0, child ); - pathStack.add( 0, childPath ); + pathStack.add( 0, childPath + '/' ); } } } diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/ExistenceFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/ExistenceFileSelector.java new file mode 100644 index 000000000..ad0a15657 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/ExistenceFileSelector.java @@ -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 Adam Murdoch + * @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 ); + } + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileList.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileList.java index 9f0c7e760..2ee4d7e78 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileList.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileList.java @@ -16,6 +16,7 @@ import org.apache.myrmidon.framework.DataType; * An ordered list of files. * * @author Adam Murdoch + * * @ant:role shorthand="v-path" */ public interface FileList diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSelector.java new file mode 100644 index 000000000..7ad5932d2 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSelector.java @@ -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 Adam Murdoch + * @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; +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSet.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSet.java index c56a68930..8bf9ec40b 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSet.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSet.java @@ -16,6 +16,7 @@ import org.apache.myrmidon.framework.DataType; * with it. * * @author Adam Murdoch + * * @ant:role shorthand="v-fileset" */ public interface FileSet @@ -30,5 +31,6 @@ public interface FileSet * @throws TaskException * On error building the set. */ - FileSetResult getResult( TaskContext context ) throws TaskException; + FileSetResult getResult( TaskContext context ) + throws TaskException; } diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FilteredFileList.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FilteredFileList.java new file mode 100644 index 000000000..27386c395 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FilteredFileList.java @@ -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 Adam Murdoch + * @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() ] ); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FlatFileSet.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FlatFileSet.java new file mode 100644 index 000000000..f190c950c --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FlatFileSet.java @@ -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 Adam Murdoch + * @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; + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/IsDirectorySelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/IsDirectorySelector.java new file mode 100644 index 000000000..5a17f2d84 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/IsDirectorySelector.java @@ -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 Adam Murdoch + * @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 ); + } + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/IsFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/IsFileSelector.java new file mode 100644 index 000000000..cc275c051 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/IsFileSelector.java @@ -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 Adam Murdoch + * @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 ); + } + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFileSetTask.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFileSetTask.java new file mode 100644 index 000000000..fa64e9862 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFileSetTask.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; + +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 Adam Murdoch + * @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 ); + } + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFilesTask.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFilesTask.java index 7bea957e3..c313ce3fc 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFilesTask.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFilesTask.java @@ -17,7 +17,7 @@ import org.apache.myrmidon.api.TaskException; * @author Adam Murdoch * @version $Revision$ $Date$ * - * @ant:task name="v-list-files" + * @ant:task name="v-list-path" */ public class ListFilesTask extends AbstractTask diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/NameFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/NameFileSelector.java new file mode 100644 index 000000000..9f498b0df --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/NameFileSelector.java @@ -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 Adam Murdoch + * @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; + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/NotFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/NotFileSelector.java new file mode 100644 index 000000000..ac67fbad2 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/NotFileSelector.java @@ -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 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 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 ); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/OrFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/OrFileSelector.java new file mode 100644 index 000000000..32ba9330e --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/OrFileSelector.java @@ -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 Adam Murdoch + * @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); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/PathFileList.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/PathFileList.java index 5975077f6..12e0cc5fe 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/PathFileList.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/PathFileList.java @@ -48,7 +48,7 @@ public class PathFileList implements FileList String element = elements[ i ]; try { - result[ i ] = fileSystemManager.resolveFile( element ); + result[ i ] = fileSystemManager.resolveFile( context.getBaseDirectory(), element ); } catch( FileSystemException e ) { 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 ccaed603b..ad2489458 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/Resources.properties +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/Resources.properties @@ -1,7 +1,17 @@ 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.list-files.error=Could not list the files in folder "{0}". + 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 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/SingletonFileList.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/SingletonFileList.java index 595be62e7..13fd2ed64 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/SingletonFileList.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/SingletonFileList.java @@ -15,9 +15,12 @@ import org.apache.myrmidon.api.TaskException; * A file list that contains a single file. * * @author Adam Murdoch + * * @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; diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/UrlFileSelector.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/UrlFileSelector.java new file mode 100644 index 000000000..6196831aa --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/UrlFileSelector.java @@ -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 Adam Murdoch + * @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(); + } +}