ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/launcher Main.java
Date Mon, 04 Mar 2002 02:44:16 GMT
adammurdoch    02/03/03 18:44:15

  Modified:    proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs
                        UpToDate.java
               proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive
                        Tar.java Zip.java
               proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers
                        Javac.java
               proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/rmic
                        DefaultRmicAdapter.java Rmic.java RmicAdapter.java
               proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text
                        Native2Ascii.java
               proposal/myrmidon/src/main/org/apache/tools/ant/types
                        SourceFileScanner.java
               proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers
                        GlobPatternMapper.java IdentityMapper.java
                        MergingMapper.java RegexpPatternMapper.java
               proposal/myrmidon/src/java/org/apache/antlib/file
                        CopyTask.java
               proposal/myrmidon/src/java/org/apache/myrmidon/launcher
                        Main.java
  Added:       proposal/myrmidon/src/java/org/apache/antlib/core
                        ExtFileNameMapper.java FlatFileNameMapper.java
                        PrefixFileNameMapper.java
               proposal/myrmidon/src/java/org/apache/antlib/vfile
                        MappedFileSet.java
               proposal/myrmidon/src/java/org/apache/myrmidon/framework
                        ChainFileNameMapper.java FileNameMapper.java
  Removed:     proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text
                        ExtMapper.java
               proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers
                        FileNameMapper.java FlatFileNameMapper.java
                        Mapper.java MapperType.java
  Log:
  * Moved FileNameMapper to framework.  Got rid of setTo() and setFrom()
    from the interface, as these are no longer needed.
  
  * Changed tasks to accept a FileNameMapper directly, rather than using Mapper.
  
  * Removed the 'flatten' attribute from the <copy> task.
  
  * Removed the 'ext' attribute from the <native2ascii> task.
  
  * Removed Mapper and MapperType.
  
  * Moved <flatten> mapper to antlib.
  
  * Made ExtMapper available as <map-extension> and moved to antlib.
  
  * Added <prefix> mapper, to apply a fixed prefix to names.
  
  * Added <chain> mapper, to apply a chain of mappers to names.
  
  * Added <mapped-fileset>, a fileset that transforms nested filesets using a mapper.
  
  Revision  Changes    Path
  1.23      +32 -37    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/UpToDate.java
  
  Index: UpToDate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/UpToDate.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- UpToDate.java	3 Mar 2002 02:19:10 -0000	1.22
  +++ UpToDate.java	4 Mar 2002 02:44:14 -0000	1.23
  @@ -10,13 +10,13 @@
   import java.io.File;
   import java.util.ArrayList;
   import java.util.Iterator;
  +import org.apache.myrmidon.api.AbstractTask;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.framework.FileNameMapper;
   import org.apache.tools.ant.types.DirectoryScanner;
   import org.apache.tools.ant.types.FileSet;
   import org.apache.tools.ant.types.ScannerUtil;
   import org.apache.tools.ant.types.SourceFileScanner;
  -import org.apache.tools.ant.util.mappers.FileNameMapper;
  -import org.apache.tools.ant.util.mappers.Mapper;
   import org.apache.tools.ant.util.mappers.MergingMapper;
   
   /**
  @@ -29,16 +29,15 @@
    *      hnakamur@mc.neweb.ne.jp</a>
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
    */
  -
  -public class UpToDate extends MatchingTask
  +public class UpToDate
  +    extends AbstractTask
   {
  -    private ArrayList sourceFileSets = new ArrayList();
  -
  -    protected Mapper mapperElement = null;
  +    private final ArrayList m_fileSets = new ArrayList();
  +    private FileNameMapper m_mapper;
   
  -    private String _property;
  -    private File _targetFile;
  -    private String _value;
  +    private String m_property;
  +    private File m_targetFile;
  +    private String m_value;
   
       /**
        * The property to set if the target file is more up to date than each of
  @@ -46,9 +45,9 @@
        *
        * @param property the name of the property to set if Target is up to date.
        */
  -    public void setProperty( String property )
  +    public void setProperty( final String property )
       {
  -        _property = property;
  +        m_property = property;
       }
   
       /**
  @@ -57,9 +56,9 @@
        *
        * @param file the file which we are checking against.
        */
  -    public void setTargetFile( File file )
  +    public void setTargetFile( final File file )
       {
  -        _targetFile = file;
  +        m_targetFile = file;
       }
   
       /**
  @@ -68,9 +67,9 @@
        *
        * @param value the value to set the property to if Target is up to date
        */
  -    public void setValue( String value )
  +    public void setValue( final String value )
       {
  -        _value = value;
  +        m_value = value;
       }
   
       /**
  @@ -78,26 +77,22 @@
        *
        * @param fs The feature to be added to the Srcfiles attribute
        */
  -    public void addSrcfiles( FileSet fs )
  +    public void addSrcfiles( final FileSet fs )
       {
  -        sourceFileSets.add( fs );
  +        m_fileSets.add( fs );
       }
   
       /**
        * Defines the FileNameMapper to use (nested mapper element).
  -     *
  -     * @return Description of the Returned Value
  -     * @exception TaskException Description of Exception
        */
  -    public Mapper createMapper()
  +    public void addMapper( final FileNameMapper mapper )
           throws TaskException
       {
  -        if( mapperElement != null )
  +        if( m_mapper != null )
           {
               throw new TaskException( "Cannot define more than one mapper" );
           }
  -        mapperElement = new Mapper();
  -        return mapperElement;
  +        m_mapper = mapper;
       }
   
       /**
  @@ -108,23 +103,23 @@
       public boolean eval()
           throws TaskException
       {
  -        if( sourceFileSets.size() == 0 )
  +        if( m_fileSets.size() == 0 )
           {
               throw new TaskException( "At least one <srcfiles> element must be set" );
           }
   
  -        if( _targetFile == null && mapperElement == null )
  +        if( m_targetFile == null && m_mapper == null )
           {
               throw new TaskException( "The targetfile attribute or a nested mapper element must be set" );
           }
   
           // if not there then it can't be up to date
  -        if( _targetFile != null && !_targetFile.exists() )
  +        if( m_targetFile != null && !m_targetFile.exists() )
           {
               return false;
           }
   
  -        Iterator enum = sourceFileSets.iterator();
  +        Iterator enum = m_fileSets.iterator();
           boolean upToDate = true;
           while( upToDate && enum.hasNext() )
           {
  @@ -148,12 +143,12 @@
           boolean upToDate = eval();
           if( upToDate )
           {
  -            final String name = _property;
  +            final String name = m_property;
               final Object value = this.getValue();
               getContext().setProperty( name, value );
  -            if( mapperElement == null )
  +            if( m_mapper == null )
               {
  -                getLogger().debug( "File \"" + _targetFile.getAbsolutePath() + "\" is up to date." );
  +                getLogger().debug( "File \"" + m_targetFile.getAbsolutePath() + "\" is up to date." );
               }
               else
               {
  @@ -169,18 +164,18 @@
           setupLogger( scanner );
           FileNameMapper mapper = null;
           File dir = srcDir;
  -        if( mapperElement == null )
  +        if( m_mapper == null )
           {
               MergingMapper mm = new MergingMapper();
  -            mm.setTo( _targetFile.getAbsolutePath() );
  +            mm.setTo( m_targetFile.getAbsolutePath() );
               mapper = mm;
               dir = null;
           }
           else
           {
  -            mapper = mapperElement.getImplementation();
  +            mapper = m_mapper;
           }
  -        return scanner.restrict( files, srcDir, dir, mapper ).length == 0;
  +        return scanner.restrict( files, srcDir, dir, mapper, getContext() ).length == 0;
       }
   
       /**
  @@ -190,6 +185,6 @@
        */
       private String getValue()
       {
  -        return ( _value != null ) ? _value : "true";
  +        return ( m_value != null ) ? m_value : "true";
       }
   }
  
  
  
  1.4       +1 -1      jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Tar.java
  
  Index: Tar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Tar.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Tar.java	6 Feb 2002 13:38:21 -0000	1.3
  +++ Tar.java	4 Mar 2002 02:44:14 -0000	1.4
  @@ -227,7 +227,7 @@
           setupLogger( scanner );
           final MergingMapper mapper = new MergingMapper();
           mapper.setTo( tarFile.getAbsolutePath() );
  -        return scanner.restrict( files, baseDir, null, mapper ).length == 0;
  +        return scanner.restrict( files, baseDir, null, mapper, getContext() ).length == 0;
       }
   
       private void tarFile( final File file,
  
  
  
  1.5       +1 -1      jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Zip.java
  
  Index: Zip.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/archive/Zip.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Zip.java	18 Feb 2002 08:45:07 -0000	1.4
  +++ Zip.java	4 Mar 2002 02:44:14 -0000	1.5
  @@ -483,7 +483,7 @@
               for( int i = 0; i < scanners.length; i++ )
               {
                   if( scanner.restrict( fileNames[ i ], scanners[ i ].getBasedir(), null,
  -                                      mm ).length > 0 )
  +                                      mm, getContext() ).length > 0 )
                   {
                       return false;
                   }
  
  
  
  1.2       +2 -2      jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Javac.java
  
  Index: Javac.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Javac.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Javac.java	3 Mar 2002 06:40:11 -0000	1.1
  +++ Javac.java	4 Mar 2002 02:44:14 -0000	1.2
  @@ -13,11 +13,11 @@
   import org.apache.aut.nativelib.Os;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.framework.JavaVersion;
  +import org.apache.tools.ant.taskdefs.MatchingTask;
   import org.apache.tools.ant.types.DirectoryScanner;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.SourceFileScanner;
   import org.apache.tools.ant.util.mappers.GlobPatternMapper;
  -import org.apache.tools.ant.taskdefs.MatchingTask;
   
   /**
    * Task to compile Java source files. This task can take the following
  @@ -713,7 +713,7 @@
           m.setTo( "*.class" );
           SourceFileScanner sfs = new SourceFileScanner();
           setupLogger( sfs );
  -        File[] newFiles = sfs.restrictAsFiles( files, srcDir, destDir, m );
  +        File[] newFiles = sfs.restrictAsFiles( files, srcDir, destDir, m, getContext() );
   
           if( newFiles.length > 0 )
           {
  
  
  
  1.16      +3 -2      jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java
  
  Index: DefaultRmicAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DefaultRmicAdapter.java	3 Mar 2002 07:11:40 -0000	1.15
  +++ DefaultRmicAdapter.java	4 Mar 2002 02:44:14 -0000	1.16
  @@ -11,11 +11,12 @@
   import java.util.ArrayList;
   import java.util.Random;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.framework.FileNameMapper;
   import org.apache.tools.ant.types.Commandline;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.util.FileUtils;
  -import org.apache.tools.ant.util.mappers.FileNameMapper;
   
   /**
    * This is the default implementation for the RmicAdapter interface. Currently,
  @@ -268,7 +269,7 @@
           {
           }
   
  -        public String[] mapFileName( String name )
  +        public String[] mapFileName( String name, TaskContext context )
           {
               if( name == null
                   || !name.endsWith( ".class" )
  
  
  
  1.2       +4 -5      jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/rmic/Rmic.java
  
  Index: Rmic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/rmic/Rmic.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Rmic.java	3 Mar 2002 07:11:40 -0000	1.1
  +++ Rmic.java	4 Mar 2002 02:44:14 -0000	1.2
  @@ -15,13 +15,12 @@
   import java.util.ArrayList;
   import org.apache.avalon.excalibur.io.FileUtil;
   import org.apache.myrmidon.api.TaskException;
  -import org.apache.myrmidon.api.AbstractTask;
  +import org.apache.myrmidon.framework.FileNameMapper;
  +import org.apache.tools.ant.taskdefs.MatchingTask;
   import org.apache.tools.ant.types.DirectoryScanner;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.PathUtil;
   import org.apache.tools.ant.types.SourceFileScanner;
  -import org.apache.tools.ant.util.mappers.FileNameMapper;
  -import org.apache.tools.ant.taskdefs.MatchingTask;
   
   /**
    * Task to compile RMI stubs and skeletons. This task can take the following
  @@ -569,7 +568,7 @@
           {
               final SourceFileScanner scanner = new SourceFileScanner();
               setupLogger( scanner );
  -            newFiles = scanner.restrict( files, baseDir, baseDir, mapper );
  +            newFiles = scanner.restrict( files, baseDir, baseDir, mapper, getContext() );
           }
   
           for( int i = 0; i < newFiles.length; i++ )
  @@ -603,7 +602,7 @@
           String classFileName =
               classname.replace( '.', File.separatorChar ) + ".class";
           String[] generatedFiles =
  -            adapter.getMapper().mapFileName( classFileName );
  +            adapter.getMapper().mapFileName( classFileName, getContext() );
   
           for( int i = 0; i < generatedFiles.length; i++ )
           {
  
  
  
  1.7       +1 -1      jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapter.java
  
  Index: RmicAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RmicAdapter.java	3 Mar 2002 07:11:40 -0000	1.6
  +++ RmicAdapter.java	4 Mar 2002 02:44:14 -0000	1.7
  @@ -8,8 +8,8 @@
   package org.apache.tools.ant.taskdefs.rmic;
   
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.framework.FileNameMapper;
   import org.apache.tools.ant.types.Path;
  -import org.apache.tools.ant.util.mappers.FileNameMapper;
   
   /**
    * The interface that all rmic adapters must adher to. <p>
  
  
  
  1.8       +10 -34    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text/Native2Ascii.java
  
  Index: Native2Ascii.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text/Native2Ascii.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Native2Ascii.java	6 Feb 2002 13:38:22 -0000	1.7
  +++ Native2Ascii.java	4 Mar 2002 02:44:14 -0000	1.8
  @@ -9,13 +9,12 @@
   
   import java.io.File;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.framework.FileNameMapper;
   import org.apache.tools.ant.taskdefs.MatchingTask;
   import org.apache.tools.ant.types.Commandline;
   import org.apache.tools.ant.types.DirectoryScanner;
   import org.apache.tools.ant.types.SourceFileScanner;
  -import org.apache.tools.ant.util.mappers.FileNameMapper;
   import org.apache.tools.ant.util.mappers.IdentityMapper;
  -import org.apache.tools.ant.util.mappers.Mapper;
   
   /**
    * Convert files from native encodings to ascii.
  @@ -30,8 +29,7 @@
       private String m_encoding;// encoding to convert to/from
       private File m_srcDir;// Where to find input files
       private File m_destDir;// Where to put output files
  -    private String m_ext;// Extension of output files if different
  -    private Mapper m_mapper;
  +    private FileNameMapper m_mapper;
   
       /**
        * Set the destination dirctory to place converted files into.
  @@ -56,17 +54,6 @@
       }
   
       /**
  -     * Set the extension which converted files should have. If unset, files will
  -     * not be renamed.
  -     *
  -     * @param ext File extension to use for converted files.
  -     */
  -    public void setExt( final String ext )
  -    {
  -        m_ext = ext;
  -    }
  -
  -    /**
        * Flag the conversion to run in the reverse sense, that is Ascii to Native
        * encoding.
        *
  @@ -89,19 +76,15 @@
   
       /**
        * Defines the FileNameMapper to use (nested mapper element).
  -     *
  -     * @return Description of the Returned Value
  -     * @exception TaskException Description of Exception
        */
  -    public Mapper createMapper()
  +    public void createMapper( final FileNameMapper mapper )
           throws TaskException
       {
           if( m_mapper != null )
           {
               throw new TaskException( "Cannot define more than one mapper" );
           }
  -        m_mapper = new Mapper();
  -        return m_mapper;
  +        m_mapper = mapper;
       }
   
       public void execute()
  @@ -115,7 +98,7 @@
           final SourceFileScanner sfs = new SourceFileScanner();
           setupLogger( sfs );
           final FileNameMapper mapper = buildMapper();
  -        files = sfs.restrict( files, m_srcDir, m_destDir, mapper );
  +        files = sfs.restrict( files, m_srcDir, m_destDir, mapper, getContext() );
           int count = files.length;
           if( count == 0 )
           {
  @@ -129,7 +112,7 @@
   
           for( int i = 0; i < files.length; i++ )
           {
  -            final String name = mapper.mapFileName( files[ i ] )[ 0 ];
  +            final String name = mapper.mapFileName( files[ i ], getContext() )[ 0 ];
               convert( files[ i ], name );
           }
       }
  @@ -140,18 +123,11 @@
           FileNameMapper mapper = null;
           if( m_mapper == null )
           {
  -            if( m_ext == null )
  -            {
  -                mapper = new IdentityMapper();
  -            }
  -            else
  -            {
  -                mapper = new ExtMapper( m_ext );
  -            }
  +            mapper = new IdentityMapper();
           }
           else
           {
  -            mapper = m_mapper.getImplementation();
  +            mapper = m_mapper;
           }
   
           return mapper;
  @@ -169,9 +145,9 @@
           // if src and dest dirs are the same, require the extension
           // to be set, so we don't stomp every file.  One could still
           // include a file with the same extension, but ....
  -        if( m_srcDir.equals( m_destDir ) && m_ext == null && m_mapper == null )
  +        if( m_srcDir.equals( m_destDir ) && m_mapper == null )
           {
  -            throw new TaskException( "The ext attribute or a mapper must be set if" +
  +            throw new TaskException( "A mapper must be specified if" +
                                        " src and dest dirs are the same." );
           }
   
  
  
  
  1.6       +11 -6     jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/types/SourceFileScanner.java
  
  Index: SourceFileScanner.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/types/SourceFileScanner.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SourceFileScanner.java	2 Mar 2002 04:03:37 -0000	1.5
  +++ SourceFileScanner.java	4 Mar 2002 02:44:14 -0000	1.6
  @@ -13,8 +13,9 @@
   import org.apache.aut.nativelib.Os;
   import org.apache.avalon.excalibur.io.FileUtil;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.TaskException;
  -import org.apache.tools.ant.util.mappers.FileNameMapper;
  +import org.apache.myrmidon.framework.FileNameMapper;
   
   /**
    * Utility class that collects the functionality of the various scanDir methods
  @@ -40,8 +41,11 @@
        * @param mapper knows how to construct a target file names from source file
        *      names.
        */
  -    public String[] restrict( String[] files, File srcDir, File destDir,
  -                              FileNameMapper mapper )
  +    public String[] restrict( final String[] files,
  +                              final File srcDir,
  +                              final File destDir,
  +                              final FileNameMapper mapper,
  +                              final TaskContext context )
           throws TaskException
       {
   
  @@ -64,7 +68,7 @@
           final ArrayList v = new ArrayList();
           for( int i = 0; i < files.length; i++ )
           {
  -            final String[] targets = mapper.mapFileName( files[ i ] );
  +            final String[] targets = mapper.mapFileName( files[ i ], context );
               if( targets == null || targets.length == 0 )
               {
                   final String message = files[ i ] + " skipped - don\'t know how to handle it";
  @@ -130,10 +134,11 @@
       public File[] restrictAsFiles( final String[] files,
                                      final File srcDir,
                                      final File destDir,
  -                                   final FileNameMapper mapper )
  +                                   final FileNameMapper mapper,
  +                                   final TaskContext context )
           throws TaskException
       {
  -        final String[] res = restrict( files, srcDir, destDir, mapper );
  +        final String[] res = restrict( files, srcDir, destDir, mapper, context );
           final File[] result = new File[ res.length ];
           for( int i = 0; i < res.length; i++ )
           {
  
  
  
  1.2       +7 -2      jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers/GlobPatternMapper.java
  
  Index: GlobPatternMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers/GlobPatternMapper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GlobPatternMapper.java	13 Jan 2002 04:45:01 -0000	1.1
  +++ GlobPatternMapper.java	4 Mar 2002 02:44:15 -0000	1.2
  @@ -7,6 +7,9 @@
    */
   package org.apache.tools.ant.util.mappers;
   
  +import org.apache.myrmidon.api.TaskContext;
  +import org.apache.myrmidon.framework.FileNameMapper;
  +
   /**
    * Implementation of FileNameMapper that does simple wildcard pattern
    * replacements. <p>
  @@ -18,6 +21,8 @@
    * This is one of the more useful Mappers, it is used by javac for example.</p>
    *
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  + *
  + * @ant:type type="mapper" name="glob"
    */
   public class GlobPatternMapper
       implements FileNameMapper
  @@ -101,7 +106,7 @@
        * @param sourceFileName Description of Parameter
        * @return Description of the Returned Value
        */
  -    public String[] mapFileName( final String sourceFileName )
  +    public String[] mapFileName( final String sourceFileName, TaskContext context )
       {
           if( m_fromPrefix == null ||
               !sourceFileName.startsWith( m_fromPrefix ) ||
  @@ -124,7 +129,7 @@
        * @param name Description of Parameter
        * @return Description of the Returned Value
        */
  -    protected String extractVariablePart( final String name )
  +    private String extractVariablePart( final String name )
       {
           return name.substring( m_prefixLength,
                                  name.length() - m_postfixLength );
  
  
  
  1.2       +7 -22     jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers/IdentityMapper.java
  
  Index: IdentityMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers/IdentityMapper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IdentityMapper.java	13 Jan 2002 04:45:01 -0000	1.1
  +++ IdentityMapper.java	4 Mar 2002 02:44:15 -0000	1.2
  @@ -7,43 +7,28 @@
    */
   package org.apache.tools.ant.util.mappers;
   
  +import org.apache.myrmidon.api.TaskContext;
  +import org.apache.myrmidon.framework.FileNameMapper;
  +
   /**
    * Implementation of FileNameMapper that always returns the source file name.
    * <p>
    *
  - * This is the default FileNameMapper for the copy and move tasks.</p>
  - *
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  + *
  + * @ant:type type="mapper" name="identity"
    */
   public class IdentityMapper
       implements FileNameMapper
   {
       /**
  -     * Ignored.
  -     *
  -     * @param from The new From value
  -     */
  -    public void setFrom( final String from )
  -    {
  -    }
  -
  -    /**
  -     * Ignored.
  -     *
  -     * @param to The new To value
  -     */
  -    public void setTo( final String to )
  -    {
  -    }
  -
  -    /**
        * Returns an one-element array containing the source file name.
        *
        * @param sourceFileName Description of Parameter
        * @return Description of the Returned Value
        */
  -    public String[] mapFileName( final String sourceFileName )
  +    public String[] mapFileName( final String sourceFileName, TaskContext context )
       {
  -        return new String[]{sourceFileName};
  +        return new String[]{ sourceFileName };
       }
   }
  
  
  
  1.2       +14 -14    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers/MergingMapper.java
  
  Index: MergingMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers/MergingMapper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MergingMapper.java	13 Jan 2002 04:45:01 -0000	1.1
  +++ MergingMapper.java	4 Mar 2002 02:44:15 -0000	1.2
  @@ -7,13 +7,17 @@
    */
   package org.apache.tools.ant.util.mappers;
   
  +import org.apache.myrmidon.api.TaskContext;
  +import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.framework.FileNameMapper;
  +
   /**
    * Implementation of FileNameMapper that always returns the same target file
    * name. <p>
    *
  - * This is the default FileNameMapper for the archiving tasks and uptodate.</p>
  - *
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  + *
  + * @ant:type type="mapper" name="merge"
    */
   public class MergingMapper
       implements FileNameMapper
  @@ -21,22 +25,13 @@
       private String[] m_mergedFile;
   
       /**
  -     * Ignored.
  -     *
  -     * @param from The new From value
  -     */
  -    public void setFrom( String from )
  -    {
  -    }
  -
  -    /**
        * Sets the name of the merged file.
        *
        * @param to The new To value
        */
  -    public void setTo( String to )
  +    public void setTo( final String to )
       {
  -        m_mergedFile = new String[]{to};
  +        m_mergedFile = new String[]{ to };
       }
   
       /**
  @@ -45,8 +40,13 @@
        * @param sourceFileName Description of Parameter
        * @return Description of the Returned Value
        */
  -    public String[] mapFileName( final String sourceFileName )
  +    public String[] mapFileName( final String sourceFileName, TaskContext context )
  +        throws TaskException
       {
  +        if( m_mergedFile == null )
  +        {
  +            throw new TaskException( "Destination file was not specified." );
  +        }
           return m_mergedFile;
       }
   }
  
  
  
  1.2       +5 -1      jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers/RegexpPatternMapper.java
  
  Index: RegexpPatternMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers/RegexpPatternMapper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RegexpPatternMapper.java	13 Jan 2002 04:45:01 -0000	1.1
  +++ RegexpPatternMapper.java	4 Mar 2002 02:44:15 -0000	1.2
  @@ -8,7 +8,9 @@
   package org.apache.tools.ant.util.mappers;
   
   import java.util.ArrayList;
  +import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.framework.FileNameMapper;
   import org.apache.tools.ant.util.regexp.RegexpMatcher;
   import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
   
  @@ -16,6 +18,8 @@
    * Implementation of FileNameMapper that does regular expression replacements.
    *
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  + *
  + * @ant:type type="mapper" name="regexp"
    */
   public class RegexpPatternMapper
       implements FileNameMapper
  @@ -65,7 +69,7 @@
        * @param sourceFileName Description of Parameter
        * @return Description of the Returned Value
        */
  -    public String[] mapFileName( final String sourceFileName )
  +    public String[] mapFileName( final String sourceFileName, TaskContext context )
           throws TaskException
       {
           if( m_matcher == null || m_to == null ||
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/ExtFileNameMapper.java
  
  Index: ExtFileNameMapper.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.core;
  
  import org.apache.avalon.excalibur.io.FileUtil;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.framework.FileNameMapper;
  
  /**
   * Maps file extensions.
   *
   * @ant:type type="mapper" name="map-extension"
   */
  public class ExtFileNameMapper
      implements FileNameMapper
  {
      private String m_extension;
  
      public void setExtension( final String extension )
      {
          m_extension = extension;
      }
  
      public String[] mapFileName( final String filename, TaskContext context )
          throws TaskException
      {
          final String name = FileUtil.removeExtension( filename );
          if( m_extension != null )
          {
              return new String[]{ name + '.' + m_extension };
          }
          else
          {
              return new String[]{ name };
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/FlatFileNameMapper.java
  
  Index: FlatFileNameMapper.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.core;
  
  import org.apache.avalon.excalibur.io.FileUtil;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.framework.FileNameMapper;
  
  /**
   * Implementation of FileNameMapper that always returns the source file name
   * without any leading directory information. <p>
   *
   * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
   *
   * @ant:type type="mapper" name="flatten"
   */
  public class FlatFileNameMapper
      extends PrefixFileNameMapper
      implements FileNameMapper
  {
  
      /**
       * Returns an one-element array containing the source file name without any
       * leading directory information.
       *
       * @param sourceFileName Description of Parameter
       * @return Description of the Returned Value
       */
      public String[] mapFileName( final String sourceFileName, TaskContext context )
          throws TaskException
      {
          final String baseName = FileUtil.removePath( sourceFileName, '/' );
          return super.mapFileName( baseName, context );
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/PrefixFileNameMapper.java
  
  Index: PrefixFileNameMapper.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.core;
  
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.framework.FileNameMapper;
  
  /**
   * A filename mapper that applies a prefix to each file.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/03/04 02:44:15 $
   *
   * @ant:type type="mapper" name="prefix"
   */
  public class PrefixFileNameMapper
      implements FileNameMapper
  {
      private String m_prefix;
  
      /**
       * Sets the prefix.
       */
      public void setPrefix( final String prefix )
      {
          m_prefix = prefix;
          if( ! m_prefix.endsWith( "/" ) )
          {
              m_prefix = m_prefix + '/';
          }
      }
  
      /**
       * Returns an array containing the target filename(s) for the given source
       * file.
       */
      public String[] mapFileName( final String sourceFileName,
                                   final TaskContext context )
          throws TaskException
      {
          if( m_prefix == null )
          {
              return new String[]{ sourceFileName };
          }
          else
          {
              return new String[] { m_prefix + sourceFileName };
          }
      }
  }
  
  
  
  1.4       +8 -28     jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/file/CopyTask.java
  
  Index: CopyTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/file/CopyTask.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CopyTask.java	14 Feb 2002 10:53:53 -0000	1.3
  +++ CopyTask.java	4 Mar 2002 02:44:15 -0000	1.4
  @@ -18,14 +18,12 @@
   import org.apache.avalon.excalibur.io.FileUtil;
   import org.apache.myrmidon.api.AbstractTask;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.framework.FileNameMapper;
   import org.apache.tools.ant.types.DirectoryScanner;
   import org.apache.tools.ant.types.FileSet;
   import org.apache.tools.ant.types.ScannerUtil;
   import org.apache.tools.ant.types.SourceFileScanner;
  -import org.apache.tools.ant.util.mappers.FileNameMapper;
  -import org.apache.tools.ant.util.mappers.FlatFileNameMapper;
   import org.apache.tools.ant.util.mappers.IdentityMapper;
  -import org.apache.tools.ant.util.mappers.Mapper;
   
   /**
    * This is a task used to copy files.
  @@ -36,7 +34,7 @@
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
    * @author <A href="gholam@xtra.co.nz">Michael McCallum</A>
    * @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a>
  - * @version $Revision: 1.3 $ $Date: 2002/02/14 10:53:53 $
  + * @version $Revision: 1.4 $ $Date: 2002/03/04 02:44:15 $
    */
   public class CopyTask
       extends AbstractTask
  @@ -50,9 +48,8 @@
       private File m_destDir;
       private boolean m_preserveLastModified;
       private boolean m_overwrite;
  -    private boolean m_flatten;
       private boolean m_includeEmpty = true;
  -    private Mapper m_mapper;
  +    private FileNameMapper m_mapper;
   
       private HashMap m_fileMap = new HashMap();
       private HashMap m_dirMap = new HashMap();
  @@ -94,22 +91,9 @@
       }
   
       /**
  -     * When copying directory trees, the files can be "flattened" into a single
  -     * directory. If there are multiple files with the same name in the source
  -     * directory tree, only the first file will be copied into the "flattened"
  -     * directory, unless the forceoverwrite attribute is true.
  -     *
  -     * @param flatten The new Flatten value
  -     */
  -    public void setFlatten( final boolean flatten )
  -    {
  -        m_flatten = flatten;
  -    }
  -
  -    /**
        * Defines the FileNameMapper to use (nested mapper element).
        */
  -    public void addMapper( final Mapper mapper )
  +    public void addMapper( final FileNameMapper mapper )
           throws TaskException
       {
           if( null != m_mapper )
  @@ -269,7 +253,7 @@
           final String[] toCopy = buildFilenameList( files, mapper, sourceDir, destDir );
           for( int i = 0; i < toCopy.length; i++ )
           {
  -            final String destFilename = mapper.mapFileName( toCopy[ i ] )[ 0 ];
  +            final String destFilename = mapper.mapFileName( toCopy[ i ], getContext() )[ 0 ];
               final File source = new File( sourceDir, toCopy[ i ] );
               final File destination = new File( destDir, destFilename );
               map.put( source.getAbsolutePath(), destination.getAbsolutePath() );
  @@ -292,7 +276,7 @@
               for( int i = 0; i < names.length; i++ )
               {
                   final String name = names[ i ];
  -                if( null != mapper.mapFileName( name ) )
  +                if( null != mapper.mapFileName( name, getContext() ) )
                   {
                       list.add( name );
                   }
  @@ -304,7 +288,7 @@
           {
               final SourceFileScanner scanner = new SourceFileScanner();
               setupLogger( scanner );
  -            return scanner.restrict( names, fromDir, toDir, mapper );
  +            return scanner.restrict( names, fromDir, toDir, mapper, getContext() );
           }
       }
   
  @@ -406,11 +390,7 @@
       {
           if( null != m_mapper )
           {
  -            return m_mapper.getImplementation();
  -        }
  -        else if( m_flatten )
  -        {
  -            return new FlatFileNameMapper();
  +            return m_mapper;
           }
           else
           {
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/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/03/04 02:44:15 $
   *
   * @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/proposal/myrmidon/src/java/org/apache/myrmidon/framework/ChainFileNameMapper.java
  
  Index: ChainFileNameMapper.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.myrmidon.framework;
  
  import java.util.ArrayList;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * A mapper that applies a chain of mappers.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/03/04 02:44:15 $
   *
   * @ant:type type="mapper" name="chain"
   */
  public class ChainFileNameMapper
      implements FileNameMapper
  {
      private final ArrayList m_mappers = new ArrayList();
  
      /**
       * Adds a nested mapper.
       */
      public void add( final FileNameMapper mapper )
      {
          m_mappers.add( mapper );
      }
  
      /**
       * Returns an array containing the target filename(s) for the given source
       * file.
       */
      public String[] mapFileName( final String sourceFileName,
                                   final TaskContext context )
          throws TaskException
      {
          ArrayList names = new ArrayList();
          names.add( sourceFileName );
  
          final int count = m_mappers.size();
          for( int i = 0; i < count; i++ )
          {
              final FileNameMapper mapper = (FileNameMapper)m_mappers.get( i );
              names = mapNames( mapper, names, context );
          }
  
          return (String[])names.toArray( new String[ names.size() ] );
      }
  
      /**
       * Maps a set of names.
       */
      private ArrayList mapNames( final FileNameMapper mapper,
                                  final ArrayList names,
                                  final TaskContext context )
          throws TaskException
      {
          final ArrayList retval = new ArrayList();
  
          // Map each of the supplied names
          final int count = names.size();
          for( int i = 0; i < count; i++ )
          {
              final String name = (String)names.get( i );
              final String[] newNames = mapper.mapFileName( name, context );
              if( newNames == null )
              {
                  continue;
              }
              for( int j = 0; j < newNames.length; j++ )
              {
                  final String newName = newNames[ j ];
                  retval.add( newName );
              }
          }
  
          return retval;
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/FileNameMapper.java
  
  Index: FileNameMapper.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.myrmidon.framework;
  
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * Interface to be used by SourceFileScanner. <p>
   *
   * Used to find the name of the target file(s) corresponding to a source file.
   * </p> <p>
   *
   * The rule by which the file names are transformed is specified via the setFrom
   * and setTo methods. The exact meaning of these is implementation dependent.
   * </p>
   *
   * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
   *
   * @ant:role shorthand="mapper"
   */
  public interface FileNameMapper
  {
      /**
       * Returns an array containing the target filename(s) for the given source
       * file.
       *
       * <p>if the given rule doesn't apply to the source file, implementation
       * must return null. SourceFileScanner will then omit the source file in
       * question.</p>
       *
       * @param sourceFileName the name of the source file relative to some given
       *      basedirectory.
       * @param context the context to perform the mapping in.
       * @return Description of the Returned Value
       */
      String[] mapFileName( String sourceFileName, TaskContext context )
          throws TaskException;
  }
  
  
  
  1.15      +2 -2      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/launcher/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/launcher/Main.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Main.java	18 Feb 2002 09:08:08 -0000	1.14
  +++ Main.java	4 Mar 2002 02:44:15 -0000	1.15
  @@ -19,7 +19,7 @@
    * Basic Loader that is responsible for all the hackery to get classloader to work.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.14 $ $Date: 2002/02/18 09:08:08 $
  + * @version $Revision: 1.15 $ $Date: 2002/03/04 02:44:15 $
    */
   public final class Main
   {
  @@ -116,7 +116,7 @@
               final String name = file.getName();
               if( !name.endsWith( ".jar" ) && !name.endsWith( ".zip" ) )
               {
  -                //Ifnore files in lib dir that are not jars or zips
  +                //Ignore files in lib dir that are not jars or zips
                   continue;
               }
   
  
  
  

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