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-myrmidon/myrmidon/src/samples sample.ant
Date Fri, 03 May 2002 06:56:12 GMT
adammurdoch    02/05/02 23:56:12

  Modified:    antlib/src/java/org/apache/antlib/project
                        Resources.properties TypeLibTask.java
               antlib/src/java/org/apache/antlib/runtime Import.java
                        Resources.properties TypeDef.java
               container/src/java/org/apache/myrmidon/components/deployer
                        DefaultDeployer.java
                        DefaultTypeLibraryDeployer.java
                        Resources.properties
               container/src/java/org/apache/myrmidon/components/embeddor
                        DefaultEmbeddor.java
               container/src/java/org/apache/myrmidon/components/workspace
                        DefaultWorkspace.java Resources.properties
               container/src/java/org/apache/myrmidon/interfaces/deployer
                        Deployer.java
               container/src/test/org/apache/myrmidon/components
                        AbstractComponentTest.java
               container/src/test/org/apache/myrmidon/components/deployer/test
                        DefaultDeployerTestCase.java
               framework/src/java/org/apache/myrmidon/framework
                        AbstractTypeDef.java
               framework/src/java/org/apache/myrmidon/framework/file
                        FileListUtil.java
               myrmidon/src/samples sample.ant
  Added:       container/src/java/org/apache/myrmidon/components/library
                        DefaultLibrary.java DefaultLibraryManager.java
                        DefaultTypeLibraryManager.java
                        MultiParentURLClassLoader.java Resources.properties
               container/src/java/org/apache/myrmidon/interfaces/library
                        Library.java LibraryManager.java
                        TypeLibraryManager.java
               container/src/test/org/apache/myrmidon/components/library/test
                        DefaultLibraryManagerTestCase.java
  Removed:     container/src/java/org/apache/myrmidon/components/classloader
                        DefaultClassLoaderManager.java
                        MultiParentURLClassLoader.java
               container/src/java/org/apache/myrmidon/interfaces/classloader
                        ClassLoaderException.java ClassLoaderManager.java
               container/src/test/org/apache/myrmidon/components/classloader/test
                        DefaultClassLoaderManagerTestCase.java
  Log:
  Added a (really badly named) abstraction for the various jar files, classpaths,
  and classloaders that we have to deal with:
  
  * Added Library, and the LibraryManager service.  These replace ClassLoaderManager,
    and a bunch of factory methods on Deployer.
  
  * Added TypeLibraryManager service, used to locate antlibs.  Moved the
    search code out of DefaultEmbeddor, DefaultWorkspace, and TypeLibTask.
  
  * DefaultDeployer can now deploy from arbitrary URLs (including directories),
    rather than just Jar files.
  
  * AbstractTypeDef now supports a classpath, rather than a single file.
  
  Revision  Changes    Path
  1.2       +1 -2      jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/Resources.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Resources.properties	2 May 2002 08:43:33 -0000	1.1
  +++ Resources.properties	3 May 2002 06:56:10 -0000	1.2
  @@ -5,5 +5,4 @@
   typelib.missing-library.error=Missing library attribute from typelib statement.
   typelib.missing-name.error=Specified role ("{0}") but missing name from typelib statement.
   typelib.missing-role.error=Specified name ("{0}") but missing role from typelib statement.
  -typelib.no-read.error=Unable to read file "{0}" to load library "{1}".
  -typelib.no-file.error=No file can be found when searching for library "{0}".
  \ No newline at end of file
  +typelib.no-deploy.error=Could not import types from Type Library "{0}".
  \ No newline at end of file
  
  
  
  1.2       +8 -54     jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/TypeLibTask.java
  
  Index: TypeLibTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/TypeLibTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TypeLibTask.java	2 May 2002 08:43:33 -0000	1.1
  +++ TypeLibTask.java	3 May 2002 06:56:10 -0000	1.2
  @@ -7,14 +7,14 @@
    */
   package org.apache.antlib.project;
   
  -import java.io.File;
   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;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  -import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   import org.apache.myrmidon.interfaces.deployer.TypeLibraryDeployer;
  +import org.apache.myrmidon.interfaces.library.TypeLibraryManager;
  +import org.apache.myrmidon.interfaces.library.Library;
   
   /**
    * Task to import a typeLib.
  @@ -94,12 +94,13 @@
       private void deployTypeLib()
           throws TaskException
       {
  -        final File file = findTypeLib();
  -
           try
           {
  +            final TypeLibraryManager libraryManager = (TypeLibraryManager)getService( TypeLibraryManager.class );
  +            final Library library = libraryManager.getTypeLibrary( m_library );
  +
               final Deployer deployer = (Deployer)getService( Deployer.class );
  -            final TypeLibraryDeployer typeDeployer = deployer.createDeployer( file );
  +            final TypeLibraryDeployer typeDeployer = deployer.createDeployer( library );
               if( null == m_role )
               {
                   // Deploy everything in the typelib
  @@ -111,58 +112,11 @@
                   typeDeployer.deployType( m_role, m_name );
               }
           }
  -        catch( final DeploymentException de )
  +        catch( final Exception de )
           {
               final String message =
  -                REZ.getString( "no-deploy.error",
  -                               m_library,
  -                               file );
  +                REZ.getString( "typelib.no-deploy.error", m_library );
               throw new TaskException( message, de );
           }
  -    }
  -
  -    /**
  -     * Find the physical file location of library.
  -     *
  -     * @return the File representing library
  -     * @throws TaskException if can not find library
  -     *         matching name
  -     * @todo In future this will be expanded to allow
  -     *       users to specify search path or automagically
  -     *       add entries to lib path (like user specific or
  -     *       workspace specific)
  -     */
  -    private File findTypeLib()
  -        throws TaskException
  -    {
  -        final String name = m_library.replace( '/', File.separatorChar ) + ".atl";
  -
  -        final File[] extPath =
  -            (File[])getContext().getProperty( "myrmidon.antlib.path" );
  -        for( int i = 0; i < extPath.length; i++ )
  -        {
  -            final File extDir = extPath[ i ];
  -            final File file = new File( extDir, name );
  -
  -            if( file.exists() )
  -            {
  -                if( !file.canRead() )
  -                {
  -                    final String message =
  -                        REZ.getString( "typelib.no-read.error",
  -                                       file,
  -                                       m_library );
  -                    throw new TaskException( message );
  -                }
  -                else
  -                {
  -                    return file;
  -                }
  -            }
  -        }
  -
  -        final String message =
  -            REZ.getString( "typelib.no-file.error", m_library );
  -        throw new TaskException( message );
       }
   }
  
  
  
  1.3       +8 -5      jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/runtime/Import.java
  
  Index: Import.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/runtime/Import.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Import.java	25 Apr 2002 01:41:49 -0000	1.2
  +++ Import.java	3 May 2002 06:56:10 -0000	1.3
  @@ -13,8 +13,9 @@
   import org.apache.myrmidon.api.AbstractTask;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  -import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   import org.apache.myrmidon.interfaces.deployer.TypeLibraryDeployer;
  +import org.apache.myrmidon.interfaces.library.Library;
  +import org.apache.myrmidon.interfaces.library.LibraryManager;
   
   /**
    * Task to import a tasklib.
  @@ -46,14 +47,16 @@
   
           try
           {
  +            final LibraryManager libraryManager = (LibraryManager)getService( LibraryManager.class );
  +            final Library library = libraryManager.createLibrary( new File[] { m_lib } );
               final Deployer deployer = (Deployer)getService( Deployer.class );
  -            final TypeLibraryDeployer typeDeployer = deployer.createDeployer( m_lib );
  +            final TypeLibraryDeployer typeDeployer = deployer.createDeployer( library );
               typeDeployer.deployAll();
           }
  -        catch( final DeploymentException de )
  +        catch( final Exception e )
           {
  -            final String message = REZ.getString( "import.no-deploy.error" );
  -            throw new TaskException( message, de );
  +            final String message = REZ.getString( "import.no-deploy.error", m_lib );
  +            throw new TaskException( message, e );
           }
       }
   }
  
  
  
  1.3       +1 -1      jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/runtime/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/runtime/Resources.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Resources.properties	24 Apr 2002 02:20:58 -0000	1.2
  +++ Resources.properties	3 May 2002 06:56:10 -0000	1.3
  @@ -3,7 +3,7 @@
   facility.no-namespace.error=Must specify namespace parameter.
   
   import.no-lib.error=Must specify lib parameter.
  -import.no-deploy.error=Error importing tasklib.
  +import.no-deploy.error=Could not  import types from library "{0}".
   
   typeavailable.no-type-name.error=No type name was specified.
   typeavailable.evaluate.error=Could not determine if type "{0}" is available.
  
  
  
  1.2       +10 -6     jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/runtime/TypeDef.java
  
  Index: TypeDef.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/runtime/TypeDef.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TypeDef.java	14 Apr 2002 10:55:08 -0000	1.1
  +++ TypeDef.java	3 May 2002 06:56:10 -0000	1.2
  @@ -20,11 +20,7 @@
       extends AbstractTypeDef
   {
       private String m_role;
  -
  -    public void setName( final String name )
  -    {
  -        super.setName( name );
  -    }
  +    private String m_name;
   
       /**
        * Sets the type's role.
  @@ -34,8 +30,16 @@
           m_role = role;
       }
   
  +    /**
  +     * Sets the type's name.
  +     */
  +    public void setName( final String name )
  +    {
  +        m_name = name;
  +    }
  +
       protected TypeDefinition createTypeDefinition()
       {
  -        return new TypeDefinition( getName(), m_role, getClassname() );
  +        return new TypeDefinition( m_name, m_role, getClassname() );
       }
   }
  
  
  
  1.40      +16 -50    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java
  
  Index: DefaultDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- DefaultDeployer.java	25 Apr 2002 09:34:45 -0000	1.39
  +++ DefaultDeployer.java	3 May 2002 06:56:10 -0000	1.40
  @@ -7,8 +7,6 @@
    */
   package org.apache.myrmidon.components.deployer;
   
  -import java.io.File;
  -import java.net.URL;
   import java.util.HashMap;
   import java.util.Map;
   import org.apache.aut.converter.Converter;
  @@ -18,11 +16,11 @@
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
  -import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
  +import org.apache.myrmidon.interfaces.deployer.DefaultTypeDeployer;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
   import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   import org.apache.myrmidon.interfaces.deployer.TypeLibraryDeployer;
  -import org.apache.myrmidon.interfaces.deployer.DefaultTypeDeployer;
  +import org.apache.myrmidon.interfaces.library.Library;
   import org.apache.myrmidon.interfaces.role.RoleRegistry;
   
   /**
  @@ -30,7 +28,7 @@
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.39 $ $Date: 2002/04/25 09:34:45 $
  + * @version $Revision: 1.40 $ $Date: 2002/05/03 06:56:10 $
    */
   public class DefaultDeployer
       extends AbstractLogEnabled
  @@ -41,7 +39,6 @@
   
       // The components used to deploy
       private RoleRegistry m_roleDeployer;
  -    private ClassLoaderManager m_classLoaderManager;
       private CompoundTypeDeployer m_typeDeployer;
   
       /** Map from ClassLoader to the deployer for that class loader. */
  @@ -56,8 +53,6 @@
       public void service( final ServiceManager serviceManager )
           throws ServiceException
       {
  -        m_classLoaderManager = (ClassLoaderManager)serviceManager.lookup( ClassLoaderManager.ROLE );
  -
           // Assemble the type deployer
           final DefaultTypeDeployer defaultDeployer = new DefaultTypeDeployer();
           defaultDeployer.service( serviceManager );
  @@ -84,59 +79,30 @@
       }
   
       /**
  -     * Returns the deployer for a ClassLoader, creating the deployer if
  +     * Returns the deployer for a library, creating the deployer if
        * necessary.
        */
  -    public TypeLibraryDeployer createDeployer( final ClassLoader loader )
  +    public TypeLibraryDeployer createDeployer( final Library library )
           throws DeploymentException
       {
           try
           {
  -            return createDeployment( loader, null );
  -        }
  -        catch( Exception e )
  -        {
  -            final String message = REZ.getString( "deploy-from-classloader.error", loader );
  -            throw new DeploymentException( message, e );
  -        }
  -    }
  +            // Locate cached deployer, creating it if necessary
  +            DefaultTypeLibraryDeployer deployment = (DefaultTypeLibraryDeployer)m_classLoaderDeployers.get( library );
  +            if( deployment == null )
  +            {
  +                deployment = new DefaultTypeLibraryDeployer( m_roleDeployer, m_typeDeployer, library.getClassLoader() );
  +                setupLogger( deployment );
  +                deployment.loadDescriptors( library.getClassPath() );
  +                m_classLoaderDeployers.put( library, deployment );
  +            }
   
  -    /**
  -     * Returns the deployer for a type library, creating the deployer if
  -     * necessary.
  -     */
  -    public TypeLibraryDeployer createDeployer( final File file )
  -        throws DeploymentException
  -    {
  -        try
  -        {
  -            final ClassLoader classLoader = m_classLoaderManager.getClassLoader( file );
  -            return createDeployment( classLoader, file.toURL() );
  +            return deployment;
           }
           catch( final Exception e )
           {
  -            final String message = REZ.getString( "deploy-from-file.error", file );
  +            final String message = REZ.getString( "deploy-from-library.error", library.getName() );
               throw new DeploymentException( message, e );
           }
  -    }
  -
  -    /**
  -     * Creates a deployer for a ClassLoader.
  -     */
  -    private DefaultTypeLibraryDeployer createDeployment( final ClassLoader loader,
  -                                                         final URL jarUrl )
  -        throws Exception
  -    {
  -        // Locate cached deployer, creating it if necessary
  -        DefaultTypeLibraryDeployer deployment = (DefaultTypeLibraryDeployer)m_classLoaderDeployers.get( loader );
  -        if( deployment == null )
  -        {
  -            deployment = new DefaultTypeLibraryDeployer( m_roleDeployer, m_typeDeployer, loader );
  -            setupLogger( deployment );
  -            deployment.loadDescriptors( jarUrl );
  -            m_classLoaderDeployers.put( loader, deployment );
  -        }
  -
  -        return deployment;
       }
   }
  
  
  
  1.4       +27 -26    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultTypeLibraryDeployer.java
  
  Index: DefaultTypeLibraryDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultTypeLibraryDeployer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultTypeLibraryDeployer.java	26 Apr 2002 03:22:24 -0000	1.3
  +++ DefaultTypeLibraryDeployer.java	3 May 2002 06:56:10 -0000	1.4
  @@ -10,7 +10,6 @@
   import java.io.FileNotFoundException;
   import java.net.URL;
   import java.util.ArrayList;
  -import java.util.Enumeration;
   import java.util.HashMap;
   import java.util.Map;
   import javax.xml.parsers.SAXParser;
  @@ -21,8 +20,8 @@
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
  -import org.apache.myrmidon.interfaces.deployer.TypeLibraryDeployer;
   import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
  +import org.apache.myrmidon.interfaces.deployer.TypeLibraryDeployer;
   import org.apache.myrmidon.interfaces.role.RoleInfo;
   import org.apache.myrmidon.interfaces.role.RoleRegistry;
   import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
  @@ -33,7 +32,7 @@
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.3 $ $Date: 2002/04/26 03:22:24 $
  + * @version $Revision: 1.4 $ $Date: 2002/05/03 06:56:10 $
    */
   class DefaultTypeLibraryDeployer
       extends AbstractLogEnabled
  @@ -70,10 +69,9 @@
        * Load the descriptors.  Deploys all roles, then loads the descriptors
        * for, but does not deploy, all the types.
        *
  -     * @param jarUrl The URL for the typelib, used to locate the descriptors.
  -     *               If null, the resources from the classloader are used.
  +     * @param searchPath The files containing the descriptors.
        */
  -    public void loadDescriptors( final URL jarUrl )
  +    public void loadDescriptors( final URL[] searchPath )
           throws Exception
       {
           // Create a SAX parser to assemble the descriptors into Configuration
  @@ -88,7 +86,7 @@
           parser.setErrorHandler( handler );
   
           // Build the role descriptors
  -        final ArrayList roleUrls = locateResources( ROLE_DESCRIPTOR_NAME, jarUrl );
  +        final ArrayList roleUrls = locateResources( ROLE_DESCRIPTOR_NAME, searchPath );
           final ArrayList roleDescriptors =
               buildDescriptors( roleUrls, m_roleBuilder, parser, handler );
   
  @@ -102,7 +100,7 @@
           }
   
           // Build the type descriptors
  -        final ArrayList typeUrls = locateResources( TYPE_DESCRIPTOR_NAME, jarUrl );
  +        final ArrayList typeUrls = locateResources( TYPE_DESCRIPTOR_NAME, searchPath );
           final ArrayList typeDescriptors =
               buildDescriptors( typeUrls, m_typeBuilder, parser, handler );
           m_descriptors = (TypeDescriptor[])typeDescriptors.toArray
  @@ -267,37 +265,40 @@
       /**
        * Locates all resources of a particular name.
        */
  -    private ArrayList locateResources( final String resource, final URL jarUrl )
  +    private ArrayList locateResources( final String resource, final URL[] searchPath )
           throws Exception
       {
  -        final ArrayList urls = new ArrayList();
  -        if( null != jarUrl )
  +        final ArrayList resourceUrls = new ArrayList();
  +        for( int i = 0; i < searchPath.length; i++ )
           {
  -            final String systemID = "jar:" + jarUrl + "!/" + resource;
  +            final URL url = searchPath[ i ];
  +
  +            // Build the URL for the resource
  +            final String systemID;
  +            if( url.getFile().endsWith( "/" ) )
  +            {
  +                systemID = url + resource;
  +            }
  +            else
  +            {
  +                systemID = "jar:" + url + "!/" + resource;
  +            }
  +
               try
               {
                   // Probe the resource
  -                final URL url = new URL( systemID );
  -                url.openStream().close();
  +                final URL resourceUrl = new URL( systemID );
  +                resourceUrl.openStream().close();
   
                   // Add to the list
  -                urls.add( systemID );
  +                resourceUrls.add( systemID );
               }
  -            catch( FileNotFoundException e )
  +            catch( final FileNotFoundException e )
               {
                   // Ignore
               }
           }
  -        else
  -        {
  -            final Enumeration enum = m_classLoader.getResources( resource );
  -            while( enum.hasMoreElements() )
  -            {
  -                urls.add( enum.nextElement().toString() );
  -            }
  -        }
  -
  -        return urls;
  +        return resourceUrls;
       }
   
       /**
  
  
  
  1.16      +1 -2      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/Resources.properties,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Resources.properties	25 Apr 2002 09:34:45 -0000	1.15
  +++ Resources.properties	3 May 2002 06:56:10 -0000	1.16
  @@ -4,8 +4,7 @@
   url-deploy-roles.notice=Registering roles from "{0}".
   url-deploy-services.notice=Registering services from "{0}".
   
  -deploy-from-classloader.error=Could not register types from ClassLoader.
  -deploy-from-file.error=Could not register types from type library "{0}".
  +deploy-from-library.error=Could not deploy types from library "{0}".
   deploy-roles.error=Could not register roles from "{0}".
   deploy-types.error=Could not register types from "{0}".
   deploy-services.error=Could not register services from "{0}".
  
  
  
  1.58      +29 -72    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- DefaultEmbeddor.java	2 May 2002 08:50:10 -0000	1.57
  +++ DefaultEmbeddor.java	3 May 2002 06:56:10 -0000	1.58
  @@ -7,16 +7,14 @@
    */
   package org.apache.myrmidon.components.embeddor;
   
  -import java.io.File;
  -import java.io.FilenameFilter;
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  +import java.io.File;
   import org.apache.aut.converter.Converter;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.avalon.excalibur.io.ExtensionFileFilter;
   import org.apache.avalon.excalibur.io.FileUtil;
   import org.apache.avalon.framework.CascadingException;
   import org.apache.avalon.framework.activity.Disposable;
  @@ -36,11 +34,9 @@
   import org.apache.myrmidon.components.property.DefaultPropertyStore;
   import org.apache.myrmidon.components.workspace.DefaultExecutionFrame;
   import org.apache.myrmidon.interfaces.builder.ProjectBuilder;
  -import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
   import org.apache.myrmidon.interfaces.configurer.Configurer;
   import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  -import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   import org.apache.myrmidon.interfaces.deployer.TypeLibraryDeployer;
   import org.apache.myrmidon.interfaces.embeddor.Embeddor;
   import org.apache.myrmidon.interfaces.event.TaskEventManager;
  @@ -48,6 +44,9 @@
   import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
   import org.apache.myrmidon.interfaces.executor.Executor;
   import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
  +import org.apache.myrmidon.interfaces.library.Library;
  +import org.apache.myrmidon.interfaces.library.LibraryManager;
  +import org.apache.myrmidon.interfaces.library.TypeLibraryManager;
   import org.apache.myrmidon.interfaces.oldmodel.Project;
   import org.apache.myrmidon.interfaces.property.PropertyResolver;
   import org.apache.myrmidon.interfaces.property.PropertyStore;
  @@ -64,7 +63,7 @@
    * Instantiate this to embed inside other applications.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.57 $ $Date: 2002/05/02 08:50:10 $
  + * @version $Revision: 1.58 $ $Date: 2002/05/03 06:56:10 $
    */
   public class DefaultEmbeddor
       extends AbstractLogEnabled
  @@ -78,6 +77,8 @@
   
       private Deployer m_deployer;
       private TypeManager m_typeManager;
  +    private LibraryManager m_libraryManager;
  +    private TypeLibraryManager m_typeLibraryManager;
       private MultiSourceServiceManager m_workspaceServiceManager;
   
       private List m_components = new ArrayList();
  @@ -190,6 +191,8 @@
           // locate the components we need
           m_deployer = (Deployer)m_serviceManager.lookup( Deployer.ROLE );
           m_typeManager = (TypeManager)m_serviceManager.lookup( TypeManager.ROLE );
  +        m_libraryManager = (LibraryManager)m_serviceManager.lookup( LibraryManager.ROLE );
  +        m_typeLibraryManager = (TypeLibraryManager)m_serviceManager.lookup( TypeLibraryManager.ROLE );
   
           // setup a service manager that creates the project services
           final ServiceManager projServiceManager
  @@ -207,15 +210,20 @@
       public void start()
           throws Exception
       {
  -        // Deploy all type libraries found in the classpath
  -        final ClassLoader libClassloader = getClass().getClassLoader();
  -        final TypeLibraryDeployer typeDeployer = m_deployer.createDeployer( libClassloader );
  -        typeDeployer.deployAll();
  -
  -        // Deploy all type libraries in the lib directory
  -        final ExtensionFileFilter filter = new ExtensionFileFilter( ".atl" );
  -        final File[] taskLibDirs = (File[])m_context.get( "myrmidon.lib.path" );
  -        deployFromDirectories( m_deployer, taskLibDirs, filter );
  +        // Deploy all types found in the container classpath
  +        final ClassLoader containerClassLoader = getClass().getClassLoader();
  +        final Library containerLib = m_libraryManager.createLibrary( containerClassLoader );
  +        final TypeLibraryDeployer containerTypeDeployer = m_deployer.createDeployer( containerLib );
  +        containerTypeDeployer.deployAll();
  +
  +        // Deploy all core type libraries in the lib directory
  +        final Library[] coreLibs = m_typeLibraryManager.getCoreTypeLibraries();
  +        for( int i = 0; i < coreLibs.length; i++ )
  +        {
  +            final Library library = coreLibs[ i ];
  +            final TypeLibraryDeployer libDeployer = m_deployer.createDeployer( library );
  +            libDeployer.deployAll();
  +        }
       }
   
       /**
  @@ -278,9 +286,12 @@
           createComponent( Deployer.ROLE,
                            Deployer.class,
                            PREFIX + "deployer.DefaultDeployer" );
  -        createComponent( ClassLoaderManager.ROLE,
  -                         ClassLoaderManager.class,
  -                         PREFIX + "classloader.DefaultClassLoaderManager" );
  +        createComponent( LibraryManager.ROLE,
  +                         LibraryManager.class,
  +                         PREFIX + "library.DefaultLibraryManager" );
  +        createComponent( TypeLibraryManager.ROLE,
  +                         TypeLibraryManager.class,
  +                         PREFIX + "library.DefaultTypeLibraryManager" );
           createComponent( Executor.ROLE,
                            Executor.class,
                            PREFIX + "executor.DefaultExecutor" );
  @@ -391,60 +402,6 @@
           if( object instanceof Initializable )
           {
               ( (Initializable)object ).initialize();
  -        }
  -    }
  -
  -    /**
  -     * Deploys all type libraries in a directory.
  -     */
  -    private void deployFromDirectories( final Deployer deployer,
  -                                        final File[] directories,
  -                                        final FilenameFilter filter )
  -        throws DeploymentException
  -    {
  -        for( int i = 0; i < directories.length; i++ )
  -        {
  -            File directory = directories[ i ];
  -            final File[] files = directory.listFiles( filter );
  -
  -            if( null != files )
  -            {
  -                deployFiles( deployer, files );
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Deploys a set of type libraries.
  -     */
  -    private void deployFiles( final Deployer deployer, final File[] files )
  -        throws DeploymentException
  -    {
  -        for( int i = 0; i < files.length; i++ )
  -        {
  -            final String filename = files[ i ].getName();
  -
  -            int index = filename.lastIndexOf( '.' );
  -            if( -1 == index )
  -            {
  -                index = filename.length();
  -            }
  -
  -            try
  -            {
  -                final File file = files[ i ].getCanonicalFile();
  -                final TypeLibraryDeployer typeDeployer = deployer.createDeployer( file );
  -                typeDeployer.deployAll();
  -            }
  -            catch( final DeploymentException de )
  -            {
  -                throw de;
  -            }
  -            catch( final Exception e )
  -            {
  -                final String message = REZ.getString( "bad-filename.error", files[ i ] );
  -                throw new DeploymentException( message, e );
  -            }
           }
       }
   
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/DefaultLibrary.java
  
  Index: DefaultLibrary.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.components.library;
  
  import java.net.URL;
  import org.apache.avalon.excalibur.extension.Extension;
  import org.apache.myrmidon.interfaces.library.Library;
  
  /**
   * The default library implementation.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/03 06:56:11 $
   */
  public class DefaultLibrary
      implements Library
  {
      private final String m_name;
      private final Extension m_extension;
      private final ClassLoader m_classLoader;
      private final URL[] m_classpath;
  
      public DefaultLibrary( final String name,
                             final Extension extension,
                             final ClassLoader classLoader,
                             final URL[] classpath )
      {
          m_name = name;
          m_extension = extension;
          m_classLoader = classLoader;
          m_classpath = classpath;
      }
  
      /**
       * Returns the name of the library, if any.
       */
      public String getName()
      {
          return m_name;
      }
  
      /**
       * Returns the library meta-info, if any.
       */
      public Extension getExtension()
      {
          return m_extension;
      }
  
      /**
       * Returns the ClassLoader for the library.
       */
      public ClassLoader getClassLoader()
      {
          return m_classLoader;
      }
  
      /**
       * Returns the classpath for the library.
       */
      public URL[] getClassPath()
      {
          return m_classpath;
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/DefaultLibraryManager.java
  
  Index: DefaultLibraryManager.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.components.library;
  
  import java.io.File;
  import java.net.JarURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
  import java.util.jar.Manifest;
  import org.apache.aut.nativelib.PathUtil;
  import org.apache.avalon.excalibur.extension.Extension;
  import org.apache.avalon.excalibur.extension.OptionalPackage;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.myrmidon.interfaces.ComponentException;
  import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
  import org.apache.myrmidon.interfaces.library.Library;
  import org.apache.myrmidon.interfaces.library.LibraryManager;
  
  /**
   * The default library manager implementation.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/03 06:56:11 $
   */
  public class DefaultLibraryManager
      implements Serviceable, Contextualizable, LibraryManager
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( DefaultLibraryManager.class );
  
      private ExtensionManager m_extensionManager;
  
      private ClassLoader m_rootClassLoader;
  
      /**
       * Map from File/ArrayList to the ClassLoader for that file/files.
       */
      private final Map m_classLoaders = new HashMap();
  
      public void contextualize( final Context context ) throws ContextException
      {
          m_rootClassLoader = (ClassLoader)context.get( "myrmidon.shared.classloader" );
      }
  
      public void service( final ServiceManager serviceManager )
          throws ServiceException
      {
          m_extensionManager = (ExtensionManager)serviceManager.lookup( ExtensionManager.ROLE );
      }
  
      /**
       * Creates a library for a ClassLoader.
       */
      public Library createLibrary( final ClassLoader classLoader )
          throws Exception
      {
          // Try to extract classpath from ClassLoader
          final ArrayList classPath = new ArrayList();
          for( ClassLoader loader = classLoader; loader != null; loader = loader.getParent() )
          {
              prependClassPath( loader, classPath );
          }
          final URL[] libClassPath = (URL[])classPath.toArray( new URL[ classPath.size() ] );
  
          return new DefaultLibrary( null, null, classLoader, libClassPath );
      }
  
      /**
       * Returns the library for an extension.
       */
      public Library getLibrary( final String libName ) throws Exception
      {
          throw new Exception( "not implemented" );
      }
  
      /**
       * Creates a library for a set of files.
       */
      public Library createLibrary( final File[] files )
          throws Exception
      {
          try
          {
              // Build a list of optional packages for the files
              final OptionalPackage[] packages = new OptionalPackage[ files.length ];
              for( int i = 0; i < files.length; i++ )
              {
                  final File canonFile = files[ i ].getCanonicalFile();
                  packages[ i ] = toOptionalPackage( canonFile );
              }
  
              // Build the classloaders for the required extensions
              final ClassLoader[] parentClassLoaders = buildParentClassLoaders( packages, new HashSet() );
  
              // Build the classloader
              final URL[] urls = toUrls( files );
              final ClassLoader classLoader = new MultiParentURLClassLoader( urls, parentClassLoaders );
  
              return new DefaultLibrary( null, null, classLoader, urls );
          }
          catch( final Exception e )
          {
              final String formattedPath = PathUtil.formatPath( files );
              final String message = REZ.getString( "create-classloader-for-files.error", formattedPath );
              throw new ComponentException( message, e );
          }
      }
  
      /**
       * Builds the parent classloaders for a set of optional packages.  That is,
       * the classloaders for all of the extensions required by the given set
       * of optional packages.
       */
      private ClassLoader[] buildParentClassLoaders( final OptionalPackage[] packages,
                                                     final Set pending )
          throws Exception
      {
          final ArrayList classLoaders = new ArrayList();
  
          // Include the common class loader
          classLoaders.add( m_rootClassLoader );
  
          // Build the classloader for each optional package, filtering out duplicates
          for( int i = 0; i < packages.length; i++ )
          {
              final OptionalPackage optionalPackage = packages[ i ];
  
              // Locate the dependencies for this jar file
              final OptionalPackage[] requiredPackages = getOptionalPackagesFor( optionalPackage );
  
              // Build the classloader for the package
              for( int j = 0; j < requiredPackages.length; j++ )
              {
                  final OptionalPackage requiredPackage = requiredPackages[ j ];
                  final ClassLoader classLoader = buildClassLoader( requiredPackage, pending );
                  if( !classLoaders.contains( classLoader ) )
                  {
                      classLoaders.add( classLoader );
                  }
              }
          }
  
          return (ClassLoader[])classLoaders.toArray( new ClassLoader[ classLoaders.size() ] );
      }
  
      /**
       * Builds the classloader for an optional package.
       */
      private ClassLoader buildClassLoader( final OptionalPackage pkg,
                                            final Set pending )
          throws Exception
      {
          final File jarFile = pkg.getFile();
  
          // Check for cached classloader
          ClassLoader classLoader = (ClassLoader)m_classLoaders.get( jarFile );
          if( classLoader != null )
          {
              return classLoader;
          }
  
          // Check for cyclic dependency
          if( pending.contains( jarFile ) )
          {
              final String message = REZ.getString( "dependency-cycle.error", jarFile );
              throw new Exception( message );
          }
          pending.add( jarFile );
  
          // Build the classloaders for the extensions required by this optional
          // package
          final ClassLoader[] parentClassLoaders =
              buildParentClassLoaders( new OptionalPackage[]{pkg}, pending );
  
          // Create and cache the classloader
          final URL[] urls = {jarFile.toURL()};
          classLoader = new MultiParentURLClassLoader( urls, parentClassLoaders );
          m_classLoaders.put( jarFile, classLoader );
          pending.remove( jarFile );
          return classLoader;
      }
  
      /**
       * Locates the optional packages required by an optional package.
       */
      private OptionalPackage[] getOptionalPackagesFor( final OptionalPackage pkg )
          throws Exception
      {
          // Locate the optional packages that provide the required extesions
          final Extension[] required = pkg.getRequiredExtensions();
          final ArrayList packages = new ArrayList();
          for( int i = 0; i < required.length; i++ )
          {
              final Extension extension = required[ i ];
              final OptionalPackage optionalPackage = m_extensionManager.getOptionalPackage( extension );
              if( optionalPackage == null )
              {
                  final String message =
                      REZ.getString( "unsatisfied.extension.error",
                                     pkg.getFile(),
                                     extension.getExtensionName(),
                                     extension.getSpecificationVersion() );
                  throw new Exception( message );
              }
              packages.add( optionalPackage );
          }
  
          return (OptionalPackage[])packages.toArray( new OptionalPackage[ packages.size() ] );
      }
  
      /**
       * Prepends the classpath for a classloader.
       */
      private void prependClassPath( final ClassLoader loader, final ArrayList classPathUrls )
          throws Exception
      {
          if( !( loader instanceof URLClassLoader ) )
          {
              final String message = REZ.getString( "get-classpath-for-loader.error" );
              throw new Exception( message );
          }
          final URLClassLoader urlClassLoader = (URLClassLoader)loader;
          final URL[] urls = urlClassLoader.getURLs();
          for( int i = 0; i < urls.length; i++ )
          {
              final URL url = urls[ i ];
              classPathUrls.add( i, url );
          }
      }
  
      /**
       * Assembles a set of files into a URL classpath.
       */
      private URL[] toUrls( final File[] files )
          throws MalformedURLException
      {
          final URL[] urls = new URL[ files.length ];
          for( int i = 0; i < files.length; i++ )
          {
              final File file = files[ i ];
              if( file.isDirectory() )
              {
                  urls[i] = new URL( file.toURL() + "/" );
              }
              else
              {
                  urls[ i ] = file.toURL();
              }
          }
  
          return urls;
      }
  
      /**
       * Builds an OptionalPackage for a Jar file.
       */
      private OptionalPackage toOptionalPackage( final File file )
          throws Exception
      {
          if( !file.exists() )
          {
              final String message = REZ.getString( "no-file.error", file );
              throw new Exception( message );
          }
          if( file.isDirectory() )
          {
              // TODO - handle directories
              final String message = REZ.getString( "file-is-dir.error", file );
              throw new Exception( message );
          }
  
          // Determine the extensions required by this file
          final URL url = new URL( "jar:" + file.toURL() + "!/" );
          final JarURLConnection connection = (JarURLConnection)url.openConnection();
          final Manifest manifest = connection.getManifest();
          final Extension[] required = Extension.getRequired( manifest );
          return new OptionalPackage( file, new Extension[ 0 ], required );
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/DefaultTypeLibraryManager.java
  
  Index: DefaultTypeLibraryManager.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.components.library;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.List;
  import org.apache.aut.nativelib.PathUtil;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.excalibur.io.ExtensionFileFilter;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.myrmidon.interfaces.library.Library;
  import org.apache.myrmidon.interfaces.library.TypeLibraryManager;
  import org.apache.myrmidon.interfaces.library.LibraryManager;
  import org.apache.myrmidon.interfaces.ComponentException;
  
  /**
   * The default type library manager implementation.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/03 06:56:11 $
   */
  public class DefaultTypeLibraryManager
      implements TypeLibraryManager, Contextualizable, Serviceable
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( DefaultTypeLibraryManager.class );
  
      private Context m_context;
      private LibraryManager m_libManager;
  
      public void contextualize( final Context context )
          throws ContextException
      {
          m_context = context;
      }
  
      public void service( final ServiceManager serviceManager )
          throws ServiceException
      {
          m_libManager = (LibraryManager)serviceManager.lookup( LibraryManager.ROLE );
      }
  
      /**
       * Locates a type library by name.
       */
      public Library getTypeLibrary( final String libraryName )
          throws Exception
      {
          final File[] extPath;
  
          try
          {
              //TODO: In future this will be expanded to allow
              //users to specify search path or automagically
              //add entries to lib path (like user specific or
              //workspace specific)
              final String name = libraryName.replace( '/', File.separatorChar ) + ".atl";
  
              extPath = (File[])m_context.get( "myrmidon.antlib.path" );
              for( int i = 0; i < extPath.length; i++ )
              {
                  final File extDir = extPath[ i ];
                  final File library = new File( extDir, name );
  
                  if( library.exists() )
                  {
                      return buildLibrary( library );
                  }
              }
          }
          catch( final Exception e )
          {
              final String message = REZ.getString( "load-library.error", libraryName );
              throw new ComponentException( message, e );
          }
  
          final String formattedPath = PathUtil.formatPath( extPath );
          final String message = REZ.getString( "no-library.error", libraryName, formattedPath );
          throw new Exception( message );
      }
  
      /**
       * Locates the core type libraries.
       */
      public Library[] getCoreTypeLibraries() throws Exception
      {
          final ExtensionFileFilter filter = new ExtensionFileFilter( ".atl" );
          final File[] directories = (File[])m_context.get( "myrmidon.lib.path" );
  
          final ArrayList libs = new ArrayList();
          for( int i = 0; i < directories.length; i++ )
          {
              final File directory = directories[ i ];
              final File[] files = directory.listFiles( filter );
              if( null != files )
              {
                  buildLibraries( files, libs );
              }
          }
  
          return (Library[])libs.toArray( new Library[ libs.size() ] );
      }
  
      /**
       * Builds library wrappers for a set of files.
       */
      private void buildLibraries( final File[] files, final List libs )
          throws Exception
      {
          for( int i = 0; i < files.length; i++ )
          {
              final File file = files[ i ];
              libs.add( buildLibrary( file ) );
          }
      }
  
      /**
       * Builds a library wrapper for a file.
       */
      private Library buildLibrary( final File library )
          throws Exception
      {
          if( !library.canRead() )
          {
              final String message = REZ.getString( "no-read.error", library );
              throw new Exception( message );
          }
          return m_libManager.createLibrary( new File[] { library } );
      }
  
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/MultiParentURLClassLoader.java
  
  Index: MultiParentURLClassLoader.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.components.library;
  
  import java.io.IOException;
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Enumeration;
  import java.util.List;
  import java.util.Set;
  import java.util.HashSet;
  
  /**
   * A URLClassLoader with more than one parent.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/03 06:56:11 $
   */
  public class MultiParentURLClassLoader
      extends URLClassLoader
  {
      private final ClassLoader[] m_parents;
  
      /**
       * Constructs a new URLClassLoader for the given URLs.
       *
       * @param urls the URLs from which to load classes and resources
       * @param parents the parent class loaderer for delegation
       */
      public MultiParentURLClassLoader( final URL[] urls, final ClassLoader[] parents )
      {
          super( urls );
          m_parents = parents;
      }
  
      /**
       * Finds a class.
       *
       * @param name the name of the class
       * @return the resulting class
       * @exception java.lang.ClassNotFoundException if the class could not be found
       */
      protected Class findClass( final String name )
          throws ClassNotFoundException
      {
          // Try the parent classloaders first
          for( int i = 0; i < m_parents.length; i++ )
          {
              try
              {
                  final ClassLoader parent = m_parents[ i ];
                  return parent.loadClass( name );
              }
              catch( ClassNotFoundException e )
              {
                  // Ignore - continue to the next ClassLoader
              }
          }
  
          // Now this classloader
          return super.findClass( name );
      }
  
      /**
       * Finds a resource.
       *
       * @param name the name of the resource
       * @return a <code>URL</code> for the resource, or <code>null</code>
       * if the resource could not be found.
       */
      public URL findResource( final String name )
      {
          // Try the parent classloaders first
          for( int i = 0; i < m_parents.length; i++ )
          {
              final ClassLoader parent = m_parents[ i ];
              final URL resource = parent.getResource( name );
              if( resource != null )
              {
                  return resource;
              }
          }
  
          // Now this classloader
          return super.findResource( name );
      }
  
      /**
       * Returns an Enumeration of URLs representing all of the resources
       * having the specified name.
       *
       * @param name the resource name
       * @throws java.io.IOException if an I/O exception occurs
       * @return an <code>Enumeration</code> of <code>URL</code>s
       */
      public Enumeration findResources( final String name ) throws IOException
      {
          // Need to filter out duplicate resources
          final ArrayList urls = new ArrayList();
          final Set urlSet = new HashSet();
  
          // Gather the resources from the parent classloaders
          for( int i = 0; i < m_parents.length; i++ )
          {
              final ClassLoader parent = m_parents[ i ];
              final Enumeration enum = parent.getResources( name );
              addUrls( enum, urls, urlSet );
          }
  
          // Gather the resources from this classloader
          addUrls( super.findResources( name ), urls, urlSet );
  
          return Collections.enumeration( urls );
      }
  
      /**
       * Adds those URLs not already present.
       */
      private void addUrls( final Enumeration enum,
                            final List urls,
                            final Set urlSet )
      {
          while( enum.hasMoreElements() )
          {
              final URL url = (URL)enum.nextElement();
              final String urlStr = url.toExternalForm();
              if( !urlSet.contains( urlStr ) )
              {
                  urls.add( url );
                  urlSet.add( urlStr );
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  no-read.error=Could not read library "{0}".
  no-file.error=Could not find library "{0}".
  file-is-dir.error=Library "{0}" is a directory.
  no-library.error=Could not locate Type Library "{0}" in {1}
  load-library.error=Could not load Type Library "{0}".
  get-classpath-for-loader.error=Could not determine the class-path for a ClassLoader.
  create-classloader-for-files.error=Could not create a ClassLoader for {0}.
  dependency-cycle.error=Cycle in dependencies for library "{0}".
  unsatisfied.extension.error=Library "{0}" requires unknown extension "{1}" ( version {2}).
  
  
  
  1.53      +18 -60    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
  
  Index: DefaultWorkspace.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- DefaultWorkspace.java	2 May 2002 08:52:45 -0000	1.52
  +++ DefaultWorkspace.java	3 May 2002 06:56:11 -0000	1.53
  @@ -7,25 +7,22 @@
    */
   package org.apache.myrmidon.components.workspace;
   
  -import java.io.File;
   import java.util.HashMap;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.context.ContextException;
  -import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.service.DefaultServiceManager;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  -import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   import org.apache.myrmidon.interfaces.deployer.TypeLibraryDeployer;
   import org.apache.myrmidon.interfaces.event.TaskEventManager;
   import org.apache.myrmidon.interfaces.executor.ExecutionContainer;
   import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
   import org.apache.myrmidon.interfaces.executor.Executor;
  +import org.apache.myrmidon.interfaces.library.Library;
  +import org.apache.myrmidon.interfaces.library.TypeLibraryManager;
   import org.apache.myrmidon.interfaces.oldmodel.Dependency;
   import org.apache.myrmidon.interfaces.oldmodel.Project;
   import org.apache.myrmidon.interfaces.oldmodel.Target;
  @@ -39,11 +36,11 @@
    * This is the default implementation of Workspace.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.52 $ $Date: 2002/05/02 08:52:45 $
  + * @version $Revision: 1.53 $ $Date: 2002/05/03 06:56:11 $
    */
   public class DefaultWorkspace
       extends AbstractLogEnabled
  -    implements Workspace, ExecutionContainer, Contextualizable
  +    implements Workspace, ExecutionContainer
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( DefaultWorkspace.class );
  @@ -56,7 +53,6 @@
       private Executor m_executor;
       private TypeManager m_typeManager;
       private Deployer m_deployer;
  -    private Context m_context;
   
       /** A map from Project object -> ProjectEntry for that project. */
       private HashMap m_entries = new HashMap();
  @@ -99,11 +95,6 @@
           m_deployer = (Deployer)serviceManager.lookup( Deployer.ROLE );
       }
   
  -    public void contextualize( final Context context ) throws ContextException
  -    {
  -        m_context = context;
  -    }
  -
       /**
        * Execute a target in a particular project.
        * Execute in the project context.
  @@ -120,40 +111,8 @@
           executeTarget( entry, target );
       }
   
  -    private File findTypeLib( final String libraryName )
  -        throws Exception
  -    {
  -        //TODO: In future this will be expanded to allow
  -        //users to specify search path or automagically
  -        //add entries to lib path (like user specific or
  -        //workspace specific)
  -        final String name = libraryName.replace( '/', File.separatorChar ) + ".atl";
  -
  -        final File[] extPath = (File[])m_context.get( "myrmidon.antlib.path" );
  -        for( int i = 0; i < extPath.length; i++ )
  -        {
  -            final File extDir = extPath[ i ];
  -            final File library = new File( extDir, name );
  -
  -            if( library.exists() )
  -            {
  -                if( !library.canRead() )
  -                {
  -                    final String message = REZ.getString( "no-read.error", library );
  -                    throw new TaskException( message );
  -                }
  -                else
  -                {
  -                    return library;
  -                }
  -            }
  -        }
  -
  -        final String message = REZ.getString( "no-library.error", libraryName );
  -        throw new TaskException( message );
  -    }
  -
  -    private void deployTypeLib( final Deployer deployer,
  +    private void deployTypeLib( final TypeLibraryManager typeLibraryManager,
  +                                final Deployer deployer,
                                   final Project project )
           throws Exception
       {
  @@ -162,19 +121,19 @@
           for( int i = 0; i < typeLibs.length; i++ )
           {
               final TypeLib typeLib = typeLibs[ i ];
  -            deployTypeLib( deployer, typeLib );
  +            deployTypeLib( typeLibraryManager, deployer, typeLib );
           }
       }
   
  -    private void deployTypeLib( final Deployer deployer,
  +    private void deployTypeLib( final TypeLibraryManager typeLibraryManager,
  +                                final Deployer deployer,
                                   final TypeLib typeLib )
           throws Exception
       {
  -        final File file = findTypeLib( typeLib.getLibrary() );
  -
           try
           {
  -            final TypeLibraryDeployer typeDeployer = deployer.createDeployer( file );
  +            final Library library = typeLibraryManager.getTypeLibrary( typeLib.getLibrary() );
  +            final TypeLibraryDeployer typeDeployer = deployer.createDeployer( library );
               if( null == typeLib.getRole() )
               {
                   // Deploy everything in the typelib
  @@ -183,16 +142,13 @@
               else
               {
                   // Deploy the specified type
  -                typeDeployer.
  -                    deployType( typeLib.getRole(),
  -                                typeLib.getName() );
  +                typeDeployer.deployType( typeLib.getRole(), typeLib.getName() );
               }
           }
  -        catch( final DeploymentException de )
  +        catch( final Exception e )
           {
  -            final String message = REZ.getString( "no-deploy.error",
  -                                                  typeLib.getLibrary(), file );
  -            throw new TaskException( message, de );
  +            final String message = REZ.getString( "no-deploy.error", typeLib.getLibrary() );
  +            throw new TaskException( message, e );
           }
       }
   
  @@ -242,7 +198,9 @@
           serviceManager.put( ExecutionFrame.ROLE, frame );
   
           // Deploy the imported typelibs
  -        deployTypeLib( deployer, project );
  +        final TypeLibraryManager typeLibraryManager =
  +            (TypeLibraryManager)m_frame.getServiceManager().lookup( TypeLibraryManager.ROLE );
  +        deployTypeLib( typeLibraryManager, deployer, project );
   
           return frame;
       }
  
  
  
  1.11      +1 -3      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/Resources.properties,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Resources.properties	13 Mar 2002 07:35:18 -0000	1.10
  +++ Resources.properties	3 May 2002 06:56:11 -0000	1.11
  @@ -1,6 +1,4 @@
  -no-read.error=Unable to read library at {0}.
  -no-library.error=Unable to locate Type Library {0}.
  -no-deploy.error=Error deploying type library {0} at {1}.
  +no-deploy.error=Error deploying type library {0}.
   bad-deployer-config.error=Error configuring deployer.
   bad-frame.error=Error setting up ExecutionFrame.
   no-project.error=Project {0} not found.
  
  
  
  1.10      +6 -17     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/deployer/Deployer.java
  
  Index: Deployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/deployer/Deployer.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Deployer.java	25 Apr 2002 01:41:50 -0000	1.9
  +++ Deployer.java	3 May 2002 06:56:11 -0000	1.10
  @@ -7,15 +7,15 @@
    */
   package org.apache.myrmidon.interfaces.deployer;
   
  -import java.io.File;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.myrmidon.interfaces.library.Library;
   
   /**
    * This class deploys type libraries into a registry.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.9 $ $Date: 2002/04/25 01:41:50 $
  + * @version $Revision: 1.10 $ $Date: 2002/05/03 06:56:11 $
    */
   public interface Deployer
   {
  @@ -23,25 +23,14 @@
       String ROLE = Deployer.class.getName();
   
       /**
  -     * Returns the deployer for the type libraries contained in a ClassLoader,
  -     * creating the deployer if necessary.
  -     *
  -     * @param loader The ClassLoader to get the deployer for.
  -     * @return the deployer for this loader.
  -     * @exception DeploymentException if an error occurs.
  -     */
  -    TypeLibraryDeployer createDeployer( ClassLoader loader )
  -        throws DeploymentException;
  -
  -    /**
  -     * Returns the deployer for a type library, creating the deployer if
  +     * Returns the deployer for a library, creating the deployer if
        * necessary.
        *
  -     * @param file the file containing the type library.
  -     * @return the deployer for this type library.
  +     * @param library The library.
  +     * @return The deployer for this type library.
        * @exception DeploymentException if an error occurs.
        */
  -    TypeLibraryDeployer createDeployer( File file )
  +    TypeLibraryDeployer createDeployer( Library library )
           throws DeploymentException;
   
       /**
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/library/Library.java
  
  Index: Library.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.interfaces.library;
  
  import java.net.URL;
  import org.apache.avalon.excalibur.extension.Extension;
  
  /**
   * This interface represents a library of Java classes, and deployable types.
   * This interface provides a unified view of typelibs, extensions, the container API,
   * the java runtime, and ad hoc classpaths.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/03 06:56:11 $
   */
  public interface Library
  {
      /**
       * Returns the name of the library, if any.
       */
      String getName();
  
      /**
       * Returns the library meta-info, if any.
       */
      Extension getExtension();
  
      /**
       * Returns the ClassLoader for the library.
       */
      ClassLoader getClassLoader();
  
      /**
       * Returns the class-path for the library.
       */
      URL[] getClassPath();
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/library/LibraryManager.java
  
  Index: LibraryManager.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.interfaces.library;
  
  import java.io.File;
  
  /**
   * Manages a set of libraries.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/03 06:56:11 $
   */
  public interface LibraryManager
  {
      String ROLE = LibraryManager.class.getName();
  
      /**
       * Returns the library for an extension.
       */
      Library getLibrary( String libName ) throws Exception;
  
      /**
       * Creates a library wrapper for a ClassLoader.
       */
      Library createLibrary( ClassLoader classLoader ) throws Exception;
  
      /**
       * Creates a library for a set of files, locating any extensions required
       * by the files.
       *
       * <p>The ancestors of the library ClassLoader will include the ClassLoader
       * for the shared library, along with the ClassLoaders for any extensions
       * required by the library.  It is guaranteed that each extension will
       * appear at most once in the ClassLoader hierarchy, so that extension
       * classes can be shared across the libraries created by this library
       * manager.
       */
      Library createLibrary( File[] files ) throws Exception;
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/library/TypeLibraryManager.java
  
  Index: TypeLibraryManager.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.interfaces.library;
  
  /**
   * Manages a set of type libraries.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/03 06:56:11 $
   */
  public interface TypeLibraryManager
  {
      String ROLE = TypeLibraryManager.class.getName();
  
      /**
       * Locates a type library by name.
       *
       * @param name The name of the library to locate.
       * @throws Exception If the library could not be found, or if more than
       *                   one library was found.
       */
      Library getTypeLibrary( String name ) throws Exception;
  
      /**
       * Returns the core type libraries.
       */
      Library[] getCoreTypeLibraries() throws Exception;
  }
  
  
  
  1.31      +12 -9     jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/AbstractComponentTest.java
  
  Index: AbstractComponentTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/AbstractComponentTest.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- AbstractComponentTest.java	2 May 2002 04:03:53 -0000	1.30
  +++ AbstractComponentTest.java	3 May 2002 06:56:11 -0000	1.31
  @@ -25,7 +25,6 @@
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.myrmidon.AbstractContainerTestCase;
   import org.apache.myrmidon.api.TaskContext;
  -import org.apache.myrmidon.components.classloader.DefaultClassLoaderManager;
   import org.apache.myrmidon.components.configurer.DefaultConfigurer;
   import org.apache.myrmidon.components.converter.DefaultMasterConverter;
   import org.apache.myrmidon.components.deployer.DefaultDeployer;
  @@ -38,7 +37,8 @@
   import org.apache.myrmidon.components.property.DefaultPropertyStore;
   import org.apache.myrmidon.components.workspace.DefaultExecutionFrame;
   import org.apache.myrmidon.components.workspace.DefaultTaskContext;
  -import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
  +import org.apache.myrmidon.components.library.DefaultLibraryManager;
  +import org.apache.myrmidon.components.library.DefaultTypeLibraryManager;
   import org.apache.myrmidon.interfaces.configurer.Configurer;
   import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  @@ -53,12 +53,14 @@
   import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeManager;
   import org.apache.myrmidon.interfaces.event.TaskEventManager;
  +import org.apache.myrmidon.interfaces.library.LibraryManager;
  +import org.apache.myrmidon.interfaces.library.TypeLibraryManager;
   
   /**
    * A base class for tests for the default components.
    *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.30 $ $Date: 2002/05/02 04:03:53 $
  + * @version $Revision: 1.31 $ $Date: 2002/05/03 06:56:11 $
    */
   public abstract class AbstractComponentTest
       extends AbstractContainerTestCase
  @@ -104,8 +106,12 @@
               m_serviceManager.put( Executor.ROLE, component );
               components.add( component );
   
  -            component = createComponent( ClassLoaderManager.ROLE, DefaultClassLoaderManager.class );
  -            m_serviceManager.put( ClassLoaderManager.ROLE, component );
  +            component = createComponent( LibraryManager.ROLE, DefaultLibraryManager.class );
  +            m_serviceManager.put( LibraryManager.ROLE, component );
  +            components.add( component );
  +
  +            component = createComponent( TypeLibraryManager.ROLE, DefaultTypeLibraryManager.class );
  +            m_serviceManager.put( TypeLibraryManager.ROLE, component );
               components.add( component );
   
               component = createComponent( ExtensionManager.ROLE, DefaultExtensionManager.class );
  @@ -192,6 +198,7 @@
           parameters.put( "myrmidon.home", homeDir );
           final File extDir = getTestDirectory( "home/ext" );
           parameters.put( "myrmidon.ext.path", new File[] { extDir } );
  +        parameters.put( "myrmidon.shared.classloader", getClass().getClassLoader() );
           return parameters;
       }
   
  @@ -202,10 +209,6 @@
       protected Object createComponent( final String role, final Class defaultImpl )
           throws Exception
       {
  -        if( role.equals( ClassLoaderManager.ROLE ) )
  -        {
  -            return new DefaultClassLoaderManager( getClass().getClassLoader() );
  -        }
           return defaultImpl.newInstance();
       }
   
  
  
  
  1.6       +25 -11    jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/deployer/test/DefaultDeployerTestCase.java
  
  Index: DefaultDeployerTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/deployer/test/DefaultDeployerTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultDeployerTestCase.java	26 Apr 2002 03:12:51 -0000	1.5
  +++ DefaultDeployerTestCase.java	3 May 2002 06:56:11 -0000	1.6
  @@ -11,12 +11,14 @@
   import org.apache.aut.converter.Converter;
   import org.apache.aut.converter.ConverterException;
   import org.apache.myrmidon.components.AbstractComponentTest;
  -import org.apache.myrmidon.components.deployer.DefaultDeployer;
   import org.apache.myrmidon.components.TestDataType;
  +import org.apache.myrmidon.components.deployer.DefaultDeployer;
   import org.apache.myrmidon.interfaces.deployer.ConverterDefinition;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
   import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   import org.apache.myrmidon.interfaces.deployer.TypeLibraryDeployer;
  +import org.apache.myrmidon.interfaces.library.Library;
  +import org.apache.myrmidon.interfaces.library.LibraryManager;
   import org.apache.myrmidon.interfaces.type.TypeException;
   import org.apache.myrmidon.interfaces.type.TypeFactory;
   
  @@ -67,6 +69,18 @@
       }
   
       /**
  +     * Create the test deployer
  +     */
  +    private TypeLibraryDeployer getTestDeployer()
  +        throws Exception
  +    {
  +        final File file = getTestResource( "test.atl" );
  +        final LibraryManager libraryManager = (LibraryManager)getServiceManager().lookup( LibraryManager.ROLE );
  +        final Library library = libraryManager.createLibrary( new File[] { file } );
  +        return m_deployer.createDeployer( library );
  +    }
  +
  +    /**
        * Tests deployment of a single type from a ClassLoader.
        */
       public void testSingleType() throws Exception
  @@ -77,10 +91,10 @@
           // Create the type definition
           final TypeDefinition typeDef = new TypeDefinition( typeName, TestDataType.ROLE, classname );
   
  -        final ClassLoader classLoader = getClass().getClassLoader();
  -        final TypeLibraryDeployer typeDeployer = m_deployer.createDeployer( classLoader );
  +        final TypeLibraryDeployer typeDeployer = getTestDeployer();
   
  -        // Make sure the test types have not been deployed
  +        // Make sure the test types have not been deployed.  Do this after
  +        // the deployer has been created
           assertTypesNotRegistered();
   
           // Deploy the type
  @@ -105,10 +119,10 @@
           final ConverterDefinition typeDef =
               new ConverterDefinition( classname, source, destClass );
   
  -        final ClassLoader classLoader = getClass().getClassLoader();
  -        final TypeLibraryDeployer typeDeployer = m_deployer.createDeployer( classLoader );
  +        final TypeLibraryDeployer typeDeployer = getTestDeployer();
   
  -        // Make sure the test types have not been deployed
  +        // Make sure the test types have not been deployed.  Do this after
  +        // the deployer has been created
           assertTypesNotRegistered();
   
           // Deploy the type
  @@ -120,14 +134,14 @@
       }
   
       /**
  -     * Tests deployment of types from a typelib descriptor.
  +     * Tests deployment of all types from a typelib descriptor.
        */
       public void testLibDescriptor() throws Exception
       {
  -        final File typelib = getTestResource( "test.atl" );
  -        final TypeLibraryDeployer typeDeployer = m_deployer.createDeployer( typelib );
  +        final TypeLibraryDeployer typeDeployer = getTestDeployer();
   
  -        // Make sure the test types have not been deployed
  +        // Make sure the test types have not been deployed.  Do this after
  +        // the deployer has been created
           assertTypesNotRegistered();
   
           // Deploy all the types from the descriptor
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/library/test/DefaultLibraryManagerTestCase.java
  
  Index: DefaultLibraryManagerTestCase.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.components.library.test;
  
  import java.io.File;
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.util.Enumeration;
  import java.util.Map;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.myrmidon.components.AbstractComponentTest;
  import org.apache.myrmidon.components.library.DefaultLibraryManager;
  import org.apache.myrmidon.interfaces.library.LibraryManager;
  import org.apache.myrmidon.interfaces.library.Library;
  
  /**
   * Test cases for the DefaultClassLoaderManager.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/03 06:56:11 $
   */
  public class DefaultLibraryManagerTestCase
      extends AbstractComponentTest
  {
      private static final String UNSHARED_PKG_NAME =
          getPackageName( DefaultLibraryManagerTestCase.class ) + ".libs.unshared";
      private static final String UNSHARED_RES_NAME = getResourceName( UNSHARED_PKG_NAME, "unshared.txt" );
      private static final String UNSHARED_CLASS_NAME = UNSHARED_PKG_NAME + ".UnsharedClass";
  
      private static final String SHARED_PKG_NAME =
          getPackageName( DefaultLibraryManagerTestCase.class ) + ".libs.shared";
      private static final String SHARED_RES_NAME = getResourceName( SHARED_PKG_NAME, "shared.txt" );
      private static final String SHARED_CLASS_NAME = SHARED_PKG_NAME + ".SharedClass";
  
      private static final String EXTN_PKG_NAME =
          getPackageName( DefaultLibraryManagerTestCase.class ) + ".libs.extn";
      private static final String EXTN_RES_NAME = getResourceName( EXTN_PKG_NAME, "extn.txt" );
      private static final String EXTN_CLASS_NAME = EXTN_PKG_NAME + ".ExtnClass";
  
      private File m_commonJar;
      private ClassLoader m_commonClassLoader;
      private LibraryManager m_libraryManager;
  
      public DefaultLibraryManagerTestCase( final String name )
      {
          super( name );
      }
  
      /**
       * Sets up the test.
       */
      protected void setUp() throws Exception
      {
          super.setUp();
  
          m_commonJar = getTestResource( "common.jar" );
          final URL commonJarUrl = m_commonJar.toURL();
          m_commonClassLoader = new URLClassLoader( new URL[]{commonJarUrl} );
  
          assertClassFound( m_commonClassLoader, SHARED_CLASS_NAME );
          assertResourcesFound( m_commonClassLoader, SHARED_RES_NAME, m_commonJar );
  
          // Create the classloader mgr
          m_libraryManager = (LibraryManager)getServiceManager().lookup( LibraryManager.ROLE );
      }
  
      /**
       * Creates the parameters for the test.  Sub-classes can override this
       * method to set-up the parameters.
       */
      protected Map getParameters()
      {
          final Map parameters = super.getParameters();
          parameters.put( "myrmidon.ext.path", new File[] { getTestDirectory( "ext" ) } );
          parameters.put( "myrmidon.shared.classloader", m_commonClassLoader );
          return parameters;
      }
  
      /**
       * Returns the name of a resource in a package.
       */
      private static String getResourceName( final String pkgName,
                                             final String resname )
      {
          return pkgName.replace( '.', '/' ) + '/' + resname;
      }
  
      /**
       * Asserts that a class is not available in a classloader.
       */
      private void assertClassNotFound( final ClassLoader classLoader,
                                        final String className )
      {
          try
          {
              classLoader.loadClass( className );
              fail( "Class " + className + " should not be available." );
          }
          catch( ClassNotFoundException e )
          {
          }
      }
  
      /**
       * Asserts that a class is available in a classloader.
       */
      private void assertClassFound( final ClassLoader classLoader,
                                     final String className )
          throws Exception
      {
          assertClassFound( classLoader, className, classLoader );
      }
  
      /**
       * Asserts that a class is available in a classloader.
       */
      private void assertClassFound( final ClassLoader classLoader,
                                     final String className,
                                     final ClassLoader expectedClassLoader )
          throws Exception
      {
          try
          {
              final Class cls = classLoader.loadClass( className );
              assertSame( expectedClassLoader, cls.getClassLoader() );
              if( classLoader != expectedClassLoader )
              {
                  final Class expectedCls = expectedClassLoader.loadClass( className );
                  assertSame( expectedCls, cls );
              }
          }
          catch( ClassNotFoundException e )
          {
              fail( "Class " + className + " not found." );
          }
  
      }
  
      /**
       * Asserts that a resouce is not available in a classloader.
       */
      private void assertResourceNotFound( final ClassLoader classLoader,
                                           final String resName )
          throws Exception
      {
          assertNull( classLoader.getResource( resName ) );
          assertNull( classLoader.getResourceAsStream( resName ) );
          final Enumeration enum = classLoader.getResources( resName );
          assertTrue( !enum.hasMoreElements() );
      }
  
      /**
       * Asserts that a resource is available in a classloader.
       */
      private void assertResourcesFound( final ClassLoader classLoader,
                                         final String resName,
                                         final File expectedJar )
          throws Exception
      {
          assertResourcesFound( classLoader, resName, new File[]{expectedJar} );
      }
  
      /**
       * Asserts that a resource is available in a classloader.
       */
      private void assertResourcesFound( final ClassLoader classLoader,
                                         final String resName,
                                         final File[] expectedJars )
          throws Exception
      {
          final String[] expectedLocations = new String[ expectedJars.length ];
          for( int i = 0; i < expectedJars.length; i++ )
          {
              final File jar = expectedJars[ i ];
              expectedLocations[ i ] = "jar:" + jar.toURL() + "!/" + resName;
          }
  
          assertResourcesFound( classLoader, resName, expectedLocations );
      }
  
      /**
       * Asserts that a resource is available in a classloader.
       */
      private void assertResourcesFound( final ClassLoader classLoader,
                                         final String resName,
                                         final String[] expectedLocations )
          throws Exception
      {
          // Use the first in the list of expected locations as the location
          // of the resource returned by getResource()
          final URL resUrl = classLoader.getResource( resName );
          assertNotNull( resUrl );
          assertEquals( expectedLocations[ 0 ], resUrl.toString() );
  
          // Now check all of the resources returned by getResources()
          final Enumeration resources = classLoader.getResources( resName );
          for( int i = 0; i < expectedLocations.length; i++ )
          {
              final String expectedLocation = expectedLocations[ i ];
              assertTrue( resources.hasMoreElements() );
              final URL location = (URL)resources.nextElement();
              assertEquals( expectedLocation, location.toString() );
          }
          assertTrue( !resources.hasMoreElements() );
      }
  
      /**
       * Tests for a Jar with no required extensions.
       */
      public void testNoDependencies() throws Exception
      {
          // Make some assumptions about the common classloader
          assertClassNotFound( m_commonClassLoader, UNSHARED_CLASS_NAME );
          assertResourceNotFound( m_commonClassLoader, UNSHARED_RES_NAME );
  
          // Build the classloader
          final File jarFile = getTestResource( "no-dependencies.jar" );
          final Library lib = m_libraryManager.createLibrary( new File[] { jarFile } );
          final ClassLoader classLoader = lib.getClassLoader();
  
          // Check shared classes/resources
          assertClassFound( classLoader, SHARED_CLASS_NAME, m_commonClassLoader );
          assertResourcesFound( classLoader, SHARED_RES_NAME, new File[]{m_commonJar, jarFile} );
  
          // Check unshared classes/resources
          assertClassFound( classLoader, UNSHARED_CLASS_NAME );
          assertResourcesFound( classLoader, UNSHARED_RES_NAME, jarFile );
      }
  
      /**
       * Tests for a Jar with a single required extension.
       */
      public void testOneDependency() throws Exception
      {
          // Make some assumptions about the common classloader
          assertClassNotFound( m_commonClassLoader, UNSHARED_CLASS_NAME );
          assertResourceNotFound( m_commonClassLoader, UNSHARED_RES_NAME );
          assertClassNotFound( m_commonClassLoader, EXTN_CLASS_NAME );
          assertResourceNotFound( m_commonClassLoader, EXTN_RES_NAME );
  
          // Build the extension classloader
          final File extnJarFile = getTestResource( "ext/simple-extension.jar" );
          final Library extnLib = m_libraryManager.getLibrary( "test.simple" );
          final ClassLoader extnClassLoader = extnLib.getClassLoader();
  
          // Build the Jar classloader
          final File jarFile = getTestResource( "one-dependency.jar" );
          final Library lib = m_libraryManager.createLibrary( new File[] { jarFile } );
          final ClassLoader classLoader = lib.getClassLoader();
  
          // Check shared classes/resources
          assertClassFound( classLoader, SHARED_CLASS_NAME, m_commonClassLoader );
          assertResourcesFound( classLoader, SHARED_RES_NAME, new File[]{m_commonJar, extnJarFile, jarFile} );
  
          // Check extension classes/resources
          assertClassFound( classLoader, EXTN_CLASS_NAME, extnClassLoader );
          assertResourcesFound( classLoader, EXTN_RES_NAME, extnJarFile );
  
          // Check unshared classes/resources
          assertClassFound( classLoader, UNSHARED_CLASS_NAME );
          assertResourcesFound( classLoader, UNSHARED_RES_NAME, jarFile );
      }
  
      /**
       * Tests that classes from extensions can be shared across classloaders.
       */
      public void testShareClasses() throws Exception
      {
          // Build the extension classloader
          final File extnJarFile = getTestResource( "ext/simple-extension.jar" );
          final Library extnLib = m_libraryManager.getLibrary( "test.simple" );
          final ClassLoader extnClassLoader = extnLib.getClassLoader();
  
          // Build the Jar classloaders
          final File jarFile1 = getTestResource( "one-dependency.jar" );
          final Library lib1 = m_libraryManager.createLibrary( new File[] { jarFile1 } );
          final ClassLoader classLoader1 = lib1.getClassLoader();
          final File jarFile2 = getTestResource( "one-dependency-2.jar" );
          final Library lib2 = m_libraryManager.createLibrary( new File[] { jarFile2 } );
          final ClassLoader classLoader2 = lib2.getClassLoader();
  
          // Check extension classes/resources
          assertClassFound( classLoader1, EXTN_CLASS_NAME, extnClassLoader );
          assertResourcesFound( classLoader1, EXTN_RES_NAME, extnJarFile );
          assertClassFound( classLoader2, EXTN_CLASS_NAME, extnClassLoader );
          assertResourcesFound( classLoader2, EXTN_RES_NAME, extnJarFile );
      }
  
      /**
       * Tests detection of dependency cycles in extensions.
       */
      public void testCycle() throws Exception
      {
          final File jarFile = getTestResource( "ext/cycle-extension-1.jar" );
          try
          {
              m_libraryManager.createLibrary( new File[] { jarFile } );
              fail();
          }
          catch( final Exception e )
          {
              final Resources rez = getResourcesForTested( DefaultLibraryManager.class );
              final String[] messages = {
                  rez.getString( "create-classloader-for-file.error", jarFile ),
                  rez.getString( "dependency-cycle.error", jarFile )
              };
              assertSameMessage( messages, e );
          }
      }
  
      /**
       * add some classes to common loader only.
       *
       * unknown extension
       * multiple versions of the same extension
       * extn with requirement on itself
       *
       * jar with 1 and 2 extns:
       *   class/resources in parent
       *   class/resources in jar
       *   class/resources in extn
       *   class/resources in all
       *
       * jar with transitive extn
       *   class/resources in 2nd extn
       *
       * jar with transitive extn + explicit extn on same jar
       *   class/resources in 2nd extn
       *
       * Same classes:
       *     get extn explicitly and implicitly, and check classes are the same
       *     extn shared by 2 jars, using same extn and different extns
       *     classes in common classloader, shared by 2 jars
       *
       * multiple files:
       *     fetch classloader twice
       *     different path ordering
       *
       * tools.jar
       */
  }
  
  
  
  1.3       +16 -18    jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/AbstractTypeDef.java
  
  Index: AbstractTypeDef.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/AbstractTypeDef.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractTypeDef.java	25 Apr 2002 01:41:50 -0000	1.2
  +++ AbstractTypeDef.java	3 May 2002 06:56:11 -0000	1.3
  @@ -11,10 +11,13 @@
   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.file.FileListUtil;
  +import org.apache.myrmidon.framework.file.Path;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  -import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   import org.apache.myrmidon.interfaces.deployer.TypeLibraryDeployer;
  +import org.apache.myrmidon.interfaces.library.Library;
  +import org.apache.myrmidon.interfaces.library.LibraryManager;
   
   /**
    * Abstract task to extend to define a type.
  @@ -22,7 +25,7 @@
    * TODO: Make this support classpath sub-element in future
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.2 $ $Date: 2002/04/25 01:41:50 $
  + * @version $Revision: 1.3 $ $Date: 2002/05/03 06:56:11 $
    */
   public abstract class AbstractTypeDef
       extends AbstractContainerTask
  @@ -30,29 +33,22 @@
       private static final Resources REZ =
           ResourceManager.getPackageResources( AbstractTypeDef.class );
   
  -    // TODO - replace lib with class-path
  -    private File m_lib;
  -    private String m_name;
  +    private Path m_classpath = new Path();
       private String m_classname;
   
  -    protected void setName( final String name )
  -    {
  -        m_name = name;
  -    }
  -
       public void setClassname( final String classname )
       {
           m_classname = classname;
       }
   
  -    public void setLib( final File lib )
  +    public void setClasspath( final String path )
       {
  -        m_lib = lib;
  +        m_classpath.add( path );
       }
   
  -    protected final String getName()
  +    public void addClasspath( final Path path )
       {
  -        return m_name;
  +        m_classpath.add( path );
       }
   
       protected final String getClassname()
  @@ -66,7 +62,8 @@
       public void execute()
           throws TaskException
       {
  -        if( null == m_lib )
  +        final File[] classpath = FileListUtil.toFiles( m_classpath, getContext() );
  +        if( classpath.length == 0 )
           {
               final String message = REZ.getString( "typedef.no-lib.error" );
               throw new TaskException( message );
  @@ -74,13 +71,14 @@
   
           try
           {
  -            // Locate the deployer, and use it to deploy the type
  +            final LibraryManager libraryManager = (LibraryManager)getService( LibraryManager.class );
  +            final Library library = libraryManager.createLibrary( classpath );
               final Deployer deployer = (Deployer)getService( Deployer.class );
  -            final TypeLibraryDeployer typeDeployer = deployer.createDeployer( m_lib );
  +            final TypeLibraryDeployer typeDeployer = deployer.createDeployer( library );
               final TypeDefinition typeDef = createTypeDefinition();
               typeDeployer.deployType( typeDef );
           }
  -        catch( DeploymentException e )
  +        catch( final Exception e )
           {
               throw new TaskException( e.getMessage(), e );
           }
  
  
  
  1.3       +7 -6      jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/file/FileListUtil.java
  
  Index: FileListUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/file/FileListUtil.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FileListUtil.java	20 Apr 2002 12:53:37 -0000	1.2
  +++ FileListUtil.java	3 May 2002 06:56:12 -0000	1.3
  @@ -13,15 +13,15 @@
   import org.apache.aut.nativelib.PathUtil;
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.TaskException;
  -import org.apache.myrmidon.interfaces.classloader.ClassLoaderException;
  -import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
  +import org.apache.myrmidon.interfaces.library.Library;
  +import org.apache.myrmidon.interfaces.library.LibraryManager;
   
   /**
    * Utility methods for dealing with {@link FileList} objects.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.2 $ $Date: 2002/04/20 12:53:37 $
  + * @version $Revision: 1.3 $ $Date: 2002/05/03 06:56:12 $
    */
   public final class FileListUtil
   {
  @@ -88,12 +88,13 @@
           throws TaskException
       {
           final File[] files = toFiles( classpath, context );
  -        final ClassLoaderManager manager = (ClassLoaderManager)context.getService( ClassLoaderManager.class );
  +        final LibraryManager manager = (LibraryManager)context.getService( LibraryManager.class );
           try
           {
  -            return manager.createClassLoader( files );
  +            final Library library = manager.createLibrary( files );
  +            return library.getClassLoader();
           }
  -        catch( final ClassLoaderException e )
  +        catch( final Exception e )
           {
               throw new TaskException( e.getMessage(), e );
           }
  
  
  
  1.4       +2 -2      jakarta-ant-myrmidon/myrmidon/src/samples/sample.ant
  
  Index: sample.ant
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/myrmidon/src/samples/sample.ant,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- sample.ant	25 Apr 2002 11:33:34 -0000	1.3
  +++ sample.ant	3 May 2002 06:56:12 -0000	1.4
  @@ -55,7 +55,7 @@
           <type-def name="log2"
               role="task"
               classname="org.apache.antlib.core.Log"
  -            lib="../../dist/lib/core.atl" />
  +            classpath="../../dist/lib/core.atl" />
   
           <log2 message="Luke to Echo base. Can you hear me?"/>
       </target>
  @@ -64,7 +64,7 @@
           <converter-def classname="org.apache.myrmidon.libs.core.StringToClassConverter"
               source-type="java.lang.String"
               destination-type="java.lang.Class"
  -            lib="../../dist/lib/core.atl" />
  +            classpath="../../dist/lib/core.atl" />
       </target>
   
       <target name="ant-call-test">
  
  
  

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