mcconnell    2003/11/26 09:05:47

  Modified:    repository/main project.xml
               repository/main/src/java/org/apache/avalon/repository/main
                        InitialRepositoryFactory.java
               repository/spi/src/java/org/apache/avalon/repository/criteria
                        Criteria.java
               repository/test/src/test/org/apache/avalon/repository/main
                        InitialRepositoryFactoryTest.java
  Log:
  Add Env dependency so that we can resolve AVALON_HOME as the default cache directory.
  
  Revision  Changes    Path
  1.3       +10 -0     avalon-sandbox/repository/main/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/main/project.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project.xml       20 Nov 2003 04:19:07 -0000      1.2
  +++ project.xml       26 Nov 2003 17:05:47 -0000      1.3
  @@ -35,6 +35,16 @@
         <artifactId>avalon-repository-impl</artifactId>
         <version>1.2-dev</version>
       </dependency>
  +    <dependency>
  +      <groupId>avalon-util</groupId>
  +      <artifactId>avalon-util-env</artifactId>
  +      <version>1.0-dev</version>
  +    </dependency>
  +    <dependency>
  +      <groupId>avalon-util</groupId>
  +      <artifactId>avalon-util-exception</artifactId>
  +      <version>1.0-dev</version>
  +    </dependency>
     </dependencies>
   
   </project>
  
  
  
  1.7       +62 -17    
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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- InitialRepositoryFactory.java     26 Nov 2003 14:11:40 -0000      1.6
  +++ InitialRepositoryFactory.java     26 Nov 2003 17:05:47 -0000      1.7
  @@ -82,6 +82,11 @@
   import org.apache.avalon.repository.meta.ApplicationDescriptor;
   import org.apache.avalon.repository.meta.RelationalDescriptor;
   
  +import org.apache.avalon.util.env.Env;
  +import org.apache.avalon.util.env.EnvAccessException;
  +import org.apache.avalon.util.exception.ExceptionHelper;
  +
  +
   /**
    * Sets up the environment to create repositories by downloading the required 
    * jars, preparing a ClassLoader and delegating calls to repository factory 
  @@ -109,6 +114,7 @@
       public static final Artifact STANDARD_REF =
           Artifact.createArtifact( STANDARD_GROUP, STANDARD_NAME );
   
  +    private static final File CACHE = setupDefaultCache();
   
       //------------------------------------------------------------------
       // state 
  @@ -137,20 +143,41 @@
       {
            this( STANDARD_REF, repositories );
       }
  -    
  +
       /**
        * Creates a repository which in turn instantiates a Repository 
        * factory implementation specified by an artifact descriptor and the 
        * implementation factory's class name.  This factory delegates 
        * calls to the implementation factory once it is created.
  -     * 
  -     * @throws RepositoryException
  +     *
  +     * @param reference an artifact that references a file with an associated
  +     *     meta target descriptor
  +     * @param repositories a set of initial remote repository addresses  
  +     * @throws RepositoryException if an error occurs during establishment
        */
       public InitialRepositoryFactory( Artifact reference, String[] repositories ) 
           throws RepositoryException
       {
  +        this( reference, repositories, CACHE );
  +    }
  +    
  +    /**
  +     * Creates a repository which in turn instantiates a Repository 
  +     * factory implementation specified by an artifact descriptor and the 
  +     * implementation factory's class name.  This factory delegates 
  +     * calls to the implementation factory once it is created.
  +     *
  +     * @param reference an artifact that references a file with an associated
  +     *     meta target descriptor
  +     * @param repositories a set of initial remote repository addresses  
  +     * @throws RepositoryException if an error occurs during establishment
  +     */
  +    public InitialRepositoryFactory( Artifact reference, String[] repositories, 
File cache ) 
  +        throws RepositoryException
  +    {
           if( reference == null ) throw new NullPointerException( "reference" );
           if( repositories == null ) throw new NullPointerException( "repositories" );
  +        if( cache == null ) throw new NullPointerException( "cache" );
   
           m_repositories = repositories;
   
  @@ -158,7 +185,6 @@
           // Create the temporary directory to pull down files into
           //
   
  -        File cache = setupDefaultCache();
           if ( ! cache.exists() )
           {
               cache.mkdirs();
  @@ -221,19 +247,23 @@
           }
           catch( IllegalAccessException e )
           {
  -            throw new RepositoryException( "Could not default constructor on: " 
  -                + factory , e );
  +            final String error = 
  +              "Could locate the default factory constructor class: " 
  +              + factory;
  +            throw new RepositoryException( error, e );
           }
           catch( InstantiationException e )
           {
  -            throw new RepositoryException( 
  -                "Could not instantiate the factory class: " + factory, e );
  +            final String error = 
  +              "Could not instantiate the factory class: " + factory;
  +            throw new RepositoryException( error, e );
           }
           catch( ClassNotFoundException e )
           {
               printClassLoader( classloader );
  -            throw new RepositoryException( "Could not find the factory class: " 
  -                + factory, e );
  +            final String error = 
  +              "Could not find the factory class: " + factory;
  +            throw new RepositoryException( error, e );
           }
           catch( Throwable e )
           {
  @@ -243,12 +273,6 @@
           }
       }
   
  -    private static File setupDefaultCache()
  -    {
  -        final File home = new File( System.getProperty( "user.home" ) );
  -        return new File( home, ".avalon" ); 
  -    }
  -
       // ------------------------------------------------------------------------
       // Factory
       // ------------------------------------------------------------------------
  @@ -369,4 +393,25 @@
             group, name, version );
       }
   
  +    private static File setupDefaultCache()
  +    {
  +        try
  +        {
  +            String env = Env.getEnvVariable( "AVALON_HOME" );
  +            String home = System.getProperty( "avalon.home", env );
  +            if( null != home ) return new File( home );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Internal error while attempting to access environment.";
  +            final String message = 
  +              ExceptionHelper.packException( error, e, true );
  +            System.err.println( message );
  +            return null;
  +        }
  +
  +        final File home = new File( System.getProperty( "user.home" ) );
  +        return new File( home, ".avalon" ); 
  +    }    
   }
  
  
  
  1.5       +1 -26     
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/criteria/Criteria.java
  
  Index: Criteria.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/criteria/Criteria.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Criteria.java     26 Nov 2003 14:11:40 -0000      1.4
  +++ Criteria.java     26 Nov 2003 17:05:47 -0000      1.5
  @@ -96,31 +96,6 @@
           m_params = params;
       }
   
  -   /**
  -    * Creation of a new criteria instance.
  -    * @param params the set of parameters managed by the criteria
  -    * @param params an initial set of values
  -    */
  -    //public Criteria( Parameter[] params, Map values )
  -    //{
  -    //    if( null == params ) 
  -    //      throw new NullPointerException( "params" );
  -
  -    //    m_params = params;
  -    //    for( int i=0; i<params.length; i++ )
  -    //    {
  -    //        Parameter p = params[i];
  -    //        String key = p.getKey();
  -    //        if( null != values )
  -    //        {
  -    //            if( values.containsKey( key ) )
  -    //            {
  -    //                super.put( key, values.get( key ) );
  -    //           }
  -    //        }
  -    //    }
  -    //}
  -
       //--------------------------------------------------------------
       // Criteria
       //--------------------------------------------------------------
  
  
  
  1.5       +45 -3     
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- InitialRepositoryFactoryTest.java 26 Nov 2003 14:11:40 -0000      1.4
  +++ InitialRepositoryFactoryTest.java 26 Nov 2003 17:05:47 -0000      1.5
  @@ -63,6 +63,8 @@
   import org.apache.avalon.repository.criteria.Criteria ;
   import org.apache.avalon.repository.criteria.Factory ;
   
  +import org.apache.avalon.util.env.Env;
  +import org.apache.avalon.util.exception.ExceptionHelper;
   
   /**
    * 
  @@ -91,6 +93,7 @@
       public void testRepositoryBootstrap() throws Exception
       {
           String[] bootstrap = getBootstrapRepositorySet();
  +
           Factory factory = new InitialRepositoryFactory( bootstrap );
           assertNotNull( factory );
   
  @@ -108,14 +111,53 @@
       private static String[] getBootstrapRepositorySet()
       {
           return new String[]{ 
  -          "file:///" + System.getProperty( "basedir" ) + "/target/repository",
  +          getMavenRepositoryURI()
           };
       }
   
  +    private static String getMavenRepositoryURI()
  +    {
  +        String home = getMavenHome();
  +        return "file:///" + getMavenHomeRepository();
  +    }
  +
  +    private static String getMavenHomeRepository()
  +    {
  +        return getMavenHome() + File.separator + "repository";
  +    }
  +
  +    private static String getMavenHome()
  +    {
  +        try
  +        {
  +            String local = 
  +              System.getProperty( 
  +                "maven.home.local", 
  +                Env.getEnvVariable( "MAVEN_HOME_LOCAL" ) );
  +            if( null != local ) return local;
  +
  +            String maven = 
  +              System.getProperty( 
  +                "maven.home", 
  +                Env.getEnvVariable( "MAVEN_HOME" ) );
  +            if( null != maven ) return maven;
  +
  +            return System.getProperty( "user.home" ) + File.separator + ".maven";
  +
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Internal error while attempting to access environment.";
  +            final String message = 
  +              ExceptionHelper.packException( error, e, true );
  +            throw new RuntimeException( message );
  +        }
  +    }
  +
       private static String[] getWorkingRepositorySet()
       {
           return new String[]{ 
  -          "file:///" + System.getProperty( "basedir" ) + "/target/repository",
             "http://dpml.net/";,
             "http://www.ibiblio.org/maven/";
           };
  
  
  

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

Reply via email to