avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject cvs commit: avalon-sandbox/repository/impl/src/test/org/apache/avalon/repository/impl ArtifactDatabaseImplTest.java
Date Tue, 11 Nov 2003 03:15:30 GMT
akarasulu    2003/11/10 19:15:30

  Modified:    repository/impl/src/java/org/apache/avalon/repository/impl
                        DefaultFileRepository.java
                        ArtifactDatabaseImpl.java
               repository/impl/src/test/org/apache/avalon/repository/impl
                        ArtifactDatabaseImplTest.java
  Added:       repository/impl/src/java/org/apache/avalon/repository/impl
                        defaults.properties
  Log:
  Enabled database functionality on Repository
  
  Revision  Changes    Path
  1.3       +46 -103   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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultFileRepository.java	11 Nov 2003 01:22:26 -0000	1.2
  +++ DefaultFileRepository.java	11 Nov 2003 03:15:29 -0000	1.3
  @@ -48,20 +48,19 @@
   
   */
   
  -package org.apache.avalon.repository.impl;
  +package org.apache.avalon.repository.impl ;
    
  -import java.io.File;
  -import java.io.FileOutputStream;
  -import java.io.InputStream;
  -import java.io.IOException;
  -import java.net.URL;
  -import java.net.Authenticator;
  -import java.util.jar.JarFile;
  -import java.util.zip.ZipEntry;
   
  -import org.apache.avalon.repository.ArtifactDescriptor;
  +import java.io.File ;
  +import java.net.URL ;
  +import java.net.Authenticator ;
  +
  +import javax.naming.directory.Attributes ;
  +
   import org.apache.avalon.repository.Repository ;
   import org.apache.avalon.repository.ProxyContext ;
  +import org.apache.avalon.repository.ArtifactDatabase ;
  +import org.apache.avalon.repository.ArtifactDescriptor ;
   import org.apache.avalon.repository.RepositoryException ;
   
   
  @@ -88,6 +87,9 @@
       * Sequence of remote hosts.
       */
       private final URL[] m_hosts;
  +    
  +    /** The database implementation. */
  +    private final ArtifactDatabase m_db ;
   
       //------------------------------------------------------------------
       // constructor 
  @@ -151,8 +153,39 @@
                   Authenticator.setDefault( context.getAuthenticator() );
               }
           }
  +        
  +        m_db = new ArtifactDatabaseImpl( m_hosts ) ;
       } 
   
  +
  +    //------------------------------------------------------------------
  +    // ArtifactDatabase implementation 
  +    //------------------------------------------------------------------
  +    
  +    
  +    /**
  +     * @see org.apache.avalon.repository.ArtifactDatabase#
  +     * getArtifactAttributes(org.apache.avalon.repository.ArtifactDescriptor)
  +     */
  +    public Attributes getArtifactAttributes( ArtifactDescriptor a_descriptor )
  +        throws RepositoryException
  +    {
  +        return m_db.getArtifactAttributes( a_descriptor ) ;
  +    }
  +    
  +    
  +    /**
  +     * @see org.apache.avalon.repository.ArtifactDatabase#
  +     * getDependencies(org.apache.avalon.repository.ArtifactDescriptor)
  +     */
  +    public ArtifactDescriptor [] 
  +        getDependencies( ArtifactDescriptor a_descriptor ) 
  +        throws RepositoryException
  +    {
  +        return m_db.getDependencies( a_descriptor ) ;
  +    }
  +
  +    
       //------------------------------------------------------------------
       // implementation 
       //------------------------------------------------------------------
  @@ -164,10 +197,10 @@
       */
       public String getLocation()
       {
  -        return m_base.toString();
  +        return m_base.toString() ;
       }
   
  -
  +    
       /**
        * Gets an artifact resource from a remote repository.
        * 
  @@ -328,96 +361,6 @@
               final String error = 
                 "Unable to resolve URL for resource: " + resource;
               throw new RepositoryException( error );
  -        }
  -    }
  -
  -    private int verify( final String artifact ) throws RepositoryException
  -    {
  -        int n = artifact.indexOf( SEPERATOR );
  -        if( n < 1 )
  -        {
  -            final String error = 
  -              "Invalid artifact name: " + artifact;
  -            throw new RepositoryException( error );
  -        }
  -        return n;
  -    }
  -
  -    private String getGroupName( String artifact, int index )
  -    {
  -        return artifact.substring( 0, index );
  -    }
  -
  -    private String getResourceName( String artifact, int index )
  -    {
  -        return artifact.substring( index + 1 );
  -    }
  -
  -   /**
  -    * Internal utility to install a entry from a jar file into the local repository.
  -    * @param buffer the buffer to log messages to
  -    * @param root the root directory corresponding to the bar group
  -    * @param jar the block archive
  -    * @param entry the entry from the archive to install
  -    */
  -    private void installEntry( 
  -      StringBuffer buffer, File root, JarFile jar, ZipEntry entry ) throws Exception
  -    {
  -        if( entry.isDirectory() ) return;
  -        
  -        final String name = entry.getName();
  -        File file = new File( root, name );
  -
  -        long timestamp = entry.getTime();
  -        if( file.exists() )
  -        {
  -            if( file.lastModified() == timestamp )
  -            {
  -                buffer.append( "\nEntry: " + name + " (already exists)" );
  -                return;
  -            }
  -            else if( file.lastModified() > timestamp )
  -            {
  -                buffer.append( "\nEntry: " + name + " (local version is more recent)" );
  -                return;
  -            }
  -            else
  -            {
  -                buffer.append( "\nEntry: " + name + " (updating local version)" );
  -            }
  -        }
  -        else
  -        {
  -            buffer.append( "\nEntry: " + name );
  -        }       
  -
  -        InputStream is = jar.getInputStream( entry );
  -        if ( is == null )
  -        {
  -            final String error = 
  -              "Entry returned a null input stream: " + name;
  -            buffer.append( "\n  " + error );
  -            throw new IOException( error );
  -        }
  -
  -        file.getParentFile().mkdirs();
  -        FileOutputStream fos = new FileOutputStream( file );
  -        byte[] buf = new byte[100 * 1024];
  -        int length;
  -        while ( ( length = is.read( buf ) ) >= 0 )
  -        {
  -            fos.write( buf, 0, length );
  -        }
  -        fos.close();
  -        is.close();
  -
  -        if ( timestamp < 0 )
  -        {
  -            file.setLastModified( System.currentTimeMillis() );
  -        }
  -        else
  -        {
  -            file.setLastModified( timestamp );
           }
       }
   }
  
  
  
  1.2       +59 -26    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArtifactDatabaseImpl.java	11 Nov 2003 01:22:26 -0000	1.1
  +++ ArtifactDatabaseImpl.java	11 Nov 2003 03:15:29 -0000	1.2
  @@ -48,15 +48,15 @@
   
   */
   
  -package org.apache.avalon.repository.impl;
  +package org.apache.avalon.repository.impl ;
   
   
  -import java.net.URL ;
  -import java.net.MalformedURLException ;
  -
   import java.util.HashMap ;
  -import java.io.IOException ; 
  +import java.net.URL;
  +import java.text.ParseException ;
   
  +import javax.naming.NamingException ;
  +import javax.naming.directory.Attribute ;
   import javax.naming.directory.Attributes ;
   
   import org.apache.avalon.repository.RepositoryUtils ;
  @@ -82,50 +82,83 @@
    */
   public class ArtifactDatabaseImpl implements ArtifactDatabase
   {
  -    /** the base url of the remote repository */
  -    private final String m_remoteRepoBase ;
  +    /** the base urls of remote repositories */
  +    private final String [] m_remoteRepoBase ;
       /** not used but we can cache properties rather than dl everytime */
       private final HashMap m_artifactAttributeCache = new HashMap() ;
       
       
       /**
  -     * Creates an artifact database for a remote repository.
  +     * Creates an artifact database for a set of replicated remote repositories.
        * 
  -     * @param a_remoteRepoBase the base url of the remote repository
  +     * @param a_remoteRepoBase the base urls of the replicas
        */
  -    public ArtifactDatabaseImpl( String a_remoteRepoBase )
  +    public ArtifactDatabaseImpl( String [] a_remoteRepoBase )
       {
           m_remoteRepoBase = a_remoteRepoBase ;
       }
       
       
       /**
  +     * Creates an artifact database for a set of replicated remote repositories.
  +     * 
  +     * @param a_remoteRepoBase the base urls of the replicas
  +     */
  +    public ArtifactDatabaseImpl( URL [] a_remoteRepoBase )
  +    {
  +        m_remoteRepoBase = new String[ a_remoteRepoBase.length ] ;
  +        
  +        for ( int ii = 0; ii < a_remoteRepoBase.length; ii++ )
  +        {
  +            m_remoteRepoBase[ii] = a_remoteRepoBase[ii].toExternalForm() ; 
  +        }
  +    }
  +    
  +    
  +    /**
        * @see org.apache.avalon.repository.ArtifactDatabase#
        * getArtifactAttributes(org.apache.avalon.repository.ArtifactDescriptor)
        */
       public Attributes getArtifactAttributes( ArtifactDescriptor a_descriptor )
           throws RepositoryException
       {
  -        URL l_url = null ;
  -        Attributes l_attrs = null ;
  +        return RepositoryUtils.getAsAttributes( RepositoryUtils 
  +                    .getProperties( m_remoteRepoBase, a_descriptor ) ) ;
  +    }
  +    
  +
  +    /**
  +     * @see org.apache.avalon.repository.ArtifactDatabase#
  +     * getDependencies(org.apache.avalon.repository.ArtifactDescriptor)
  +     */
  +    public ArtifactDescriptor [] getDependencies( 
  +            ArtifactDescriptor a_descriptor ) throws RepositoryException 
  +    {
  +        String l_spec = null ;
  +        ArtifactDescriptor [] l_dependencies = null ;
  +        Attributes l_attributes = getArtifactAttributes( a_descriptor ) ;
           
  -        try 
  +        try
           {
  -            l_url = new URL( a_descriptor.getUrl( m_remoteRepoBase ) ) ;
  -            l_attrs = RepositoryUtils.getAsAttributes( RepositoryUtils 
  -                    .getProperties( l_url ) ) ;
  -        } 
  -        catch ( MalformedURLException e )
  +            Attribute l_attr = l_attributes.get( DEPENDENCY ) ;
  +            l_dependencies = new ArtifactDescriptor[ l_attr.size() ] ;
  +            for ( int ii = 0; ii < l_dependencies.length; ii++ )
  +            {
  +                l_spec = ( String ) l_attr.get( ii ) ;
  +                l_dependencies[ii] = new ArtifactDescriptor( l_spec ) ;
  +            }
  +        }
  +        catch ( ParseException e )
           {
  -            throw new RepositoryException( "Bad URL for artifact: " 
  -                + a_descriptor.getSpecification(), e ) ;
  +            throw new RepositoryException( 
  +                    "Failed to parse artifact specification: " + l_spec, e ) ; 
           }
  -        catch ( IOException e )
  +        catch ( NamingException e )
           {
  -            throw new RepositoryException( "Failed to access properties file: " 
  -                + l_url.toString(), e ) ;
  +            throw new RepositoryException( "Failed to get " + DEPENDENCY 
  +                    + " attribute values for " + a_descriptor, e ) ;
           }
  -
  -        return l_attrs ;
  +        
  +        return l_dependencies ;
       }
   }
  
  
  
  1.1                  avalon-sandbox/repository/impl/src/java/org/apache/avalon/repository/impl/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  #
  # Not used at the moment but can be used for defaults discovery 
  #
  
  cache.dir=.merlin
  remote.repository.url.0=http://dpml.net
  remote.repository.url.1=http://ibiblio.org/maven
  
  
  
  1.2       +2 -1      avalon-sandbox/repository/impl/src/test/org/apache/avalon/repository/impl/ArtifactDatabaseImplTest.java
  
  Index: ArtifactDatabaseImplTest.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/impl/src/test/org/apache/avalon/repository/impl/ArtifactDatabaseImplTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArtifactDatabaseImplTest.java	11 Nov 2003 01:22:27 -0000	1.1
  +++ ArtifactDatabaseImplTest.java	11 Nov 2003 03:15:30 -0000	1.2
  @@ -79,7 +79,8 @@
       protected void setUp() throws Exception
       {
           super.setUp();
  -        m_adb = new ArtifactDatabaseImpl( "http://ibiblio.org/maven" ) ;
  +        m_adb = new ArtifactDatabaseImpl( new 
  +                String [] { "http://ibiblio.org/maven" } ) ;
       }
   
       /*
  
  
  

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


Mime
View raw message