avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/repository/util/src/java/org/apache/avalon/repository/util RepositoryUtils.java
Date Mon, 24 Nov 2003 13:33:38 GMT
mcconnell    2003/11/24 05:33:38

  Modified:    repository/impl/src/java/org/apache/avalon/repository/impl
                        ArtifactDatabaseImpl.java DefaultFactory.java
                        DefaultFileRepository.java
               repository/main/src/java/org/apache/avalon/repository/main
                        InitialRepositoryFactory.java
               repository/site/xdocs/about/api navigation.xml
               repository/spi/src/java/org/apache/avalon/repository/meta
                        ArtifactDescriptor.java
               repository/test/src/test/org/apache/avalon/repository/main
                        InitialRepositoryFactoryTest.java
               repository/util/src/java/org/apache/avalon/repository/util
                        RepositoryUtils.java
  Added:       repository/spi/src/java/org/apache/avalon/repository/meta
                        RelationalDescriptor.java
  Removed:     repository/test/src/test/org/apache/avalon/repository/main
                        LoaderTest.java
  Log:
  More housekeeping and some some improvements re. NPE protection.
  
  Revision  Changes    Path
  1.9       +3 -1      avalon-sandbox/repository/impl/src/java/org/apache/avalon/repository/impl/ArtifactDatabaseImpl.java
  
  Index: ArtifactDatabaseImpl.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/impl/src/java/org/apache/avalon/repository/impl/ArtifactDatabaseImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ArtifactDatabaseImpl.java	24 Nov 2003 05:19:53 -0000	1.8
  +++ ArtifactDatabaseImpl.java	24 Nov 2003 13:33:37 -0000	1.9
  @@ -161,6 +161,8 @@
           String spec = null ;
           Artifact[] dependencies = null ;
           Attributes attributes = getArtifactAttributes( artifact ) ;
  +        //RelationalDescriptor links = new RelationalDescriptor( attributes );
  +        //return links.getDependencies();
           
           try
           {
  
  
  
  1.9       +5 -33     avalon-sandbox/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultFactory.java
  
  Index: DefaultFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultFactory.java	24 Nov 2003 09:43:31 -0000	1.8
  +++ DefaultFactory.java	24 Nov 2003 13:33:37 -0000	1.9
  @@ -74,6 +74,7 @@
   import org.apache.avalon.repository.criteria.Factory ;
   import org.apache.avalon.repository.criteria.Criteria ;
   import org.apache.avalon.repository.criteria.Parameter ;
  +import org.apache.avalon.repository.util.RepositoryUtils ;
   
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  @@ -143,7 +144,8 @@
       */
       public Object create( Map map )
       {
  -        System.out.println( "CRITERIA: " + map );
  +        if( null == map ) 
  +          throw new NullPointerException( "map" );
   
           final String proxyHostName = 
             (String) map.get( 
  @@ -182,7 +184,7 @@
           String[] hosts = 
             (String[]) map.get( 
               RepositoryCriteria.REPOSITORY_REMOTE_HOSTS.getKey() );
  -        URL[] repositories = convertToURLs( hosts );
  +        URL[] repositories = RepositoryUtils.convertToURLs( hosts );
    
           if ( null == proxy && null == repositories )
           {
  @@ -198,34 +200,4 @@
           }
       }
   
  -    private URL[] convertToURLs( String[] hosts )
  -    {
  -        ArrayList list = new ArrayList();
  -        for( int i=0; i<hosts.length; i++ )
  -        {
  -            URL url = convertToURL( hosts[i] );
  -            if( url != null ) list.add( url );
  -        }
  -        return (URL[]) list.toArray( new URL[0] );
  -    }
  -
  -    //
  -    // TODO: change this so that we lot to a buffer of some kind
  -    //
  -
  -    private URL convertToURL( String host )
  -    {
  -        try
  -        {
  -            return new URL( host );
  -        }
  -        catch( Throwable e )
  -        {
  -            final String error = 
  -             "Unable to convert a supplied host spec to a url: "
  -             + host;
  -            System.err.println( error );
  -            return null;
  -        }
  -    }
   }
  
  
  
  1.16      +46 -104   avalon-sandbox/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultFileRepository.java
  
  Index: DefaultFileRepository.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultFileRepository.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DefaultFileRepository.java	24 Nov 2003 06:06:11 -0000	1.15
  +++ DefaultFileRepository.java	24 Nov 2003 13:33:37 -0000	1.16
  @@ -76,8 +76,8 @@
   import org.apache.avalon.repository.RepositoryRuntimeException;
   import org.apache.avalon.repository.ClassicArtifact;
   import org.apache.avalon.repository.util.LOADER;
  -
  -
  +import org.apache.avalon.repository.meta.RelationalDescriptor;
  +import org.apache.avalon.repository.meta.MetaException;
   
   /**
    * A component that provides access to versioned resources based on 
  @@ -182,12 +182,10 @@
           m_db = new ArtifactDatabaseImpl( m_hosts );
       } 
   
  -
       //------------------------------------------------------------------
       // ArtifactDatabase implementation 
       //------------------------------------------------------------------
       
  -    
       /**
        * @see org.apache.avalon.repository.ArtifactDatabase#
        * getArtifactAttributes(org.apache.avalon.repository.Artifact)
  @@ -246,7 +244,6 @@
           {
               throw new NullPointerException( "artifact" );
           }
  -
           return LOADER.getResource( artifact, m_roots, m_base, true );
       }
           
  @@ -276,7 +273,6 @@
            l_name = a_artifact.substring( n + 1 ); 
            return getArtifact( l_group, l_name, a_version, a_type );
        }
  -    
        
       /**
        * Get a resource relative to the supplied application name, 
  @@ -309,26 +305,49 @@
       }
   
       /**
  -     * @see org.apache.avalon.repository.Repository#
  -     * getClassLoader(org.apache.avalon.repository.Artifact)
  +     * @param parent the parent classloader
  +     * @param artifact the implementation artifact
  +     * @return the classloader
        */
  -    public ClassLoader getClassLoader( ClassLoader parent, Artifact implementation )
  +    public ClassLoader getClassLoader( ClassLoader parent, Artifact artifact )
           throws RepositoryException
       {
  +        if( null == parent ) 
  +          throw new NullPointerException( "parent" );
  +        if( null == artifact ) 
  +          throw new NullPointerException( "artifact" );
  +
  +        Attributes attributes = getArtifactAttributes( artifact );
  +        RelationalDescriptor relational = null;
  +        try
  +        {
  +            relational = new RelationalDescriptor( attributes );
  +        }
  +        catch( MetaException me )
  +        {
  +            final String error = 
  +              "Could not create a relational descriptor from the artifact: " 
  +              + artifact; 
  +            throw new RepositoryException( error, me ); 
  +        }
  +       
           URL[] apis = 
             getURLs( 
  -            getDependencies( 
  -              implementation, "avalon.artifact.dependency.api" ) );
  +            relational.getDependencies( 
  +              RelationalDescriptor.API_KEY ) );
           ClassLoader api = buildClassLoader( apis, parent );
   
           URL[] spis = 
             getURLs( 
  -            getDependencies(     
  -              implementation, "avalon.artifact.dependency.spi" ) );
  +            relational.getDependencies( 
  +              RelationalDescriptor.SPI_KEY ) );
           ClassLoader spi = buildClassLoader( spis, api );
   
           URL[] imps = 
  -          getURLs( implementation, getDependencies( implementation ) );
  +          getURLs( artifact, 
  +            relational.getDependencies( 
  +              RelationalDescriptor.IMP_KEY ) );
  +
           return buildClassLoader( imps, spi );
       }
   
  @@ -339,30 +358,27 @@
           return new URLClassLoader( urls, parent );
       }
   
  -    private URL[] getURLs( Artifact[] dependents ) 
  -      throws RepositoryException
  -    {
  -        ArrayList list = new ArrayList();
  -        getURLs( list, dependents );
  -        return (URL[]) list.toArray( new URL[0] );
  -    }
  -
  -    private URL[] getURLs( Artifact artifact, Artifact[] dependents ) 
  +    private URL[] getURLs( Artifact[] artifacts ) 
         throws RepositoryException
       {
  -        ArrayList list = new ArrayList();
  -        getURLs( list, dependents );
  -        list.add( getResource( artifact ) );
  -        return (URL[]) list.toArray( new URL[0] );
  +        URL[] urls = new URL[ artifacts.length ];
  +        for( int i=0; i<urls.length; i++ )
  +        {
  +            urls[i] = getResource( artifacts[i] );
  +        }
  +        return urls;
       }
   
  -    private void getURLs( ArrayList list, Artifact[] artifacts ) 
  +    private URL[] getURLs( Artifact primary, Artifact[] artifacts ) 
         throws RepositoryException
       {
  +        URL[] urls = new URL[ artifacts.length +1 ];
           for( int i=0; i<artifacts.length; i++ )
           {
  -            list.add( getResource( artifacts[i] ) );
  +            urls[i] = getResource( artifacts[i] );
           }
  +        urls[ artifacts.length ] = getResource( primary );
  +        return urls;
       }
   
       /**
  @@ -381,7 +397,6 @@
                File temp = File.createTempFile( "avalon-", "-bar" );
                temp.delete();
                LOADER.getResource( url.toString(), temp, true );
  -             //HttpController.getFile( url.toString(), temp, true );
                temp.deleteOnExit();
                return expand( temp.toURL(), buffer );
            }
  @@ -512,79 +527,6 @@
            else
            {
                file.setLastModified( timestamp );
  -         }
  -     }
  -     
  -   
  -    /**
  -     * Get a resource relative to the supplied application name, 
  -     * resource name, version and resource type from the local cache.
  -     * 
  -     * @param group the application or group name
  -     * @param name the resource name
  -     * @param version the version identifier
  -     * @param type the resource type
  -     * @return the resource
  -     */
  -     private URL getLocalArtifact( 
  -       final String group, final String name, 
  -       final String version, final String type )
  -       throws RepositoryException
  -     {
  -         File application = new File( m_base, group );
  -         if( !application.exists() )
  -         {
  -             final String error = 
  -               "Unknown group: '" + group
  -               + "' relative to the repository base: '" 
  -               + m_base + "'.";
  -             throw new RepositoryException( error );
  -         }
  -
  -         File types = new File( application, type + "s" );
  -         if( !types.exists() )
  -         {
  -             final String error = 
  -               "No resources of the type: '" + type 
  -               + "' in the group: '" + group 
  -               + "'. File: '" + types + "'.";
  -             throw new RepositoryException( error );
  -         }
  -
  -         //
  -         // we only append the version identifier if the version
  -         // value is not null and more than 0 characters
  -         //
  -
  -         String resourceName = name;
  -         if( ( version != null ) && ( version.length() != 0 ) ) 
  -         {
  -             resourceName = resourceName + "-" + version;
  -         }
  -         File resource = 
  -           new File( types, resourceName + "." + type );
  -
  -         if( !resource.exists() )
  -         {
  -             final String error = 
  -               "No resources of the type: '" + type 
  -               + "' in the group: '" + group 
  -               + "' with the name: '" + name 
  -               + "' and version: '" + version 
  -               + ". File: '" + resource + "'.";
  -             throw new RepositoryException( error );
  -         }
  -
  -         try
  -         {
  -             return resource.toURL();
  -         }
  -         catch( Throwable e )
  -         {
  -             final String error = 
  -               "Unable to resolve URL for resource: " 
  -               + resource;
  -             throw new RepositoryException( error );
            }
        }
   }
  
  
  
  1.4       +56 -80    avalon-sandbox/repository/main/src/java/org/apache/avalon/repository/main/InitialRepositoryFactory.java
  
  Index: InitialRepositoryFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/main/src/java/org/apache/avalon/repository/main/InitialRepositoryFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InitialRepositoryFactory.java	24 Nov 2003 09:43:31 -0000	1.3
  +++ InitialRepositoryFactory.java	24 Nov 2003 13:33:37 -0000	1.4
  @@ -48,38 +48,39 @@
   
   */
   
  -package org.apache.avalon.repository.main ;
  +package org.apache.avalon.repository.main;
   
   
  -import java.io.File ;
  -import java.io.IOException ;
  -import java.io.InputStream ;
  -import java.io.FileOutputStream ;
  -
  -import java.util.ArrayList ;
  -import java.util.Map ;
  -import java.util.Properties ;
  -import java.text.ParseException ;
  -
  -import java.net.URL ;
  -import java.net.URLConnection ;
  -import java.net.URLClassLoader ;
  -import java.net.HttpURLConnection ;
  -import java.net.MalformedURLException ;
  -
  -import javax.naming.NamingException ;
  -import javax.naming.NamingEnumeration ;
  -import javax.naming.directory.Attributes ;
  +import java.io.File;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.io.FileOutputStream;
  +
  +import java.util.ArrayList;
  +import java.util.Map;
  +import java.util.Properties;
  +import java.text.ParseException;
  +
  +import java.net.URL;
  +import java.net.URLConnection;
  +import java.net.URLClassLoader;
  +import java.net.HttpURLConnection;
  +import java.net.MalformedURLException;
  +
  +import javax.naming.NamingException;
  +import javax.naming.NamingEnumeration;
  +import javax.naming.directory.Attributes;
   
   import org.apache.avalon.repository.Artifact;
   import org.apache.avalon.repository.Repository;
   import org.apache.avalon.repository.RepositoryException;
   import org.apache.avalon.repository.util.LOADER;
  -import org.apache.avalon.repository.ClassicArtifact ;
  -import org.apache.avalon.repository.util.RepositoryUtils ;
  -import org.apache.avalon.repository.criteria.Factory ;
  -import org.apache.avalon.repository.criteria.Criteria ;
  -import org.apache.avalon.repository.meta.ApplicationDescriptor ;
  +import org.apache.avalon.repository.ClassicArtifact;
  +import org.apache.avalon.repository.util.RepositoryUtils;
  +import org.apache.avalon.repository.criteria.Factory;
  +import org.apache.avalon.repository.criteria.Criteria;
  +import org.apache.avalon.repository.meta.ApplicationDescriptor;
  +import org.apache.avalon.repository.meta.RelationalDescriptor;
   
   /**
    * Sets up the environment to create repositories by downloading the required 
  @@ -134,10 +135,6 @@
       public InitialRepositoryFactory( String[] repositories ) 
           throws RepositoryException
       {
  -         //this( 
  -         //  getDefaultImplementation( repositories ), 
  -         //  repositories );
  -
            this( STANDARD_REF, repositories );
       }
       
  @@ -164,7 +161,7 @@
           File cache = setupDefaultCache();
           if ( ! cache.exists() )
           {
  -            cache.mkdirs() ;
  +            cache.mkdirs();
           }
   
           //
  @@ -185,54 +182,33 @@
           //
   
           Attributes attributes = 
  -          RepositoryUtils.getAttributes( repositories, implementation ) ;
  +          RepositoryUtils.getAttributes( repositories, implementation );
  +        RelationalDescriptor links = new RelationalDescriptor( attributes );
   
  -        ArrayList list = new ArrayList() ;
  -        Artifact dependency = null;
  -        String spec = null;
  -        File file = null;
  -        try
  -        {
  -            NamingEnumeration l_list = 
  -              attributes.get( AVALON_ARTIFACT_DEPENDENCY ).getAll() ;
  -            while ( l_list.hasMore() )
  -            {
  -                spec = ( String ) l_list.next() ;
  -                dependency = ClassicArtifact.createJarArtifact( spec ) ;
  -                list.add( LOADER.getResource( 
  -                  dependency, m_repositories, cache, true ) ) ;
  -            }
  +        //
  +        // Grab all of the dependents in one hit because this is 
  +        // the implementation so we can ignore api/spi spread.
  +        //
   
  -            //
  -            // add the actual implementation jar file
  -            //
  -
  -            list.add( 
  -              LOADER.getResource( 
  -                implementation, m_repositories, cache, true ) );
  -        }
  -        catch ( NamingException e )
  +        Artifact[] dependencies = links.getDependencies();
  +        URL[] urls = new URL[ dependencies.length + 1];
  +        for( int i=0; i<dependencies.length; i++ )
           {
  -            final String error = 
  -              "Unable to construct attributes for the implementation reference: [" 
  -              + implementation + "]."; 
  -            throw new RepositoryException( error, e ) ;
  -        }
  -        catch ( Throwable e )
  -        {
  -            final String error = 
  -              "Unable to download dependent artifact [" + spec 
  -              + "] for the implementation reference: [" + implementation + "]."; 
  -            throw new RepositoryException( error, e ) ;
  +            urls[i] = LOADER.getResource( 
  +              dependencies[i], m_repositories, cache, true );
           }
   
  +        urls[ dependencies.length ] = LOADER.getResource( 
  +            implementation, m_repositories, cache, true );
  +
           //
  -        // create the classloader to load the implementation stack
  +        // create the classloader
           //
           
  -        ClassLoader classloader = new URLClassLoader( 
  -           (URL[]) list.toArray( new URL [0] ), 
  -           Thread.currentThread().getContextClassLoader() ) ;
  +        ClassLoader classloader = 
  +          new URLClassLoader( 
  +            urls, 
  +            Thread.currentThread().getContextClassLoader() );
   
           //
           // load the actual repository implementation 
  @@ -240,24 +216,24 @@
           
           try
           {
  -            Class l_clazz = classloader.loadClass( factory ) ;
  -            m_delegate = ( Factory ) l_clazz.newInstance() ;
  +            Class l_clazz = classloader.loadClass( factory );
  +            m_delegate = ( Factory ) l_clazz.newInstance();
           }
           catch( IllegalAccessException e )
           {
               throw new RepositoryException( "Could not default constructor on: " 
  -                + factory , e ) ;
  +                + factory , e );
           }
           catch( InstantiationException e )
           {
               throw new RepositoryException( 
  -                "Could not instantiate the factory class: " + factory, e ) ;
  +                "Could not instantiate the factory class: " + factory, e );
           }
           catch( ClassNotFoundException e )
           {
               printClassLoader( classloader );
               throw new RepositoryException( "Could not find the factory class: " 
  -                + factory, e ) ;
  +                + factory, e );
           }
       }
   
  @@ -277,7 +253,7 @@
       */
       public Criteria createDefaultCriteria()
       {
  -        return m_delegate.createDefaultCriteria() ;
  +        return m_delegate.createDefaultCriteria();
       }
   
      /**
  @@ -306,7 +282,7 @@
       */
       public Object create( Map map )
       {
  -        return m_delegate.create( map ) ;
  +        return m_delegate.create( map );
       }
       
       // ------------------------------------------------------------------------
  @@ -358,7 +334,7 @@
                     "Missing resource: [" + path + "]";
                   throw new Error( error );
               }
  -            properties.load( input ) ;
  +            properties.load( input );
               return properties;
           }
           catch ( Throwable e )
  @@ -369,7 +345,7 @@
                 + "impl directive from the path: " 
                 + path;
               RepositoryException re = new RepositoryException( error, e );
  -            re.printStackTrace( System.err ) ;
  +            re.printStackTrace( System.err );
               return null;
           }
       }
  
  
  
  1.2       +1 -1      avalon-sandbox/repository/site/xdocs/about/api/navigation.xml
  
  Index: navigation.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/site/xdocs/about/api/navigation.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- navigation.xml	24 Nov 2003 06:06:12 -0000	1.1
  +++ navigation.xml	24 Nov 2003 13:33:37 -0000	1.2
  @@ -64,7 +64,7 @@
   
       <menu name="About Repository">
         <item name="Overview" href="/about/index.html">
  -        <item name="Programmer API" href="/about/api.html">
  +        <item name="Programmer API" href="/about/api/index.html">
             <item name="Artifact" href="/about/api/artifact.html"/>
             <item name="Classloaders" href="/about/api/classloader.html"/>
             <item name="Repository" href="/about/api/repository.html"/>
  
  
  
  1.3       +2 -2      avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/meta/ArtifactDescriptor.java
  
  Index: ArtifactDescriptor.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/meta/ArtifactDescriptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ArtifactDescriptor.java	24 Nov 2003 09:43:31 -0000	1.2
  +++ ArtifactDescriptor.java	24 Nov 2003 13:33:37 -0000	1.3
  @@ -211,7 +211,7 @@
       */
       public String toString()
       {
  -        return "[meta " + getDomain() 
  +        return "[artifact: " + getDomain() 
             + ":" + getClassifier() 
             + ":" + getVersion() + "]";
       }
  
  
  
  1.1                  avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/meta/RelationalDescriptor.java
  
  Index: RelationalDescriptor.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.repository.meta;
  
  import java.io.Serializable;
  import java.util.NoSuchElementException;
  import javax.naming.directory.Attributes;
  import javax.naming.directory.Attribute;
  import javax.naming.NamingException;
  
  import org.apache.avalon.repository.Artifact;
  import org.apache.avalon.repository.ClassicArtifact;
  import org.apache.avalon.repository.RepositoryRuntimeException;
  
  /**
   * A RelationalDescriptor represents a set of metadata describing the 
   * structural relationships that an artifact has on other 
   * artifacts.
   * 
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $
   */
  public class RelationalDescriptor extends ArtifactDescriptor
  {
      //-----------------------------------------------------------
      // static
      //-----------------------------------------------------------
  
      public static final String API_KEY = 
        "avalon.artifact.dependency.api";
  
      public static final String SPI_KEY = 
        "avalon.artifact.dependency.spi";
  
      public static final String IMP_KEY = 
        "avalon.artifact.dependency";
  
      //-----------------------------------------------------------
      // immutable state
      //-----------------------------------------------------------
  
      private final Artifact[] c_api;
      private final Artifact[] c_spi;
      private final Artifact[] c_imp;
  
      //-----------------------------------------------------------
      // constructor
      //-----------------------------------------------------------
  
      /**
       * Creates a new TargetMeta descriptor.
       * 
       * @param domain the domain value
       * @param classifier the classifier value
       * @param version the meta data version
       */
      public RelationalDescriptor( final Attributes attributes ) 
        throws MetaException
      {
          super( attributes );
          c_api = buildDependents( attributes, API_KEY );
          c_spi = buildDependents( attributes, SPI_KEY );
          c_imp = buildDependents( attributes, IMP_KEY );
      }
  
  
      //-----------------------------------------------------------
      // public
      //-----------------------------------------------------------
  
     /**
      * Return the implementation dependencies
      * @return the artifacts
      */
      public Artifact[] getDependencies( String key )
      {
          if( key == API_KEY )
          {
              return c_api;
          }
          else if( key == SPI_KEY )
          {
              return c_spi;
          }
          else if( key == IMP_KEY )
          {
              return c_imp;
          }
          else
          {
              final String error = 
                "Invalid dependency key: " + key;
              throw new IllegalArgumentException( error ); 
          }
      }
  
      public Artifact[] getDependencies()
      {
          int j = c_api.length + c_spi.length + c_imp.length;
          Artifact[] all = new Artifact[ j ];
          int q = 0;
          for( int i=0; i<c_api.length; i++ )
          {
              all[q] = c_api[i];
              q++;
          }
          for( int i=0; i<c_spi.length; i++ )
          {
              all[q] = c_spi[i];
              q++;
          }
          for( int i=0; i<c_imp.length; i++ )
          {
              all[q] = c_imp[i];
              q++;
          }
          return all;
      }
  
      //-----------------------------------------------------------
      // private
      //-----------------------------------------------------------
  
      private Artifact[] buildDependents( 
        Attributes attributes, String key )
      {
          try
          {
              Attribute attribute = attributes.get( key ) ;
              if( null == attribute ) return new Artifact[0];
  
              Artifact[] dependencies = 
                new Artifact[ attribute.size() ] ;
              for ( int i = 0; i < dependencies.length; i++ )
              {
                  final String spec = (String) attribute.get( i );
                  dependencies[i] = 
                    ClassicArtifact.createJarArtifact( spec ) ;
              }
              return dependencies;
          }
          catch ( NamingException e )
          {
              throw new RepositoryRuntimeException( 
                "Failed to resolve dependencies for [" + key 
                + "] on the attribute set [" + attributes + "].", e ) ;
          }
      }
  }
  
  
  
  1.3       +1 -45     avalon-sandbox/repository/test/src/test/org/apache/avalon/repository/main/InitialRepositoryFactoryTest.java
  
  Index: InitialRepositoryFactoryTest.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/test/src/test/org/apache/avalon/repository/main/InitialRepositoryFactoryTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InitialRepositoryFactoryTest.java	24 Nov 2003 09:11:43 -0000	1.2
  +++ InitialRepositoryFactoryTest.java	24 Nov 2003 13:33:37 -0000	1.3
  @@ -104,50 +104,6 @@
             "avalon-framework", "avalon-framework-api", "4.1.5", "jar" );
       }
   
  -    public void testClassloaderCreation() throws Exception
  -    {
  -        //
  -        // create the initial repo factory and
  -        // get a context object and customize it 
  -        // to suite our usage scenario
  -        //
  -
  -        String[] bootstrap = getBootstrapRepositorySet();
  -        Factory factory = 
  -          new InitialRepositoryFactory( bootstrap );
  -
  -        Criteria criteria = factory.createDefaultCriteria();
  -        String[] repositories = getWorkingRepositorySet();
  -        criteria.setValue( "avalon.repository.remote.url", repositories );
  -        Repository repository = (Repository) factory.create( criteria.getMap() ) ;
  -
  -        //
  -        // create an artifact that contains a bunch of 
  -        // dependencies (about 30 in this example) spread 
  -        // across a classloader chain (api/spi/impl)
  -        //
  -        
  -        Artifact artifact = 
  -          ClassicArtifact.createJarArtifact( 
  -            "merlin", "merlin-kernel-impl", "3.2.1-dev" );
  -
  -        //
  -        // create a classloader based on the artifact
  -        //
  -
  -        ClassLoader loader = 
  -          repository.getClassLoader( artifact );
  -
  -        //
  -        // grab a class from the classloader just to show that 
  -        // everything is working nicely
  -        //
  -
  -        Class clazz = 
  -          loader.loadClass( "org.apache.avalon.merlin.kernel.Kernel" );
  -        assertNotNull( clazz );
  -    }
  -
       private static String[] getBootstrapRepositorySet()
       {
           return new String[]{ 
  
  
  
  1.4       +33 -1     avalon-sandbox/repository/util/src/java/org/apache/avalon/repository/util/RepositoryUtils.java
  
  Index: RepositoryUtils.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/util/src/java/org/apache/avalon/repository/util/RepositoryUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RepositoryUtils.java	24 Nov 2003 05:19:54 -0000	1.3
  +++ RepositoryUtils.java	24 Nov 2003 13:33:38 -0000	1.4
  @@ -333,4 +333,36 @@
           
           return ( String [] ) l_list.toArray( new String[0] ) ; 
       }
  +
  +    public static URL[] convertToURLs( String[] hosts )
  +    {
  +        ArrayList list = new ArrayList();
  +        for( int i=0; i<hosts.length; i++ )
  +        {
  +            URL url = convertToURL( hosts[i] );
  +            if( url != null ) list.add( url );
  +        }
  +        return (URL[]) list.toArray( new URL[0] );
  +    }
  +
  +    //
  +    // TODO: change this so that we lot to a buffer of some kind
  +    //
  +
  +    public static URL convertToURL( String host )
  +    {
  +        try
  +        {
  +            return new URL( host );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +             "Unable to convert a supplied host spec to a url: "
  +             + host;
  +            System.err.println( error );
  +            return null;
  +        }
  +    }
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message