Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 91525 invoked from network); 27 Feb 2002 12:05:54 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 27 Feb 2002 12:05:54 -0000 Received: (qmail 15709 invoked by uid 97); 27 Feb 2002 12:05:38 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 15693 invoked by uid 97); 27 Feb 2002 12:05:38 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 15682 invoked by uid 97); 27 Feb 2002 12:05:37 -0000 Date: 27 Feb 2002 12:05:37 -0000 Message-ID: <20020227120537.5130.qmail@icarus.apache.org> From: adammurdoch@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile AbstractNameFileSelector.java AndFileSelector.java BaseNameFileSelector.java DefaultFileSet.java ExistenceFileSelector.java FileSelector.java FilteredFileList.java FlatFileSet.java IsDirectorySelector.java IsFileSelector.java ListFileSetTask.java NameFileSelector.java NotFileSelector.java OrFileSelector.java UrlFileSelector.java CopyFilesTask.java DefaultFileList.java FileList.java FileSet.java ListFilesTask.java PathFileList.java Resources.properties SingletonFileList.java PatternFileSet.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N adammurdoch 02/02/27 04:05:37 Modified: proposal/myrmidon/src/java/org/apache/antlib/vfile CopyFilesTask.java DefaultFileList.java FileList.java FileSet.java ListFilesTask.java PathFileList.java Resources.properties SingletonFileList.java Added: proposal/myrmidon/lib jakarta-oro-2.0.5.jar proposal/myrmidon/src/java/org/apache/antlib/vfile AbstractNameFileSelector.java AndFileSelector.java BaseNameFileSelector.java DefaultFileSet.java ExistenceFileSelector.java FileSelector.java FilteredFileList.java FlatFileSet.java IsDirectorySelector.java IsFileSelector.java ListFileSetTask.java NameFileSelector.java NotFileSelector.java OrFileSelector.java UrlFileSelector.java Removed: proposal/myrmidon/src/java/org/apache/antlib/vfile PatternFileSet.java Log: Changes to the VFS data types: * Added FileSelector interface. * now takes file selectors, instead of include and exclude patterns. * Added a bunch of file selector implementations: * , , for combining selectors. * , , for testing bits of the file name against an Ant 1 style pattern, or a regular expression. * , , for testing file type. * Added , which combines nested file sets and paths into a single directory. This allows explicit path -> fileset conversion. * Added , which applies selectors to nested file sets and paths. * Added debug task. Revision Changes Path 1.1 jakarta-ant/proposal/myrmidon/lib/jakarta-oro-2.0.5.jar <> 1.2 +8 -0 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/CopyFilesTask.java Index: CopyFilesTask.java =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/CopyFilesTask.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CopyFilesTask.java 21 Feb 2002 03:26:23 -0000 1.1 +++ CopyFilesTask.java 27 Feb 2002 12:05:36 -0000 1.2 @@ -13,6 +13,7 @@ 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 @@ * A task that copies files. * * @author Adam Murdoch + * * @ant:task name="v-copy" */ public class CopyFilesTask @@ -120,6 +122,12 @@ final String path = paths[ i ]; // 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 1.2 +2 -0 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileList.java Index: DefaultFileList.java =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileList.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DefaultFileList.java 21 Feb 2002 03:26:23 -0000 1.1 +++ DefaultFileList.java 27 Feb 2002 12:05:36 -0000 1.2 @@ -18,7 +18,9 @@ * 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 { 1.2 +1 -0 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileList.java Index: FileList.java =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileList.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FileList.java 21 Feb 2002 03:26:23 -0000 1.1 +++ FileList.java 27 Feb 2002 12:05:36 -0000 1.2 @@ -16,6 +16,7 @@ * An ordered list of files. * * @author Adam Murdoch + * * @ant:role shorthand="v-path" */ public interface FileList 1.2 +3 -1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSet.java Index: FileSet.java =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FileSet.java 21 Feb 2002 03:26:23 -0000 1.1 +++ FileSet.java 27 Feb 2002 12:05:36 -0000 1.2 @@ -16,6 +16,7 @@ * with it. * * @author Adam Murdoch + * * @ant:role shorthand="v-fileset" */ public interface FileSet @@ -30,5 +31,6 @@ * @throws TaskException * On error building the set. */ - FileSetResult getResult( TaskContext context ) throws TaskException; + FileSetResult getResult( TaskContext context ) + throws TaskException; } 1.2 +2 -2 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFilesTask.java Index: ListFilesTask.java =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFilesTask.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ListFilesTask.java 25 Feb 2002 11:09:09 -0000 1.1 +++ ListFilesTask.java 27 Feb 2002 12:05:36 -0000 1.2 @@ -15,9 +15,9 @@ * A debug task, which prints out the files in a file list. * * @author Adam Murdoch - * @version $Revision: 1.1 $ $Date: 2002/02/25 11:09:09 $ + * @version $Revision: 1.2 $ $Date: 2002/02/27 12:05:36 $ * - * @ant:task name="v-list-files" + * @ant:task name="v-list-path" */ public class ListFilesTask extends AbstractTask 1.2 +1 -1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/PathFileList.java Index: PathFileList.java =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/PathFileList.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PathFileList.java 21 Feb 2002 03:26:23 -0000 1.1 +++ PathFileList.java 27 Feb 2002 12:05:36 -0000 1.2 @@ -48,7 +48,7 @@ String element = elements[ i ]; try { - result[ i ] = fileSystemManager.resolveFile( element ); + result[ i ] = fileSystemManager.resolveFile( context.getBaseDirectory(), element ); } catch( FileSystemException e ) { 1.2 +10 -0 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/Resources.properties Index: Resources.properties =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/Resources.properties,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Resources.properties 21 Feb 2002 03:26:23 -0000 1.1 +++ Resources.properties 27 Feb 2002 12:05:36 -0000 1.2 @@ -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. 1.2 +4 -1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/SingletonFileList.java Index: SingletonFileList.java =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/SingletonFileList.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SingletonFileList.java 21 Feb 2002 03:26:23 -0000 1.1 +++ SingletonFileList.java 27 Feb 2002 12:05:36 -0000 1.2 @@ -15,9 +15,12 @@ * 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; 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/AbstractNameFileSelector.java Index: AbstractNameFileSelector.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ */ 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 ); } 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/AndFileSelector.java Index: AndFileSelector.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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; } } 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/BaseNameFileSelector.java Index: BaseNameFileSelector.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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(); } } 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/DefaultFileSet.java Index: DefaultFileSet.java =================================================================== /* * 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.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.TaskContext; import org.apache.myrmidon.api.TaskException; /** * A file set, that contains those files under a directory that match * a set of selectors. * * @author Adam Murdoch * * @ant:data-type name="v-fileset" * @ant:type type="v-fileset" name="v-fileset" */ public class DefaultFileSet implements FileSet { private final static Resources REZ = ResourceManager.getPackageResources( DefaultFileSet.class ); private FileObject m_dir; private final AndFileSelector m_selector = new AndFileSelector(); /** * Sets the root directory. */ public void setDir( final FileObject dir ) { m_dir = dir; } /** * Adds a selector. */ public void add( final FileSelector selector ) { m_selector.add( selector ); } /** * Returns the contents of the set. */ public FileSetResult getResult( final TaskContext context ) throws TaskException { if( m_dir == null ) { final String message = REZ.getString( "fileset.dir-not-set.error" ); throw new TaskException( message ); } try { final DefaultFileSetResult result = new DefaultFileSetResult(); final ArrayList stack = new ArrayList(); final ArrayList pathStack = new ArrayList(); stack.add( m_dir ); pathStack.add( "" ); while( stack.size() > 0 ) { // Pop next folder off the stack FileObject folder = (FileObject)stack.remove( 0 ); String path = (String)pathStack.remove( 0 ); // Queue the children of the folder FileObject[] children = folder.getChildren(); for( int i = 0; i < children.length; i++ ) { FileObject child = children[ i ]; String childPath = path + child.getName().getBaseName(); // Check whether to include the file in the result if( m_selector.accept( child, childPath, context ) ) { result.addElement( child, childPath ); } if( child.getType() == FileType.FOLDER ) { // A folder - push it on to the stack stack.add( 0, child ); pathStack.add( 0, childPath + '/' ); } } } return result; } catch( FileSystemException e ) { final String message = REZ.getString( "fileset.list-files.error", m_dir ); throw new TaskException( message, e ); } } } 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/ExistenceFileSelector.java Index: ExistenceFileSelector.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSelector.java Index: FileSelector.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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; } 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/FilteredFileList.java Index: FilteredFileList.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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() ] ); } } 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/FlatFileSet.java Index: FlatFileSet.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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; } } 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/IsDirectorySelector.java Index: IsDirectorySelector.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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 ); } } } 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/IsFileSelector.java Index: IsFileSelector.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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 ); } } } 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFileSetTask.java Index: ListFileSetTask.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/NameFileSelector.java Index: NameFileSelector.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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; } } 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/NotFileSelector.java Index: NotFileSelector.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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 ); } } 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/OrFileSelector.java Index: OrFileSelector.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/vfile/UrlFileSelector.java Index: UrlFileSelector.java =================================================================== /* * 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: 1.1 $ $Date: 2002/02/27 12:05:36 $ * * @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(); } } -- To unsubscribe, e-mail: For additional commands, e-mail: