mcconnell    2003/12/06 19:15:16

  Modified:    repository/main/src/java/org/apache/avalon/repository/main
                        DefaultBuilder.java DefaultInitialContext.java
  Log:
  Update factory to return a CacheManager instead of a Repository so that consumer 
components can do privaliged things like resource installation.
  
  Revision  Changes    Path
  1.4       +5 -11     
avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultBuilder.java
  
  Index: DefaultBuilder.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultBuilder.java       6 Dec 2003 23:51:08 -0000       1.3
  +++ DefaultBuilder.java       7 Dec 2003 03:15:16 -0000       1.4
  @@ -69,6 +69,7 @@
   import org.apache.avalon.repository.meta.FactoryDescriptor;
   import org.apache.avalon.repository.provider.Builder;
   import org.apache.avalon.repository.provider.InitialContext;
  +import org.apache.avalon.repository.provider.CacheManager;
   import org.apache.avalon.repository.provider.Factory;
   import org.apache.avalon.util.env.Env;
   import org.apache.avalon.util.exception.ExceptionHelper;
  @@ -85,13 +86,6 @@
   public class DefaultBuilder extends AbstractBuilder implements Builder
   {
       //-----------------------------------------------------------
  -    // static
  -    //-----------------------------------------------------------
  -
  -    private static final String[] DEFAULT_HOSTS = 
  -      new String[]{ "http://dpml.net/","http://ibiblio.org/maven"; };
  -
  -    //-----------------------------------------------------------
       // state
       //-----------------------------------------------------------
   
  @@ -152,8 +146,8 @@
           try
           {
               Factory factory = m_context.getInitialFactory();
  -            m_repository = (Repository) factory.create();
  -            System.out.println( "Repository: " + m_repository );
  +            CacheManager manager = (CacheManager)factory.create();
  +            m_repository = manager.createRepository();
           }
           catch( Throwable e )
           {
  @@ -288,7 +282,7 @@
           }
           else
           {
  -            return DEFAULT_HOSTS;
  +            return null;
           }
       }
   
  
  
  
  1.5       +47 -41    
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultInitialContext.java        6 Dec 2003 23:51:08 -0000       1.4
  +++ DefaultInitialContext.java        7 Dec 2003 03:15:16 -0000       1.5
  @@ -103,28 +103,36 @@
   public class DefaultInitialContext extends AbstractBuilder implements InitialContext
   {
       //------------------------------------------------------------------
  -    // static 
  +    // public static 
       //------------------------------------------------------------------
   
  -    public static final String STANDARD_GROUP = 
  -        "avalon-repository";
  +   /**
  +    * The name of the properties file to be searched for confiuration
  +    * properties.  Seaches will be conducted on the current directory and 
  +    * the user's home directory.
  +    */
  +    public static final String AVALON = "avalon.properties";
   
  -    public static final String STANDARD_NAME = 
  -        "avalon-repository-main";
  +    //------------------------------------------------------------------
  +    // static 
  +    //------------------------------------------------------------------
   
  -    private static final String AVALON = "avalon.properties";
  +    private static final String AVALON_IMPLEMENTATION = 
  +       "avalon.implementation";
   
       private static final File USER_HOME = 
         new File( System.getProperty( "user.home" ) );
   
  -    private static final File USER_DIR = getBaseDirectory();
  +    private static final File USER_DIR = 
  +      getBaseDirectory();
   
  -    public static final String CACHE_KEY = "avalon.repository.cache.dir";
  -
  -    public static final String HOSTS_KEY = "avalon.repository.hosts";
  +    private static final String[] DEFAULT_INITIAL_HOSTS = 
  +      new String[]{
  +        "http://dpml.net/";, 
  +        "http://ibiblio.org/maven"; };
   
       //------------------------------------------------------------------
  -    // state 
  +    // immutable state 
       //------------------------------------------------------------------
           
      /** 
  @@ -154,9 +162,20 @@
       public DefaultInitialContext( ) 
           throws RepositoryException
       {
  -         this( null );
  +         this( (File) null );
       }
   
  +    /**
  +     * Creates an initial repository context.
  +     * 
  +     * @param cache the cache directory
  +     * @throws RepositoryException if an error occurs during establishment
  +     */
  +    public DefaultInitialContext( File cache ) 
  +        throws RepositoryException
  +    {
  +         this( cache, null );
  +    }
   
       /**
        * Creates an initial repository context.
  @@ -202,18 +221,6 @@
           m_cache = setupCache( cache, avalonHome, avalonWork );
           m_hosts = setupHosts( hosts, avalonHome, avalonWork );
   
  -        if( true )
  -        {
  -            System.out.println( "Initial-Cache: " + m_cache );
  -            StringBuffer buffer = new StringBuffer( "Initial-Hosts: " );
  -            for( int i=0; i<m_hosts.length; i++ )
  -            {
  -                if( i>0 ) buffer.append( "," );
  -                buffer.append( m_hosts[i] );
  -            }
  -            System.out.println( buffer.toString() );
  -        }
  -
           Artifact implementation = 
             setupImplementation( artifact );
   
  @@ -292,19 +299,6 @@
           }
       }
   
  -    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 );
  -        }
  -    }
  -
       // ------------------------------------------------------------------------
       // InitialContext
       // ------------------------------------------------------------------------
  @@ -341,6 +335,19 @@
       // implementation
       // ------------------------------------------------------------------------
   
  +    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 );
  +        }
  +    }
  +
       private File setupCache( File file, Properties home, Properties work )
       {
           if( null != file ) return file;
  @@ -365,8 +372,7 @@
       */
       private static Properties createDefaultProperties()
       {
  -        final String path = "implementation.properties";
  -
  +        final String path = AVALON_IMPLEMENTATION;
           try
           {
               Properties properties = new Properties();
  @@ -419,7 +425,7 @@
           String homeValue = home.getProperty( HOSTS_KEY );
           String workValue = work.getProperty( HOSTS_KEY, homeValue );
           String value = System.getProperty( CACHE_KEY , workValue );
  -        if( null == value ) return new String[0];
  +        if( null == value ) return DEFAULT_INITIAL_HOSTS;
           return expandHosts( value );
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to