You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by do...@apache.org on 2002/04/07 09:49:25 UTC

cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions ExtensionSet.java ExtensionUtil.java ExtensionAdapter.java JarLibManifestTask.java

donaldp     02/04/06 23:49:25

  Modified:    proposal/myrmidon/src/java/org/apache/antlib/extensions
                        ExtensionAdapter.java JarLibManifestTask.java
  Added:       proposal/myrmidon/src/java/org/apache/antlib/extensions
                        ExtensionSet.java ExtensionUtil.java
  Log:
  Rework the extension stuff again to deal with extensionSets rather than the other constructs. Also made Extension/ExtensionSet datatypes.
  
  Revision  Changes    Path
  1.2       +4 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtensionAdapter.java
  
  Index: ExtensionAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtensionAdapter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExtensionAdapter.java	6 Apr 2002 04:25:49 -0000	1.1
  +++ ExtensionAdapter.java	7 Apr 2002 07:49:24 -0000	1.2
  @@ -12,15 +12,18 @@
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.framework.DataType;
   
   /**
    * Simple class that represents an Extension and conforms to Ants
    * patterns.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.1 $ $Date: 2002/04/06 04:25:49 $
  + * @version $Revision: 1.2 $ $Date: 2002/04/07 07:49:24 $
  + * @ant.data-type name="extension"
    */
   public class ExtensionAdapter
  +    implements DataType
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( ExtensionAdapter.class );
  
  
  
  1.6       +23 -134   jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibManifestTask.java
  
  Index: JarLibManifestTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibManifestTask.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JarLibManifestTask.java	6 Apr 2002 04:30:15 -0000	1.5
  +++ JarLibManifestTask.java	7 Apr 2002 07:49:24 -0000	1.6
  @@ -13,7 +13,6 @@
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.jar.Attributes;
  -import java.util.jar.JarFile;
   import java.util.jar.Manifest;
   import org.apache.avalon.excalibur.extension.Extension;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
  @@ -22,8 +21,6 @@
   import org.apache.myrmidon.Constants;
   import org.apache.myrmidon.api.AbstractTask;
   import org.apache.myrmidon.api.TaskException;
  -import org.apache.tools.todo.types.DirectoryScanner;
  -import org.apache.tools.todo.types.ScannerUtil;
   
   /**
    * Task to generate a manifest that declares all the dependencies
  @@ -80,18 +77,6 @@
       private final ArrayList m_optionals = new ArrayList();
   
       /**
  -     * Filesets specifying all the librarys
  -     * to generate dependency information about.
  -     */
  -    private final ArrayList m_dependsFilesets = new ArrayList();
  -
  -    /**
  -     * Filesets specifying all the librarys
  -     * to generate optional dependency information about.
  -     */
  -    private final ArrayList m_optionalsFilesets = new ArrayList();
  -
  -    /**
        * Extra attributes the user specifies for main section
        * in manifest.
        */
  @@ -127,43 +112,23 @@
       }
   
       /**
  -     * Adds an extension that this library requires.
  -     *
  -     * @param extensionAdapter an extension that this library requires.
  -     */
  -    public void addDepends( final ExtensionAdapter extensionAdapter )
  -    {
  -        m_dependencies.add( extensionAdapter );
  -    }
  -
  -    /**
  -     * Adds an extension that this library optionally requires.
  -     *
  -     * @param extensionAdapter an extension that this library optionally requires.
  -     */
  -    public void addOption( final ExtensionAdapter extensionAdapter )
  -    {
  -        m_optionals.add( extensionAdapter );
  -    }
  -
  -    /**
  -     * Adds a set of files about which library data will be displayed.
  +     * Adds a set of extensions that this library requires.
        *
  -     * @param fileSet a set of files about which library data will be displayed.
  +     * @param extensionSet a set of extensions that this library requires.
        */
  -    public void addDependsfileset( final LibFileSet fileSet )
  +    public void addDepends( final ExtensionSet extensionSet )
       {
  -        m_dependsFilesets.add( fileSet );
  +        m_dependencies.add( extensionSet );
       }
   
       /**
  -     * Adds a set of files about which library data will be displayed.
  +     * Adds a set of extensions that this library optionally requires.
        *
  -     * @param fileSet a set of files about which library data will be displayed.
  +     * @param extensionSet a set of extensions that this library optionally requires.
        */
  -    public void addOptionalfileset( final LibFileSet fileSet )
  +    public void addOption( final ExtensionSet extensionSet )
       {
  -        m_optionalsFilesets.add( fileSet );
  +        m_optionals.add( extensionSet );
       }
   
       /**
  @@ -196,7 +161,6 @@
   
           //Add all the dependency data to manifest for dependencies
           final ArrayList depends = toExtensions( m_dependencies );
  -        extractLibraryData( depends, m_dependsFilesets );
           appendExtensionList( attributes,
                                Extension.EXTENSION_LIST,
                                "lib",
  @@ -206,7 +170,6 @@
           //Add all the dependency data to manifest for "optional"
           //dependencies
           final ArrayList option = toExtensions( m_optionals );
  -        extractLibraryData( option, m_optionalsFilesets );
           appendExtensionList( attributes,
                                Extension.OPTIONAL_EXTENSION_LIST,
                                "opt",
  @@ -290,47 +253,25 @@
       }
   
       /**
  -     * Generate a list of extensions from a specified fileset.
  -     *
  -     * @param librarys the list to add extensions to
  -     * @param fileset the filesets containing librarys
  -     * @throws TaskException if an error occurs
  -     */
  -    private void extractLibraryData( final ArrayList librarys,
  -                                     final ArrayList fileset )
  -        throws TaskException
  -    {
  -        if( !fileset.isEmpty() )
  -        {
  -            final Extension[] extensions = getExtensions( fileset );
  -            for( int i = 0; i < extensions.length; i++ )
  -            {
  -                librarys.add( extensions[ i ] );
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Append specified librarys extension data to specified attributes.
  +     * Append specified extensions to specified attributes.
        * Use the extensionKey to list the extensions, usually "Extension-List:"
        * for required dependencies and "Optional-Extension-List:" for optional
        * dependencies. NOTE: "Optional" dependencies are not part of the
        * specification.
        *
        * @param attributes the attributes to add extensions to
  -     * @param librarys the filesets containing librarys
  +     * @param extensions the list of extensions
        * @throws TaskException if an error occurs
        */
       private void appendLibraryList( final Attributes attributes,
                                       final String listPrefix,
  -                                    final ArrayList librarys )
  +                                    final ArrayList extensions )
           throws TaskException
       {
  -        final int size = librarys.size();
  -
  +        final int size = extensions.size();
           for( int i = 0; i < size; i++ )
           {
  -            final Extension extension = (Extension)librarys.get( i );
  +            final Extension extension = (Extension)extensions.get( i );
               final String prefix = listPrefix + i + "-";
               Extension.addExtension( extension, prefix, attributes );
           }
  @@ -365,77 +306,25 @@
       }
   
       /**
  -     * Retrieve extensions from the specified librarys.
  +     * Convert a list of ExtensionSet objects to extensions.
        *
  -     * @param librarys the filesets for librarys
  -     * @return the extensions contained in librarys
  -     * @throws TaskException if failing to scan librarys
  -     */
  -    private static Extension[] getExtensions( final ArrayList librarys )
  -        throws TaskException
  -    {
  -        final ArrayList extensions = new ArrayList();
  -        final Iterator iterator = librarys.iterator();
  -        while( iterator.hasNext() )
  -        {
  -            final LibFileSet fileSet = (LibFileSet)iterator.next();
  -            final DirectoryScanner scanner = ScannerUtil.getDirectoryScanner( fileSet );
  -            final File basedir = scanner.getBasedir();
  -            final String[] files = scanner.getIncludedFiles();
  -            for( int i = 0; i < files.length; i++ )
  -            {
  -                final File file = new File( basedir, files[ i ] );
  -                loadExtensions( file, extensions );
  -            }
  -        }
  -        return (Extension[])extensions.toArray( new Extension[ extensions.size() ] );
  -    }
  -
  -    /**
  -     * Load list of available extensions from specified file.
  -     *
  -     * @param file the file
  -     * @param extensions the list to add available extensions to
  -     * @throws TaskException if there is an error
  -     */
  -    private static void loadExtensions( final File file,
  -                                        final ArrayList extensions )
  -        throws TaskException
  -    {
  -        try
  -        {
  -            final JarFile jarFile = new JarFile( file );
  -            final Extension[] extension =
  -                Extension.getAvailable( jarFile.getManifest() );
  -            for( int i = 0; i < extension.length; i++ )
  -            {
  -                extensions.add( extension[ i ] );
  -            }
  -        }
  -        catch( final Exception e )
  -        {
  -            throw new TaskException( e.getMessage(), e );
  -        }
  -    }
  -
  -    /**
  -     * Convert a list of extensionAdapter objects to extensions.
  -     *
  -     * @param adapters the list of ExtensionAdapterss to add to convert
  +     * @param extensionSets the list of ExtensionSets to add to list
        * @throws TaskException if an error occurs
        */
  -    private static ArrayList toExtensions( final ArrayList adapters )
  +    private static ArrayList toExtensions( final ArrayList extensionSets )
           throws TaskException
       {
           final ArrayList results = new ArrayList();
   
  -        final int size = adapters.size();
  +        final int size = extensionSets.size();
           for( int i = 0; i < size; i++ )
           {
  -            final ExtensionAdapter adapter =
  -                (ExtensionAdapter)adapters.get( i );
  -            final Extension extension = adapter.toExtension();
  -            results.add( extension );
  +            final ExtensionSet set = (ExtensionSet)extensionSets.get( i );
  +            final Extension[] extensions = set.toExtensions();
  +            for( int j = 0; j < extensions.length; j++ )
  +            {
  +                results.add( extensions[ j ] );
  +            }
           }
   
           return results;
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtensionSet.java
  
  Index: ExtensionSet.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.extensions;
  
  import java.util.ArrayList;
  import org.apache.avalon.excalibur.extension.Extension;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.framework.DataType;
  
  /**
   * The Extension set lists a set of "Optional Packages" /
   * "Extensions".
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/07 07:49:24 $
   * @ant.data-type name="extension-set"
   */
  public class ExtensionSet
      implements DataType
  {
      /**
       * ExtensionAdapter objects representing extensions.
       */
      private final ArrayList m_extensions = new ArrayList();
  
      /**
       * Filesets specifying all the extensions wanted.
       */
      private final ArrayList m_extensionsFilesets = new ArrayList();
  
      /**
       * Adds an extension that this library requires.
       *
       * @param extensionAdapter an extension that this library requires.
       */
      public void addExtension( final ExtensionAdapter extensionAdapter )
      {
          m_extensions.add( extensionAdapter );
      }
  
      /**
       * Adds a set of files about which extensions data will be extracted.
       *
       * @param fileSet a set of files about which extensions data will be extracted.
       */
      public void addLibfileset( final LibFileSet fileSet )
      {
          m_extensionsFilesets.add( fileSet );
      }
  
      /**
       * Extract a set of Extension objects from the ExtensionSet.
       *
       * @throws TaskException if an error occurs
       */
      public Extension[] toExtensions()
          throws TaskException
      {
          final ArrayList extensions = ExtensionUtil.toExtensions( m_extensions );
          ExtensionUtil.extractExtensions( extensions, m_extensionsFilesets );
          return (Extension[])extensions.toArray( new Extension[ extensions.size() ] );
      }
  
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtensionUtil.java
  
  Index: ExtensionUtil.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.extensions;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.jar.JarFile;
  import org.apache.avalon.excalibur.extension.Extension;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.tools.todo.types.DirectoryScanner;
  import org.apache.tools.todo.types.ScannerUtil;
  
  /**
   * A set of useful methods relating to extensions.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/07 07:49:24 $
   */
  public class ExtensionUtil
  {
      /**
       * Convert a list of extensionAdapter objects to extensions.
       *
       * @param adapters the list of ExtensionAdapterss to add to convert
       * @throws TaskException if an error occurs
       */
      static ArrayList toExtensions( final ArrayList adapters )
          throws TaskException
      {
          final ArrayList results = new ArrayList();
  
          final int size = adapters.size();
          for( int i = 0; i < size; i++ )
          {
              final ExtensionAdapter adapter =
                  (ExtensionAdapter)adapters.get( i );
              final Extension extension = adapter.toExtension();
              results.add( extension );
          }
  
          return results;
      }
  
      /**
       * Generate a list of extensions from a specified fileset.
       *
       * @param librarys the list to add extensions to
       * @param fileset the filesets containing librarys
       * @throws TaskException if an error occurs
       */
      static void extractExtensions( final ArrayList librarys,
                                     final ArrayList fileset )
          throws TaskException
      {
          if( !fileset.isEmpty() )
          {
              final Extension[] extensions = getExtensions( fileset );
              for( int i = 0; i < extensions.length; i++ )
              {
                  librarys.add( extensions[ i ] );
              }
          }
      }
  
      /**
       * Retrieve extensions from the specified librarys.
       *
       * @param librarys the filesets for librarys
       * @return the extensions contained in librarys
       * @throws TaskException if failing to scan librarys
       */
      private static Extension[] getExtensions( final ArrayList librarys )
          throws TaskException
      {
          final ArrayList extensions = new ArrayList();
          final Iterator iterator = librarys.iterator();
          while( iterator.hasNext() )
          {
              final LibFileSet fileSet = (LibFileSet)iterator.next();
              final DirectoryScanner scanner = ScannerUtil.getDirectoryScanner( fileSet );
              final File basedir = scanner.getBasedir();
              final String[] files = scanner.getIncludedFiles();
              for( int i = 0; i < files.length; i++ )
              {
                  final File file = new File( basedir, files[ i ] );
                  loadExtensions( file, extensions );
              }
          }
          return (Extension[])extensions.toArray( new Extension[ extensions.size() ] );
      }
  
      /**
       * Load list of available extensions from specified file.
       *
       * @param file the file
       * @param extensions the list to add available extensions to
       * @throws TaskException if there is an error
       */
      private static void loadExtensions( final File file,
                                          final ArrayList extensions )
          throws TaskException
      {
          try
          {
              final JarFile jarFile = new JarFile( file );
              final Extension[] extension =
                  Extension.getAvailable( jarFile.getManifest() );
              for( int i = 0; i < extension.length; i++ )
              {
                  extensions.add( extension[ i ] );
              }
          }
          catch( final Exception e )
          {
              throw new TaskException( e.getMessage(), e );
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>