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/test/src/test/org/apache/avalon/repository TargetReferenceTest.java ApplicationDirectiveTest.java
Date Tue, 18 Nov 2003 12:59:56 GMT
mcconnell    2003/11/18 04:59:56

  Modified:    repository/main/src/java/org/apache/avalon/repository
                        Bootstrapper.java InitialRepositoryFactory.java
  Added:       repository/api/src/java/org/apache/avalon/repository
                        TargetReference.java
               repository/test/src/test/org/apache/avalon/repository
                        TargetReferenceTest.java
  Removed:     repository/api/src/java/org/apache/avalon/repository
                        ApplicationDirective.java
               repository/test/src/test/org/apache/avalon/repository
                        ApplicationDirectiveTest.java
  Log:
  Move ApplicationDirective to TargetReference.
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/TargetReference.java
  
  Index: TargetReference.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 ;
  
  
  import java.util.Properties ;
  
  
  /**
   * A build descriptor can be generated from a jar that has extra jar build 
   * properties packaged with it.
   * 
   * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
   * @author $Author: mcconnell $
   * @version $Revision: 1.1 $
   */
  public class TargetReference extends ArtifactReference
  {
      //-----------------------------------------------------------
      // static
      //-----------------------------------------------------------
  
     /** 
      * the key used to get the defualt comma delimited 
      * repository urls
      */
      public static final String REPOS_KEY = "avalon.target.repos" ;
  
     /** 
      * the key used to get the aplication artifact group
      */
      public static final String GROUP_KEY = "avalon.target.group" ;
  
     /** 
      * the key used to get the artifact name within the group
      */
      public static final String NAME_KEY = "avalon.target.name" ;
  
     /** 
      * the version of the application artifact
      */
      public static final String VERSION_KEY = "avalon.target.version" ;
  
      //-----------------------------------------------------------
      // static
      //-----------------------------------------------------------
  
      /**
       * Creates a new TargetReference using a supplied base and 
       * filename. 
       * 
       * @param base the base directory path
       * @param filename the artifact filename
       */
      public TargetReference( String base, String filename ) 
      {
           super( base, filename, null );
      }
  
      /**
       * Creates a new TargetReference using a supplied base and 
       * filename. 
       * 
       * @param base the base directory path
       * @param filename the artifact filename
       * @param props suplimentary properties
       */
      public TargetReference( String base, String filename, Properties props ) 
      {
           super( base, filename, props );
      }
  
     /**
      * Return the artifact that the target reference refers to.
      * 
      * @param repositories the set of remote repositories from which
      *    the target reference can be resolved in order to establish
      *    the implementation artifact identity
      * @return the implementaiton artifact
      */
      public Artifact getArtifact( String[] repositories ) throws RepositoryException
      {
          if( repositories == null ) throw new NullPointerException( "repositories" );
  
          Properties properties = RepositoryUtils.getProperties( repositories, this );
          final String group = properties.getProperty( GROUP_KEY );
          final String name = properties.getProperty( NAME_KEY  );
          final String version = properties.getProperty( VERSION_KEY );
          return MavenArtifactFactory.createJarArtifact( group, name, version );
      }
  }
  
  
  
  1.3       +13 -2     avalon-sandbox/repository/main/src/java/org/apache/avalon/repository/Bootstrapper.java
  
  Index: Bootstrapper.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/main/src/java/org/apache/avalon/repository/Bootstrapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Bootstrapper.java	18 Nov 2003 07:38:03 -0000	1.2
  +++ Bootstrapper.java	18 Nov 2003 12:59:56 -0000	1.3
  @@ -68,6 +68,17 @@
    */
   public class Bootstrapper
   {
  +    //-----------------------------------------------------------
  +    // static
  +    //-----------------------------------------------------------
  +
  +    private static final String[] DEFAULT_REPOSITORIES = 
  +      new String[]{ "http://dpml.net/","http:ibiblio.org/maven" };
  +
  +    //-----------------------------------------------------------
  +    // state
  +    //-----------------------------------------------------------
  +
       /** The repository used by this bootstrapper */
       private final Repository m_repository ;
       /** The Jar artifact descriptor containing the target classes */
  @@ -451,7 +462,7 @@
           String l_jarSpec = System.getProperty( "repository.application.jar" ) ;
           String l_fqcn = System.getProperty( "repository.application.class" ) ;
   
  -        String[] l_repositories = new String[]{ System.getProperty( "repository.bootstrap.url"
) } ;
  +        String[] l_repositories = DEFAULT_REPOSITORIES; // need to handle this via args
           
           if ( null == l_jarSpec )
           {
  
  
  
  1.5       +27 -36    avalon-sandbox/repository/main/src/java/org/apache/avalon/repository/InitialRepositoryFactory.java
  
  Index: InitialRepositoryFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/repository/main/src/java/org/apache/avalon/repository/InitialRepositoryFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- InitialRepositoryFactory.java	18 Nov 2003 07:39:35 -0000	1.4
  +++ InitialRepositoryFactory.java	18 Nov 2003 12:59:56 -0000	1.5
  @@ -77,7 +77,7 @@
    * methods using the newly configured ClassLoader.
    * 
    * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
  - * @author $Author$
  + * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
    * @version $Revision$
    */
   public class InitialRepositoryFactory implements RepositoryFactory
  @@ -86,12 +86,12 @@
           "avalon.artifact.dependency";
   
       public static final String REPOSITORY_GROUP_NAME = 
  -        "avalon-repository" ;
  +        "avalon-repository";
       public static final String REPOSITORY_APPLICATION_NAME = 
  -        "avalon-repository-main" ;
  +        "avalon-repository-main";
   
       public static final String DEFAULT_FACTORY = 
  -        "org.apache.avalon.repository.impl.DefaultRepositoryFactory" ;
  +        "org.apache.avalon.repository.impl.DefaultRepositoryFactory";
   
       public static final Properties PROPERTIES = 
           createDefaultProperties();
  @@ -99,6 +99,10 @@
       public static final ArtifactReference REFERENCE = 
           new ArtifactReference( REPOSITORY_GROUP_NAME, REPOSITORY_APPLICATION_NAME );
   
  +    public static final TargetReference TARGET = 
  +        new TargetReference( REPOSITORY_GROUP_NAME, REPOSITORY_APPLICATION_NAME );
  +
  +
      /**
       * Build the properties that declare the default repository
       * implementation that was assigned at build time.
  @@ -172,7 +176,7 @@
       public InitialRepositoryFactory( String[] repositories ) 
           throws RepositoryException
       {
  -         this( REFERENCE, repositories );
  +         this( TARGET, repositories );
       }
       
       /**
  @@ -183,24 +187,11 @@
        * 
        * @throws RepositoryException
        */
  -    public InitialRepositoryFactory( ArtifactReference reference, String[] repositories
) 
  +    public InitialRepositoryFactory( TargetReference reference, String[] repositories )

           throws RepositoryException
       {
  -         this( new ApplicationDirective( reference, 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
  -     */
  -    public InitialRepositoryFactory( ApplicationDirective app ) 
  -        throws RepositoryException
  -    {
  -         if( app == null ) throw new NullPointerException( "app" );
  +         if( reference == null ) throw new NullPointerException( "reference" );
  +         if( repositories == null ) throw new NullPointerException( "repositories" );
   
           /* 
            * Create the temporary directory to pull down files into
  @@ -217,8 +208,8 @@
            * which is default mechanism dependent.
            */
   
  -        JarDescriptor implementation = app.getJarDescriptor();
  -        m_repositories = app.getDefaultRepositories();
  +        m_repositories = repositories;
  +        Artifact implementation = reference.getArtifact( repositories );
   
           Properties l_props = RepositoryUtils.getProperties( m_repositories, implementation
) ;
           Attributes l_attrs = RepositoryUtils.getAsAttributes( l_props ) ;
  @@ -228,7 +219,7 @@
            * temporary cache to build the repository classloader with.
            */
           ArrayList l_urlList = new ArrayList() ;
  -        JarDescriptor l_dep = null;
  +        Artifact l_dep = null;
           String l_spec = null;
           File l_targetFile = null;
           try
  @@ -241,7 +232,7 @@
               while ( l_list.hasMore() )
               {
                   l_spec = ( String ) l_list.next() ;
  -                l_dep = new JarDescriptor( l_spec ) ;
  +                l_dep = MavenArtifactFactory.createJarArtifact( l_spec ) ;
                   
                   StringBuffer l_target = 
                     new StringBuffer( l_tmpDir.toString() ) ;
  @@ -251,7 +242,7 @@
                       l_target.append( '/' ) ;
                   }
                   
  -                l_target.append( l_dep.getRootRelativePath() ) ;
  +                l_target.append( l_dep.getURL( "" ) ) ;
                   l_targetFile = new File( l_target.toString() ) ;
   
                   cacheArtifact( 
  @@ -267,13 +258,13 @@
                 + implementation + "]."; 
               throw new RepositoryException( error, e ) ;
           }
  -        catch ( ParseException e )
  -        {    
  -            final String error = 
  -              "Unable to parse a dependency specification [" + l_spec 
  -              + "] in the implementation reference: [" + implementation + "]."; 
  -            throw new RepositoryException( error, e ) ;
  -        }
  +        //catch ( ParseException e )
  +        //{    
  +        //    final String error = 
  +        //      "Unable to parse a dependency specification [" + l_spec 
  +        //      + "] in the implementation reference: [" + implementation + "]."; 
  +        //    throw new RepositoryException( error, e ) ;
  +        //}
           catch ( MalformedURLException e )
           {
               final String error = 
  @@ -298,7 +289,7 @@
           {
               StringBuffer target = new StringBuffer( l_tmpDir.toString() ) ;
               if ( '/' != target.charAt( target.length() - 1 ) ) target.append( '/' ) ;
  -            target.append( implementation.getRootRelativePath() ) ;
  +            target.append( implementation.getURL( "" ) ) ;
               File file = new File( target.toString() ) ;
               cacheArtifact( implementation, m_repositories, file, true ) ;
               l_urlList.add( file.toURL() ) ;
  @@ -392,7 +383,7 @@
        *      <code>destinationFile</code> against the remote <code>source</code>
        * @return TRUE if the file was updated else FALSE
        */
  -    public static boolean cacheArtifact( ArtifactDescriptor a_artifact, 
  +    public static boolean cacheArtifact( Artifact a_artifact, 
           String [] a_repos, File a_destFile, boolean a_useTimestamp ) 
           throws RepositoryException
       {
  
  
  
  1.1                  avalon-sandbox/repository/test/src/test/org/apache/avalon/repository/TargetReferenceTest.java
  
  Index: TargetReferenceTest.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;
  
  
  import junit.framework.TestCase;
  
  
  /**
   * @todo
   * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
   * @author $Author: mcconnell $
   * @version $Revision: 1.1 $
   */
  public class TargetReferenceTest extends TestCase
  {
  
      public static void main(String[] args)
      {
          junit.textui.TestRunner.run( TargetReferenceTest.class );
      }
  
      /**
       * Constructor for TargetReferenceTest.
       * @param arg0
       */
      public TargetReferenceTest(String arg0)
      {
          super(arg0);
      }
      
      public void testConstructorOne() throws Exception
      {
          try
          {
              TargetReference ref = new TargetReference( null, null );
              fail( "No null pointer exception (case 1)" );
          }
          catch( Throwable e )
          {
              assertTrue( true );
          }
      }
  
      public void testConstructorTwo() throws Exception
      {
          try
          {
              TargetReference ref = new TargetReference( null, "xxx" );
              fail( "No null pointer exception - (case 2)" );
          }
          catch( Throwable e )
          {
              assertTrue( true );
          }
      }
  
      public void testConstructorThree() throws Exception
      {
          try
          {
              TargetReference ref = new TargetReference( "xxx", null );
              fail( "No null pointer exception - (case 3)" );
          }
          catch( Throwable e )
          {
              assertTrue( true );
          }
      }
  
      public void testArtifactResolution() throws Exception
      {
          //
          // prepare the expected results
          //
  
          final String group = "avalon-repository";
          final String name = "avalon-repository-impl";
          final String version = "1.2-dev";
  
          //
          // target path, filename and repo
          //
  
          final String base = "avalon-repository";
          final String filename = "avalon-repository-main";
          final String[] repos = new String[]{ "http://dpml.net" };
  
          //
          // create the target and get the referenced artifact
          //
  
          TargetReference ref = new TargetReference( base, filename );
          Artifact impl = ref.getArtifact( repos );
  
          //
          // validate the impl reference group, name and version
          // values are not null
          // 
  
          assertNotNull( 
            "group", MavenArtifactFactory.getGroup( impl ) );
          assertNotNull( 
            "name", MavenArtifactFactory.getName( impl ) );
          assertNotNull( 
            "vesion", MavenArtifactFactory.getVersion( impl ) );
  
          //
          // validate the impl reference group, name and version
          // values are correct
          // 
  
          assertTrue( 
            "group", MavenArtifactFactory.getGroup( impl ).equals( base ) );
          assertTrue( 
            "name", MavenArtifactFactory.getName( impl ).equals( name ) );
          assertTrue( 
            "version", MavenArtifactFactory.getVersion( impl ).equals( version ) );
      }
  }
  
  
  

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


Mime
View raw message