avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/repository/util/src/java/org/apache/avalon/repository/util RepositoryUtils.java
Date Fri, 05 Dec 2003 03:03:31 GMT
mcconnell    2003/12/04 19:03:31

  Modified:    repository/main/src/java/org/apache/avalon/repository/main
                        DefaultInitialContext.java
               repository/util/src/java/org/apache/avalon/repository/util
                        RepositoryUtils.java
  Log:
  Update the repository utilities to support cache based resolution of attributes and update
the DefaultInitialContext to check the cache first before attempting to resolve meta data
remotely.
  
  Revision  Changes    Path
  1.2       +16 -3     avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultInitialContext.java
  
  Index: DefaultInitialContext.java
  ===================================================================
  RCS file: /home/cvs/avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultInitialContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultInitialContext.java	4 Dec 2003 19:34:42 -0000	1.1
  +++ DefaultInitialContext.java	5 Dec 2003 03:03:31 -0000	1.2
  @@ -192,8 +192,8 @@
           // which is default mechanism dependent.
           //
   
  -        Attributes attributes = 
  -          RepositoryUtils.getAttributes( m_hosts, implementation );
  +        Attributes attributes = loadAttributes( m_cache, m_hosts, implementation );
  +        
           FactoryDescriptor descriptor = new FactoryDescriptor( attributes );
           String factory = descriptor.getFactory();
           if( null == factory ) 
  @@ -254,6 +254,19 @@
                 + clazz.getProtectionDomain().getCodeSource().getLocation() );
               buffer.append( "\n cache: " + m_cache );
               throw new RepositoryException( buffer.toString(), e );
  +        }
  +    }
  +
  +    private Attributes loadAttributes( File cache, String[] hosts, Artifact artifact )
  +      throws RepositoryException
  +    {
  +        try
  +        {
  +             return RepositoryUtils.getAttributes( cache, artifact );
  +        }
  +        catch( RepositoryException re )
  +        {
  +             return RepositoryUtils.getAttributes( hosts, artifact );
           }
       }
   
  
  
  
  1.2       +56 -1     avalon/repository/util/src/java/org/apache/avalon/repository/util/RepositoryUtils.java
  
  Index: RepositoryUtils.java
  ===================================================================
  RCS file: /home/cvs/avalon/repository/util/src/java/org/apache/avalon/repository/util/RepositoryUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RepositoryUtils.java	4 Dec 2003 19:35:00 -0000	1.1
  +++ RepositoryUtils.java	5 Dec 2003 03:03:31 -0000	1.2
  @@ -55,6 +55,9 @@
   
   import java.io.IOException ;
   import java.io.InputStream ;
  +import java.io.File;
  +import java.io.FileInputStream ;
  +import java.io.FileNotFoundException ;
   
   import java.util.ArrayList;
   import java.util.Properties ;
  @@ -140,6 +143,58 @@
           return getAsAttributes( getProperties( repositories, artifact ) ) ;
       }
       
  +    /**
  +     * Gets the Attribues from the cache.
  +     * 
  +     * @param cache the reprository cache
  +     * @param artifact the artifact to load meta data from
  +     * @return the meta data as attributes
  +     * @throws RepositoryException if there is execution failure
  +     */
  +    public static Attributes getAttributes( 
  +      File cache, Artifact artifact ) 
  +      throws RepositoryException
  +    {
  +        return getAsAttributes( getProperties( cache, artifact ) ) ;
  +    }
  +
  +    /**
  +     * Gets the Properties in the local cache.
  +     * 
  +     * @param repositories the reprositories to search against
  +     * @param artifact the artifact to load meta data from
  +     * @return the loaded properties 
  +     * @throws RepositoryException if there is any problem loading the 
  +     *    properties
  +     */
  +    public static Properties getProperties( 
  +      File cache, Artifact artifact ) 
  +      throws RepositoryException
  +    {
  +        File local = new File( cache, artifact.getPath() + "." + META );
  +        if( !local.exists() )
  +        {
  +            final String error = "Cannot load metadata due to missing resurce.";
  +            Throwable cause = new FileNotFoundException( local.toString() );
  +            throw new RepositoryException( error, cause );
  +        }
  +
  +        try
  +        {
  +            Properties properties = new Properties();
  +            InputStream input = new FileInputStream( local );
  +            properties.load( input );
  +            return properties;
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Unexpected error while attempting to load properties from local meta: "
  +              + local.toString();
  +            throw new RepositoryException( error, e );
  +        }
  +    }
  +
       /**
        * Gets the Properties in a remote properties file.
        * 
  
  
  

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


Mime
View raw message