ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors AbstractNameFileSelector.java AndFileSelector.java BaseNameFileSelector.java ConditionSelector.java ExistenceFileSelector.java FileSelector.java FileTestCondition.java IsEmptyFolderSelector.java IsFileSelector.java IsFolderSelector.java NameFileSelector.java NotFileSelector.java OrFileSelector.java Resources.properties UrlFileSelector.java
Date Sun, 14 Apr 2002 10:56:20 GMT
donaldp     02/04/14 03:56:20

  Added:       antlib/src/java/org/apache/antlib/vfile CopyFilesTask.java
                        DefaultFileList.java DefaultFileSet.java
                        DefaultFileSetResult.java FileList.java
                        FileSet.java FileSetAdaptor.java FileSetResult.java
                        FileSetToFileListConverter.java
                        FilteredFileList.java FlatFileSet.java
                        ListFileSetTask.java ListFilesTask.java
                        MappedFileSet.java PathFileList.java
                        Resources.properties SingletonFileList.java
                        StringToFileObjectConverter.java
               antlib/src/java/org/apache/antlib/vfile/selectors
                        AbstractNameFileSelector.java AndFileSelector.java
                        BaseNameFileSelector.java ConditionSelector.java
                        ExistenceFileSelector.java FileSelector.java
                        FileTestCondition.java IsEmptyFolderSelector.java
                        IsFileSelector.java IsFolderSelector.java
                        NameFileSelector.java NotFileSelector.java
                        OrFileSelector.java Resources.properties
                        UrlFileSelector.java
  Log:
  Add the vfile suite of tasks.
  
  Revision  Changes    Path
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/CopyFilesTask.java
  
  Index: CopyFilesTask.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 java.util.Iterator;
  import org.apache.aut.vfs.FileObject;
  import org.apache.aut.vfs.FileSystemException;
  import org.apache.aut.vfs.FileType;
  import org.apache.aut.vfs.NameScope;
  import org.apache.aut.vfs.FileConstants;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.myrmidon.api.AbstractTask;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * A task that copies files.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   *
   * @ant.task name="v-copy"
   */
  public class CopyFilesTask
      extends AbstractTask
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( CopyFilesTask.class );
  
      private FileObject m_srcFile;
      private FileObject m_destFile;
      private FileObject m_destDir;
      private ArrayList m_fileSets = new ArrayList();
  
      /**
       * Sets the source file.
       */
      public void setSrcfile( final FileObject file )
      {
          m_srcFile = file;
      }
  
      /**
       * Sets the destination file.
       */
      public void setDestfile( final FileObject file )
      {
          m_destFile = file;
      }
  
      /**
       * Sets the destination directory.
       */
      public void setDestdir( final FileObject file )
      {
          m_destDir = file;
      }
  
      /**
       * Sets the source directory.
       */
      public void setSrcdir( final FileObject dir )
      {
          add( new DefaultFileSet( dir ) );
      }
  
      /**
       * Adds a source file set.
       */
      public void add( final FileSet fileset )
      {
          m_fileSets.add( fileset );
      }
  
      /**
       * Execute task.
       * This method is called to perform actual work associated with task.
       * It is called after Task has been Configured and Initialized and before
       * beig Disposed (If task implements appropriate interfaces).
       *
       * @exception TaskException if an error occurs
       */
      public void execute()
          throws TaskException
      {
          if( m_srcFile == null && m_fileSets.size() == 0 )
          {
              final String message = REZ.getString( "copyfilestask.no-source.error", getContext().getName() );
              throw new TaskException( message );
          }
          if( m_destFile == null && m_destDir == null )
          {
              final String message = REZ.getString( "copyfilestask.no-destination.error", getContext().getName() );
              throw new TaskException( message );
          }
          if( m_fileSets.size() > 0 && m_destDir == null )
          {
              final String message = REZ.getString( "copyfilestask.no-destination-dir.error", getContext().getName() );
              throw new TaskException( message );
          }
  
          try
          {
              // Copy the source file across
              if( m_srcFile != null )
              {
                  if( m_destFile == null )
                  {
                      m_destFile = m_destDir.resolveFile( m_srcFile.getName().getBaseName() );
                  }
  
                  getContext().verbose( "copy " + m_srcFile + " to " + m_destFile );
                  m_destFile.copyFrom( m_srcFile, FileConstants.SELECT_SELF );
              }
  
              // Copy the contents of the filesets across
              for( Iterator iterator = m_fileSets.iterator(); iterator.hasNext(); )
              {
                  FileSet fileset = (FileSet)iterator.next();
                  FileSetResult result = fileset.getResult( getContext() );
                  final FileObject[] files = result.getFiles();
                  final String[] paths = result.getPaths();
                  for( int i = 0; i < files.length; i++ )
                  {
                      final FileObject srcFile = files[ i ];
                      final String path = paths[ i ];
  
                      // TODO - map destination name
  
                      // TODO - maybe include empty dirs
                      if( srcFile.getType() != FileType.FILE )
                      {
                          continue;
                      }
  
                      // Locate the destination file
                      final FileObject destFile = m_destDir.resolveFile( path, NameScope.DESCENDENT );
  
                      // Copy the file across
                      getContext().verbose( "copy " + srcFile + " to " + destFile );
                      destFile.copyFrom( srcFile, FileConstants.SELECT_SELF );
                  }
              }
          }
          catch( FileSystemException e )
          {
              throw new TaskException( e.getMessage(), e );
          }
      }
  
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/DefaultFileList.java
  
  Index: DefaultFileList.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 java.util.Iterator;
  import java.util.List;
  import org.apache.aut.vfs.FileObject;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * A compound file list, which is made up of several other file lists.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   *
   * @ant.data-type name="v-path"
   * @ant.type type="v-path" name="v-path"
   */
  public class DefaultFileList implements FileList
  {
      private final List m_elements = new ArrayList();
  
      /**
       * Adds a single file to this list.
       */
      public void addLocation( final FileObject file )
      {
          final SingletonFileList element = new SingletonFileList();
          element.setFile( file );
          m_elements.add( element );
      }
  
      /**
       * Adds a path to this list.
       */
      public void addPath( final String pathStr )
      {
          final PathFileList path = new PathFileList();
          path.setPath( pathStr );
          m_elements.add( path );
      }
  
      /**
       * Adds a file list to this list.
       */
      public void add( final FileList list )
      {
          m_elements.add( list );
      }
  
      /**
       * Returns the list of files.
       */
      public FileObject[] listFiles( TaskContext context ) throws TaskException
      {
          // Collect the files from all elements
          final ArrayList allFiles = new ArrayList();
          for( Iterator iterator = m_elements.iterator(); iterator.hasNext(); )
          {
              FileList fileList = (FileList)iterator.next();
              FileObject[] files = fileList.listFiles( context );
              for( int i = 0; i < files.length; i++ )
              {
                  FileObject file = files[ i ];
                  allFiles.add( file );
              }
          }
  
          // Convert to array
          return (FileObject[])allFiles.toArray( new FileObject[ allFiles.size() ] );
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/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.antlib.vfile.selectors.AndFileSelector;
  import org.apache.antlib.vfile.selectors.FileSelector;
  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 <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   *
   * @ant.data-type name="v-fileset"
   * @ant.type type="v-fileset" name="v-fileset"
   */
  public class DefaultFileSet
      implements FileSet
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( DefaultFileSet.class );
  
      private FileObject m_dir;
      private final AndFileSelector m_selector = new AndFileSelector();
  
      public DefaultFileSet()
      {
      }
  
      public DefaultFileSet( final FileObject dir )
      {
          m_dir = dir;
      }
  
      /**
       * 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-myrmidon/antlib/src/java/org/apache/antlib/vfile/DefaultFileSetResult.java
  
  Index: DefaultFileSetResult.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 java.util.List;
  import org.apache.aut.vfs.FileObject;
  
  /**
   * An implementation of a file set result.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public class DefaultFileSetResult
      implements FileSetResult
  {
      private List m_files = new ArrayList();
      private List m_paths = new ArrayList();
  
      /**
       * Adds an element to the result.
       */
      public void addElement( final FileObject file,
                              final String path )
      {
          m_files.add( file );
          m_paths.add( path );
      }
  
      /**
       * Returns the files in the result.
       */
      public FileObject[] getFiles()
      {
          return (FileObject[])m_files.toArray( new FileObject[ m_files.size() ] );
      }
  
      /**
       * Returns the virtual paths of the files.
       */
      public String[] getPaths()
      {
          return (String[])m_paths.toArray( new String[ m_paths.size() ] );
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/FileList.java
  
  Index: FileList.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;
  
  /**
   * An ordered list of files.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   *
   * @ant:role shorthand="v-path"
   */
  public interface FileList
      extends DataType
  {
      /**
       * Returns the files in the list.
       *
       * @param context
       *      The context to use to build the list of files.
       *
       * @throws TaskException
       *      On error building the list of files.
       */
      FileObject[] listFiles( TaskContext context ) throws TaskException;
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/FileSet.java
  
  Index: FileSet.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.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.framework.DataType;
  
  /**
   * A set of files, where each file in the list has a virtual path associated
   * with it.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   *
   * @ant:role shorthand="v-fileset"
   */
  public interface FileSet
      extends DataType
  {
      /**
       * Returns the contents of the set.
       *
       * @param context
       *      The context to use to build the set.
       *
       * @throws TaskException
       *      On error building the set.
       */
      FileSetResult getResult( TaskContext context )
          throws TaskException;
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/FileSetAdaptor.java
  
  Index: FileSetAdaptor.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;
  
  /**
   * An adaptor from a {@link FileSet} to a {@link FileList}.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:56:19 $
   */
  public class FileSetAdaptor
      implements FileList
  {
      private final FileSet m_fileset;
  
      public FileSetAdaptor( final FileSet fileset )
      {
          m_fileset = fileset;
      }
  
      /**
       * Returns the files in the list.
       */
      public FileObject[] listFiles( TaskContext context )
          throws TaskException
      {
          final FileSetResult result = m_fileset.getResult( context );
          return result.getFiles();
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/FileSetResult.java
  
  Index: FileSetResult.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;
  
  /**
   * The contents of a {@link FileSet}.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public interface FileSetResult
  {
      /**
       * Returns the files in the result.
       */
      FileObject[] getFiles();
  
      /**
       * Returns the virtual paths of the files.
       */
      String[] getPaths();
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/FileSetToFileListConverter.java
  
  Index: FileSetToFileListConverter.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.converter.AbstractConverter;
  import org.apache.aut.converter.ConverterException;
  
  /**
   * A converter from {@link FileSet} to {@link FileList}.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @ant.converter source="org.apache.antlib.vfile.FileSet"
   *                destination="org.apache.antlib.vfile.FileList"
   */
  public class FileSetToFileListConverter
      extends AbstractConverter
  {
      public FileSetToFileListConverter()
      {
          super( FileSet.class, FileList.class );
      }
  
      /**
       * Do the conversion.
       */
      protected Object convert( final Object original, final Object context )
          throws ConverterException
      {
          final FileSet src = (FileSet)original;
          return new FileSetAdaptor( src );
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/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.antlib.vfile.selectors.AndFileSelector;
  import org.apache.antlib.vfile.selectors.FileSelector;
  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: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @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 setFilter( 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-myrmidon/antlib/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 <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @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-myrmidon/antlib/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 java.util.ArrayList;
  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: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @ant.task name="v-list-fileset"
   */
  public class ListFileSetTask
      extends AbstractTask
  {
      private final ArrayList m_fileSets = new ArrayList();
  
      public void add( final FileSet fileSet )
      {
          m_fileSets.add( fileSet );
      }
  
      /**
       * Execute task.
       */
      public void execute()
          throws TaskException
      {
          final int count = m_fileSets.size();
          for( int i = 0; i < count; i++ )
          {
              final FileSet fileSet = (FileSet)m_fileSets.get(i );
              FileSetResult result = fileSet.getResult( getContext() );
              final FileObject[] files = result.getFiles();
              final String[] paths = result.getPaths();
              for( int j = 0; j < files.length; j++ )
              {
                  final FileObject file = files[ j ];
                  final String path = paths[ j ];
                  getContext().info( path + " = " + file );
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/ListFilesTask.java
  
  Index: ListFilesTask.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, which prints out the files in a file list.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @ant.task name="v-list-path"
   */
  public class ListFilesTask
      extends AbstractTask
  {
      private final DefaultFileList m_files = new DefaultFileList();
  
      public void add( final FileList files )
      {
          m_files.add( files );
      }
  
      /**
       * Execute task.
       *
       * @exception TaskException if an error occurs
       */
      public void execute()
          throws TaskException
      {
          final FileObject[] files = m_files.listFiles( getContext() );
          for( int i = 0; i < files.length; i++ )
          {
              FileObject file = files[ i ];
              getContext().info( file.toString() );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/MappedFileSet.java
  
  Index: MappedFileSet.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;
  import org.apache.myrmidon.framework.ChainFileNameMapper;
  
  /**
   * A fileset that maps another fileset.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @ant.data-type name="mapped-fileset"
   */
  public class MappedFileSet
      implements FileSet
  {
      private final ArrayList m_filesets = new ArrayList();
      private ChainFileNameMapper m_mapper = new ChainFileNameMapper();
  
      /**
       * Sets the mapper to use.
       */
      public void setMapper( final ChainFileNameMapper mapper )
      {
          m_mapper.add( mapper );
      }
  
      /**
       * Sets the fileset to map.
       */
      public void add( final FileSet fileset )
      {
          m_filesets.add( fileset );
      }
  
      /**
       * Returns the contents of the set.
       */
      public FileSetResult getResult( final TaskContext context )
          throws TaskException
      {
          final DefaultFileSetResult result = new DefaultFileSetResult();
  
          // Map each source fileset.
          final int count = m_filesets.size();
          for( int i = 0; i < count; i++ )
          {
              final FileSet fileSet = (FileSet)m_filesets.get(i );
              mapFileSet( fileSet, result, context );
          }
  
          return result;
      }
  
      /**
       * Maps the contents of a fileset.
       */
      private void mapFileSet( final FileSet fileset,
                               final DefaultFileSetResult result,
                               final TaskContext context )
          throws TaskException
      {
          // Build the result from the nested fileset
          FileSetResult origResult = fileset.getResult( context );
          final FileObject[] files = origResult.getFiles();
          final String[] paths = origResult.getPaths();
  
          // Map each element of the result
          for( int i = 0; i < files.length; i++ )
          {
              final FileObject file = files[ i ];
              final String path = paths[ i ];
              String[] newPaths = m_mapper.mapFileName( path, context );
              if( newPaths == null )
              {
                  continue;
              }
              for( int j = 0; j < newPaths.length; j++ )
              {
                  String newPath = newPaths[j ];
                  result.addElement( file, newPath );
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/PathFileList.java
  
  Index: PathFileList.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.FileSystemManager;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.tools.todo.util.FileUtils;
  
  /**
   * A path made up of file names separated by ; and : characters.  Similar to
   * a CLASSPATH or PATH environment variable.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public class PathFileList implements FileList
  {
      private String m_path;
  
      /**
       * Sets the path to use for this file list.
       */
      public void setPath( final String path )
      {
          m_path = path;
      }
  
      /**
       * Returns the list of files.
       */
      public FileObject[] listFiles( final TaskContext context )
          throws TaskException
      {
          FileSystemManager fileSystemManager = (FileSystemManager)context.getService( FileSystemManager.class );
  
          // TODO - move parsing to the VFS
          final String[] elements = FileUtils.parsePath( m_path );
          final FileObject[] result = new FileObject[ elements.length ];
          for( int i = 0; i < elements.length; i++ )
          {
              String element = elements[ i ];
              try
              {
                  result[ i ] = fileSystemManager.resolveFile( context.getBaseDirectory(), element );
              }
              catch( FileSystemException e )
              {
                  throw new TaskException( e.getMessage(), e );
              }
          }
  
          return result;
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  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.
  
  filteredfilelist.no-selector.error=No filter criteria specified.
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/SingletonFileList.java
  
  Index: SingletonFileList.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 list that contains a single file.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   *
   */
  public class SingletonFileList
      implements FileList
  {
      private FileObject m_file;
  
      /**
       * Sets the file to use for tils file list.
       */
      public void setFile( final FileObject file )
      {
          m_file = file;
      }
  
      /**
       * Returns the list of files.
       */
      public FileObject[] listFiles( TaskContext context ) throws TaskException
      {
          return new FileObject[]{m_file};
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/StringToFileObjectConverter.java
  
  Index: StringToFileObjectConverter.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.converter.AbstractConverter;
  import org.apache.aut.converter.ConverterException;
  import org.apache.aut.vfs.FileObject;
  import org.apache.aut.vfs.FileSystemManager;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.myrmidon.api.TaskContext;
  
  /**
   * Converts a String to a {@link FileObject}
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @ant.converter source="java.lang.String" destination="org.apache.aut.vfs.FileObject"
   */
  public class StringToFileObjectConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToFileObjectConverter.class );
  
      public StringToFileObjectConverter()
      {
          super( String.class, FileObject.class );
      }
  
      /**
       * Converts a String into a FileObject.
       */
      protected Object convert( final Object original, final Object context )
          throws ConverterException
      {
          final String uri = (String)original;
          final TaskContext taskContext = (TaskContext)context;
  
          try
          {
              final FileSystemManager manager =
                  (FileSystemManager)taskContext.getService( FileSystemManager.class );
  
              // TODO - change TaskContext.getBaseDirectory() to return a FileObject
              return manager.resolveFile( taskContext.getBaseDirectory(), uri );
          }
          catch( Exception e )
          {
              final String message = REZ.getString( "bad-convert-string-to-file.error", uri );
              throw new ConverterException( message, e );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/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.selectors;
  
  import org.apache.aut.vfs.FileObject;
  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.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;
  
  /**
   * An abstract file selector that selects files based on name.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:56:19 $
   */
  public abstract class AbstractNameFileSelector
      implements FileSelector
  {
      private static final 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 )
          throws TaskException;
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/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.selectors;
  
  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: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @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-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/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.selectors;
  
  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: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @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-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/ConditionSelector.java
  
  Index: ConditionSelector.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.selectors;
  
  import org.apache.aut.vfs.FileObject;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.framework.conditions.AndCondition;
  import org.apache.myrmidon.framework.conditions.Condition;
  
  /**
   * A file selector that evaluates a set of nested {@link Condition} elements.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @ant.type type="v-file-selector" name="condition"
   */
  public class ConditionSelector
      implements FileSelector
  {
      private AndCondition m_condition = new AndCondition();
  
      /**
       * Adds a condition.
       */
      public void add( final Condition condition )
      {
          m_condition.add( condition );
      }
  
      /**
       * Accepts a file.
       */
      public boolean accept( final FileObject file,
                             final String path,
                             final TaskContext context )
          throws TaskException
      {
          return m_condition.evaluate( context );
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/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.selectors;
  
  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: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @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-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/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.selectors;
  
  import org.apache.aut.vfs.FileObject;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * Accepts files as part of a set.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @ant:role shorthand="v-file-selector"
   */
  public interface FileSelector
  {
      /**
       * 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-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/FileTestCondition.java
  
  Index: FileTestCondition.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.selectors;
  
  import org.apache.aut.vfs.FileObject;
  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.conditions.Condition;
  
  /**
   * A condition that applies a set of file selectors to a file.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @ant.type type="condition" name="file-test"
   */
  public class FileTestCondition
      implements Condition
  {
      private static final Resources REZ
          = ResourceManager.getPackageResources( FileTestCondition.class );
  
      private FileObject m_file;
      private AndFileSelector m_selector = new AndFileSelector();
  
      /**
       * Sets the file to test.
       */
      public void setFile( final FileObject file )
      {
          m_file = file;
      }
  
      /**
       * Adds a selector.
       */
      public void add( final FileSelector selector )
      {
          m_selector.add( selector );
      }
  
      /**
       * Evaluates this condition.
       */
      public boolean evaluate( final TaskContext context )
          throws TaskException
      {
          if( m_file == null )
          {
              final String message = REZ.getString( "filetestcondition.no-file.error" );
              throw new TaskException( message );
          }
          return m_selector.accept( m_file, null, context );
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/IsEmptyFolderSelector.java
  
  Index: IsEmptyFolderSelector.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.selectors;
  
  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 that selects empty directories.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @ant.type type="v-file-selector" name="is-empty-folder"
   */
  public class IsEmptyFolderSelector
      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
                  && file.getChildren().length == 0 );
          }
          catch( FileSystemException e )
          {
              throw new TaskException( e.getMessage(), e );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/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.selectors;
  
  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: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @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-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/IsFolderSelector.java
  
  Index: IsFolderSelector.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.selectors;
  
  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: 1.1 $ $Date: 2002/04/14 10:56:19 $
   *
   * @ant.type type="v-file-selector" name="is-folder"
   */
  public class IsFolderSelector
      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-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/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.selectors;
  
  import org.apache.aut.vfs.FileObject;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * A file selector that selects files based on their name.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:56:20 $
   *
   * @ant.type type="v-file-selector" name="name"
   */
  public class NameFileSelector
      extends AbstractNameFileSelector
  {
      private static final Resources REZ
          = ResourceManager.getPackageResources( NameFileSelector.class );
  
      /**
       * Returns the name to match against.
       */
      protected String getNameForMatch( final String path,
                                        final FileObject file )
          throws TaskException
      {
          if( path == null )
          {
              final String message = REZ.getString( "namefileselector.no-path.error" );
              throw new TaskException( message );
          }
          return path;
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/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.selectors;
  
  import org.apache.aut.vfs.FileObject;
  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 selector that negates a nested file selector.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:56:20 $
   *
   * @ant.type type="v-file-selector" name="not"
   */
  public class NotFileSelector
      implements FileSelector
  {
      private static final Resources REZ
          = ResourceManager.getPackageResources( NotFileSelector.class );
  
      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 )
          {
              final String message = REZ.getString( "notfileselector.no-selector.error" );
              throw new TaskException( message );
          }
          return !m_selector.accept( file, path, context );
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/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.selectors;
  
  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: 1.1 $ $Date: 2002/04/14 10:56:20 $
   *
   * @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-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  nameselector.too-many-patterns.error=Too many name patterns specified.
  nameselector.no-pattern.error=No name pattern specified.
  nameselector.bad-pattern.error=Invalid name pattern "{0}".
  
  notfileselector.no-selector.error=No selector specified.
  
  namefileselector.no-path.error=Cannot use the <name> file selector here.
  
  filetestcondition.no-file.error=No file specified.
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/vfile/selectors/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.selectors;
  
  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: 1.1 $ $Date: 2002/04/14 10:56:20 $
   *
   * @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:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message