michal      2004/05/16 08:58:10

  Modified:    maven-project/src/main/resources/META-INF/plexus
                        components.xml
               maven-project/src/test/java/org/apache/maven/project
                        AbstractProjectTestCase.java
               maven-project/src/main/java/org/apache/maven/artifact/resolver
                        DefaultArtifactResolver.java
               maven-project/src/main/java/org/apache/maven/artifact/snapshot
                        DefaultSnapshotResolver.java SnapshotResolver.java
                        SnapshotUtils.java
               maven-project/src/test/java/org/apache/maven/artifact/downloader
                        DefaultArtifactDownloaderTest.java
               maven-project/src/main/java/org/apache/maven/artifact/downloader
                        DefaultArtifactDownloader.java
                        ArtifactDownloader.java
  Added:       maven-project/src/test/resources/local-repo/snapshot-test/jars
                        maven-snapshot-e-1.0-SNAPSHOT.jar.snapshot-version
                        maven-snapshot-b-1.0-SNAPSHOT.jar.snapshot-version
                        maven-snapshot-a-1.0-SNAPSHOT.jar.snapshot-version
                        maven-snapshot-b-1.0-SNAPSHOT.jar
                        maven-snapshot-a-1.0-SNAPSHOT.jar
                        maven-snapshot-e-1.0-SNAPSHOT.jar
               maven-project/src/test/resources/remote-repo-1/snapshot-test/jars
                        maven-snapshot-c-1.0-SNAPSHOT.jar
                        maven-snapshot-b-1.0-SNAPSHOT.jar.snapshot-version
                        maven-snapshot-b-1.0-SNAPSHOT.jar
                        maven-snapshot-c-1.0-SNAPSHOT.jar.snapshot-version
                        maven-snapshot-a-1.0-SNAPSHOT.jar.snapshot-version
                        maven-snapshot-a-1.0-SNAPSHOT.jar
               maven-project/src/test/java/org/apache/maven/artifact/snapshot
                        DefaultSnapshotResolverTest.java
               maven-project/src/test/resources/local-repo/snapshot-test/poms
                        maven-test-snapshot-resolving-1.0.pom
  Log:
  Further improvments in Dependecy Resolving Mechanisms
  
  Revision  Changes    Path
  1.1                  
maven-components/maven-project/src/test/resources/local-repo/snapshot-test/jars/maven-snapshot-e-1.0-SNAPSHOT.jar.snapshot-version
  
  Index: maven-snapshot-e-1.0-SNAPSHOT.jar.snapshot-version
  ===================================================================
  20040101.101010
  
  
  1.1                  
maven-components/maven-project/src/test/resources/local-repo/snapshot-test/jars/maven-snapshot-b-1.0-SNAPSHOT.jar.snapshot-version
  
  Index: maven-snapshot-b-1.0-SNAPSHOT.jar.snapshot-version
  ===================================================================
  20040101.101010
  
  
  1.1                  
maven-components/maven-project/src/test/resources/local-repo/snapshot-test/jars/maven-snapshot-a-1.0-SNAPSHOT.jar.snapshot-version
  
  Index: maven-snapshot-a-1.0-SNAPSHOT.jar.snapshot-version
  ===================================================================
  20040101.101010
  
  
  1.1                  
maven-components/maven-project/src/test/resources/local-repo/snapshot-test/jars/maven-snapshot-b-1.0-SNAPSHOT.jar
  
  Index: maven-snapshot-b-1.0-SNAPSHOT.jar
  ===================================================================
  local
  
  
  1.1                  
maven-components/maven-project/src/test/resources/local-repo/snapshot-test/jars/maven-snapshot-a-1.0-SNAPSHOT.jar
  
  Index: maven-snapshot-a-1.0-SNAPSHOT.jar
  ===================================================================
  local
  
  
  1.1                  
maven-components/maven-project/src/test/resources/local-repo/snapshot-test/jars/maven-snapshot-e-1.0-SNAPSHOT.jar
  
  Index: maven-snapshot-e-1.0-SNAPSHOT.jar
  ===================================================================
  local
  
  
  1.1                  
maven-components/maven-project/src/test/resources/remote-repo-1/snapshot-test/jars/maven-snapshot-c-1.0-SNAPSHOT.jar
  
  Index: maven-snapshot-c-1.0-SNAPSHOT.jar
  ===================================================================
  remote
  
  
  1.1                  
maven-components/maven-project/src/test/resources/remote-repo-1/snapshot-test/jars/maven-snapshot-b-1.0-SNAPSHOT.jar.snapshot-version
  
  Index: maven-snapshot-b-1.0-SNAPSHOT.jar.snapshot-version
  ===================================================================
  20030101.101010
  
  
  1.1                  
maven-components/maven-project/src/test/resources/remote-repo-1/snapshot-test/jars/maven-snapshot-b-1.0-SNAPSHOT.jar
  
  Index: maven-snapshot-b-1.0-SNAPSHOT.jar
  ===================================================================
  local
  
  
  1.1                  
maven-components/maven-project/src/test/resources/remote-repo-1/snapshot-test/jars/maven-snapshot-c-1.0-SNAPSHOT.jar.snapshot-version
  
  Index: maven-snapshot-c-1.0-SNAPSHOT.jar.snapshot-version
  ===================================================================
  20040101.101010

  
  
  
  1.1                  
maven-components/maven-project/src/test/resources/remote-repo-1/snapshot-test/jars/maven-snapshot-a-1.0-SNAPSHOT.jar.snapshot-version
  
  Index: maven-snapshot-a-1.0-SNAPSHOT.jar.snapshot-version
  ===================================================================
  20050101.101010
  
  
  1.1                  
maven-components/maven-project/src/test/resources/remote-repo-1/snapshot-test/jars/maven-snapshot-a-1.0-SNAPSHOT.jar
  
  Index: maven-snapshot-a-1.0-SNAPSHOT.jar
  ===================================================================
  remote
  
  
  1.11      +13 -1     
maven-components/maven-project/src/main/resources/META-INF/plexus/components.xml
  
  Index: components.xml
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-project/src/main/resources/META-INF/plexus/components.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- components.xml    11 May 2004 19:21:10 -0000      1.10
  +++ components.xml    16 May 2004 15:58:10 -0000      1.11
  @@ -62,6 +62,18 @@
         <role>org.apache.maven.project.ModelInheritanceAssembler</role>
         
<implementation>org.apache.maven.project.DefaultModelInheritanceAssembler</implementation>
       </component>
  -
  +    <component>
  +      <role>org.apache.maven.artifact.snapshot.SnapshotResolver</role>
  +      
<implementation>org.apache.maven.artifact.snapshot.DefaultSnapshotResolver</implementation>
  +      <requirements>
  +        <requirement>
  +          <role>org.apache.maven.wagon.manager.WagonManager</role>
  +        </requirement>
  +        <requirement>
  +          <role>org.apache.maven.artifact.downloader.ArtifactDownloader</role>
  +        </requirement>
  +      </requirements>
  +    </component>
  +    
     </components>
   </component-set>
  
  
  
  1.5       +66 -1     
maven-components/maven-project/src/test/java/org/apache/maven/project/AbstractProjectTestCase.java
  
  Index: AbstractProjectTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-project/src/test/java/org/apache/maven/project/AbstractProjectTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractProjectTestCase.java      10 May 2004 19:06:30 -0000      1.4
  +++ AbstractProjectTestCase.java      16 May 2004 15:58:10 -0000      1.5
  @@ -1,13 +1,16 @@
   package org.apache.maven.project;
   
  +import java.io.File;
  +
   import org.codehaus.plexus.PlexusTestCase;
  +import org.codehaus.plexus.util.FileUtils;
   
   public class AbstractProjectTestCase
       extends PlexusTestCase
   {
       protected MavenProjectBuilder projectBuilder;
   
  -    private String localRepository =  System.getProperty( "basedir" ) + 
"/src/test/resources/local-repo";
  +    private String localRepository =  System.getProperty( "basedir" ) + 
"/target/test-classes/local-repo";
       
       public AbstractProjectTestCase( String testName )
       {
  @@ -27,6 +30,68 @@
       public String getLocalRepository()
       {
           return localRepository;    
  +    }
  +    
  +    public void initLocalRepository()
  +    {
  +        File tempLocalRepository = new File( basedir, "target/temp-repo-local" );
  +        
  +        // delete 
  +        try
  +        {
  +           FileUtils.deleteDirectory( tempLocalRepository  );
  +        }
  +        catch( Exception e)
  +        {
  +            System.out.println( "Could not delete the remaining from previous 
tests!! Test will continue anyway "); 
  +           
  +        }    
  +        
  +        tempLocalRepository.mkdirs();
  +        
  +        System.out.println( "Created temporary local repository: " + 
tempLocalRepository );
  +                
  +        System.setProperty( "maven.repo.local", tempLocalRepository.getPath()  );
  +           
  +    
  +    }
  +
  +    /**
  +     * @param f
  +     * @return
  +     */
  +    protected MavenProject buildProject( File f )
  +    {
  +        MavenProject project = null;
  +        
  +        try
  +        {
  +            project = projectBuilder.build( f );
  +        }
  +        catch( Exception e)
  +        {
  +            fail( "Could not build the project which was supposed to be used as 
provider of artifacts" );
  +        }
  +    
  +        assertNotNull( "Project is null", project );
  +        
  +        return project;
  +    }
  +
  +    /**
  +     * @param project
  +     */
  +    protected void initRemoteRepositories( MavenProject project )
  +    {
  +        File repo_1 = new File( basedir, "target/test-classes/remote-repo-1" );
  +    
  +        File repo_2 = new File( basedir, "target/test-classes/remote-repo-2" );     
  
  +        
  +        project.addRepository( "file://" + repo_1.getPath() );
  +    
  +        project.addRepository( "file://" + repo_2.getPath() );
  +    
  +        assertEquals( 2, project.getRepositories().size() );
       }
       
       
  
  
  
  1.5       +13 -2     
maven-components/maven-project/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
  
  Index: DefaultArtifactResolver.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultArtifactResolver.java      11 May 2004 19:21:10 -0000      1.4
  +++ DefaultArtifactResolver.java      16 May 2004 15:58:10 -0000      1.5
  @@ -3,6 +3,7 @@
   import org.apache.maven.artifact.MavenArtifact;
   import org.apache.maven.artifact.downloader.ArtifactDownloader;
   import org.apache.maven.artifact.factory.MavenArtifactFactory;
  +import org.apache.maven.artifact.snapshot.SnapshotResolver;
   import org.apache.maven.model.Dependency;
   import org.apache.maven.project.MavenProject;
   
  @@ -24,6 +25,11 @@
       ArtifactDownloader artifactDownloader;
       
       
  +    /**
  +     * @requirement
  +     */
  +    SnapshotResolver snapshotResolver;
  +    
       
       
       public MavenArtifact getArtifact( Dependency dependency, MavenProject project )
  @@ -35,7 +41,12 @@
          
          if ( retValue.isSnapshot() )
          {
  -          // for snapshots artifact we always have to try to check if newer version 
exists  
  +           boolean snapshotResolved = snapshotResolver.resolveSnapshotArtifact( 
retValue, project.getRepositories() );
  +           
  +           if ( !snapshotResolved  )
  +           {
  +               retValue = null;
  +           }
              
          }       
          else if ( !retValue.exists() )
  
  
  
  1.2       +147 -27   
maven-components/maven-project/src/main/java/org/apache/maven/artifact/snapshot/DefaultSnapshotResolver.java
  
  Index: DefaultSnapshotResolver.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/artifact/snapshot/DefaultSnapshotResolver.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultSnapshotResolver.java      11 May 2004 20:13:14 -0000      1.1
  +++ DefaultSnapshotResolver.java      16 May 2004 15:58:10 -0000      1.2
  @@ -6,6 +6,8 @@
   import java.util.List;
   
   import org.apache.maven.artifact.MavenArtifact;
  +import org.apache.maven.artifact.downloader.ArtifactDownloader;
  +import org.apache.maven.artifact.factory.MavenArtifactFactory;
   import org.apache.maven.wagon.Wagon;
   import org.apache.maven.wagon.manager.WagonManager;
   import org.apache.maven.wagon.repository.Repository;
  @@ -19,45 +21,153 @@
   {
   
       private WagonManager wagonManager;
  -
  -    public void resolveSnapshotArtifact( MavenArtifact artifact,
  -            List repositories )
  +    
  +    private ArtifactDownloader artifactDownloader;
  +    
  +    private MavenArtifactFactory artifactFactory;
  +    
  +    
  +    /**
  +     * @todo (michal) I made the assumption (disussed with Jason) that only one
  +     * repository should be ever used for deployment of snapshots. It means
  +     * that we don't have to search for the latest version of given snapshot 
artifact
  +     * in every visible repository. Simply once we find the snapshot artifact in 
  +     * the given remote repository we are sure that
  +     * we are looking at the only place from where snapshot can be downloaded 
  +     * 
  +     */
  +    public boolean resolveSnapshotArtifact( MavenArtifact artifact, List 
repositories )
       {
   
  +        boolean retValue = false;
  +        
           Date localVersion = getLocalVersion( artifact );
  +        
  +        System.out.println( "Local version: " + localVersion );
   
           for ( Iterator iter = repositories.iterator(); iter.hasNext(); )
           {
  +            
  +            
               Repository repository = ( Repository ) iter.next();
   
  -            // need to think how to handle excepion here and what they actually mean
  -            //Date remoteVersion =  getRemoteVersion( artifact, repository );
  +            System.out.println( "Checking in repository: " + repository.getUrl() );
  +            
  +            Wagon wagon = null;
  +            
  +            try
  +            {
  +                wagon = wagonManager.getWagon( repository.getProtocol() );
  +                
  +                wagon.connect( repository );
  +
  +                Date remoteVersion =  getRemoteVersion( artifact, wagon );
  +                
  +                System.out.println( "Remote version: " + remoteVersion );
  +                
  +                if ( remoteVersion != null )
  +                {
  +                    //if  local version is unknown (null) it means that 
  +                    //we don't have this file locally. so we will be happy
  +                    // to have any snapshot.
  +                    // we wil download in two cases: 
  +                    //  a) we don't have any snapot in local repo
  +                    //  b) we have found newer version in remote repository
  +                    if ( localVersion == null || localVersion.before( remoteVersion 
) )
  +                    {
  +                        
  +                        // here we know that we have artifact like 
foo-1.2-SNAPSHOT.jar
  +                        // and the remote timestamp is something like 
20010304.121212                        
  +                        // so we might as well fetch foo-1.2-20010304.121212.jar
  +                        // but we are just going to fetch foo-1.2-SNAPSHOT.jar.
  +                        // We can change the strategy which is used here later on
  +                                                                        
  +                        
  +                        // @todo we will delete old file first. 
  +                        //it is not really a right thing to do. Artifact Dowloader 
should
  +                        // fetch to temprary file and replace the old file with the 
new
  +                        // one once download was finished
  +                        
  +                        artifact.getFile().delete();
  +                        
  +                        artifactDownloader.getRemoteArtifact( artifact , wagon ); 
  +                        
  +                        File snapshotVersionFile = 
artifact.getSnapshotVersionFile();
  +                        
  +                        String timestamp = SnapshotUtils.getTimestamp( 
remoteVersion );
  +                        
  +                        // delete old one 
  +                        if ( snapshotVersionFile.exists() )
  +                        {
  +                             snapshotVersionFile.delete();
  +                        }
  +                        
  +                        FileUtils.fileWrite( snapshotVersionFile.getPath(), 
timestamp  );
  +                    }                                                               
              
  +                }
   
  +            }
  +            catch ( Exception e )
  +            {
  +                continue; 
  +            }
  +            
  +            finally
  +            {
  +                 if ( wagon!= null )
  +                 {
  +                    try
  +                    {
  +                        wagon.disconnect();
  +                        
  +                        wagonManager.releaseWagon( wagon );
  +                        
  +                    }
  +                    
  +                    catch( Exception e)
  +                    {
  +                    }
  +                 }
  +            
  +            }
  +            
           }
  +        
  +        return retValue;
   
       }
   
  -    private Date getRemoteVersion( MavenArtifact artifact, Repository repository )
  +    private Date getRemoteVersion( MavenArtifact artifact, Wagon wagon )
               throws Exception
       {
  -        Date retValue = null;
  -
  -        Wagon wagon = wagonManager.getWagon( repository.getProtocol() );
  -
  -        wagon.connect( repository );
  -
  -        // @todo - here I need to create temp file. 
  -        //I would prefer to have input stream from wagon and do not need to create/
  -        //delete file and handle all error which may appear.
  +        
           File file = null;
  -
  -        wagon.get( artifact.getSnapshotVersionUrlPath(), file );
  -
  -        String snapshotVersion = FileUtils.fileRead( file );
  -
  -        retValue = SnapshotUtils.parseSnapshotVersion( snapshotVersion );
  -
  -        return retValue;
  +        
  +        Date retValue = null;
  +        
  +        try
  +        {
  +            
  +            // @todo - here I need to create temporary file. 
  +            // I would really prefer to have input stream from wagon and do not 
need to 
  +            // create/delete file and handle all error which may appear.
  +            file = File.createTempFile( "maven", "tmp" );
  +
  +            wagon.get( artifact.getSnapshotVersionUrlPath(), file );
  +
  +            String timestamp = FileUtils.fileRead( file );
  +            
  +            retValue = SnapshotUtils.parseTimestamp( timestamp );
  +            
  +            return retValue;
  +        }
  +        finally
  +        {
  +            if ( file != null )
  +            {
  +                file.delete();
  +            }
  +        }
   
       }
   
  @@ -74,9 +184,9 @@
   
               if ( file.exists() )
               {
  -                String snapshotVersion = FileUtils.fileRead( file );
  +                String timestamp = FileUtils.fileRead( file );
   
  -                retValue = SnapshotUtils.parseSnapshotVersion( snapshotVersion );
  +                retValue = SnapshotUtils.parseTimestamp( timestamp );
   
               }
   
  @@ -88,13 +198,23 @@
   
           if ( retValue == null )
           {
  -            //try "traditional method"
  +            //try "traditional method" used in maven1 for obtaining snapshot version
   
               File file = artifact.getFile();
   
               if ( file.exists() )
               {
                   retValue = new Date( file.lastModified() );
  +                
  +                //@todo we should "normalize" the time.
  +                
  +                /*TimeZone gmtTimeZone = TimeZone.getTimeZone( "GMT" );
  +                
  +                TimeZone userTimeZone = TimeZone.getDefault();
  +                
  +                long diff =
  +                */ 
  +                                                
               }
   
           }
  
  
  
  1.2       +14 -2     
maven-components/maven-project/src/main/java/org/apache/maven/artifact/snapshot/SnapshotResolver.java
  
  Index: SnapshotResolver.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/artifact/snapshot/SnapshotResolver.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SnapshotResolver.java     11 May 2004 20:13:14 -0000      1.1
  +++ SnapshotResolver.java     16 May 2004 15:58:10 -0000      1.2
  @@ -13,6 +13,18 @@
       
       String ROLE = SnapshotResolver.class.getName();
           
  -    void resolveSnapshotArtifact( MavenArtifact artifact, List repositories );
  +    /**
  +     * Verifies if in any remote repository there is a newer version of snapshot 
arifact
  +     * and download this verion is case when newer version was found.
  +     * 
  +     * @param artifact Artifact to check 
  +     * 
  +     * @param repositories the list of repositories where resolver will be looking 
  +     *   for snapshot artifact
  +     * 
  +     * @return <code>true</code> in snapshot artifact was downloaded from remote 
repository, 
  +     * <code>false</code> otherwise
  +     */
  +    boolean resolveSnapshotArtifact( MavenArtifact artifact, List repositories );
       
   }
  
  
  
  1.2       +16 -4     
maven-components/maven-project/src/main/java/org/apache/maven/artifact/snapshot/SnapshotUtils.java
  
  Index: SnapshotUtils.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/artifact/snapshot/SnapshotUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SnapshotUtils.java        11 May 2004 20:13:14 -0000      1.1
  +++ SnapshotUtils.java        16 May 2004 15:58:10 -0000      1.2
  @@ -18,7 +18,7 @@
           formatter.setTimeZone( TimeZone.getTimeZone( "GMT" ) );    
       }
       
  -    public static String createSnapshotVersion()
  +    public static String getTimestamp()
       {
           Date now = new Date();
           
  @@ -28,11 +28,23 @@
       }
       
       
  -    public static Date parseSnapshotVersion( String snapshotVersion ) throws 
ParseException
  +    public static Date parseTimestamp( String timestamp ) throws ParseException
       {        
  -        Date retValue = formatter.parse( snapshotVersion );
  +        Date retValue = formatter.parse( timestamp );
           
           return retValue;       
  +    }
  +
  +
  +    /**
  +     * @param remoteVersion
  +     * @return
  +     */
  +    public static String getTimestamp( Date snapshotVersion )
  +    {
  +        String retValue = formatter.format( snapshotVersion );
  +        
  +        return retValue;   
       }
       
   }
  
  
  
  1.1                  
maven-components/maven-project/src/test/java/org/apache/maven/artifact/snapshot/DefaultSnapshotResolverTest.java
  
  Index: DefaultSnapshotResolverTest.java
  ===================================================================
  package org.apache.maven.artifact.snapshot;
  
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import java.io.File;
  import java.util.List;
  
  import org.apache.maven.artifact.MavenArtifact;
  import org.apache.maven.project.AbstractProjectTestCase;
  import org.apache.maven.project.MavenProject;
  import org.codehaus.plexus.util.FileUtils;
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]">Michal Maczka</a> 
   * @version $Id: DefaultSnapshotResolverTest.java,v 1.1 2004/05/16 15:58:10 michal 
Exp $ 
   */
  public class DefaultSnapshotResolverTest extends AbstractProjectTestCase
  {
  
      private SnapshotResolver snapshotResolver;
  
      /**
       * @param testName
       */
      public DefaultSnapshotResolverTest( String testName )
      {
          super( testName );
      }
  
      public void setUp() throws Exception
      {
  
          super.setUp();
  
          snapshotResolver = ( SnapshotResolver ) lookup( SnapshotResolver.ROLE );
  
          assertNotNull( "Test SnapshotResolver snapshotResolver can't be null!",
                  snapshotResolver );
  
      }
  
      public void testSnapshotResolving()
      {
  
          try
          {
              File f = new File( getLocalRepository(),
                      "/snapshot-test/poms/maven-test-snapshot-resolving-1.0.pom" );
  
              assertTrue( "Test file: '" + f.getAbsolutePath()
                      + "' doesn't exist!", f.exists() );
  
              System.setProperty( "maven.repo.local", getLocalRepository() );
  
              MavenProject project = buildProject( f );
  
              assertEquals( project.getLocalRepository(), getLocalRepository() );
  
              List artifacts = project.getArtifacts();
  
              assertEquals( 5, artifacts.size() );
  
              initRemoteRepositories( project );
  
              //  0 newer version of this snapshot is in remote repository 
  
              MavenArtifact a = ( MavenArtifact ) artifacts.get( 0 );
  
              snapshotResolver.resolveSnapshotArtifact( a, project.getRepositories() );
  
              assertEquals( "remote", getContent( a ) );
  
              assertEquals( "20050101.101010", getVersion( a ) );
  
              // 1 newer version of this snapshot is in local repository
  
              MavenArtifact b = ( MavenArtifact ) artifacts.get( 1 );
  
              snapshotResolver.resolveSnapshotArtifact( b, project.getRepositories() );
  
              assertEquals( "local", getContent( b ) );
  
              assertEquals( "20040101.101010", getVersion( b ) );
  
              // 2 this snapshot is missing in local repository but can be found in 
remote repository
              
              MavenArtifact c = ( MavenArtifact ) artifacts.get( 2 );
  
              snapshotResolver.resolveSnapshotArtifact( c, project.getRepositories() );
  
              assertEquals( "remote", getContent( c ) );
  
              assertEquals( "20040101.101010", getVersion( c ) );
  
              // 3 this snapshot is neither in local repository nor in any of remote 
repositories
              
              MavenArtifact d = ( MavenArtifact ) artifacts.get( 3 );
  
              snapshotResolver.resolveSnapshotArtifact( d, project.getRepositories() );
  
              assertEquals( null, getContent( d ) );
  
              assertEquals( null, getVersion( d ) );
  
              // 4 this snapshot is in the local repository but it was removed from 
all remote repositories
              
              MavenArtifact e = ( MavenArtifact ) artifacts.get( 4 );
  
              snapshotResolver.resolveSnapshotArtifact( e, project.getRepositories() );
  
              assertEquals( "local", getContent( e ) );
  
              assertEquals( "20040101.101010", getVersion( e ) );
  
          }
          catch ( Exception e )
          {
              e.printStackTrace();
  
              fail( e.getMessage() );
          }
  
      }
  
      private String getContent( MavenArtifact a )
      {
  
          String retValue = null;
  
          try
          {
              retValue = FileUtils.fileRead( a.getFile() );
  
          }
          catch ( Exception e )
          {
  
          }
  
          return retValue;
      }
  
      private String getVersion( MavenArtifact a )
      {
  
          String retValue = null;
  
          try
          {
              retValue = FileUtils.fileRead( a.getSnapshotVersionFile() );
  
          }
          catch ( Exception e )
          {
  
          }
  
          return retValue;
      }
  
  }
  
  
  1.3       +82 -115   
maven-components/maven-project/src/test/java/org/apache/maven/artifact/downloader/DefaultArtifactDownloaderTest.java
  
  Index: DefaultArtifactDownloaderTest.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-project/src/test/java/org/apache/maven/artifact/downloader/DefaultArtifactDownloaderTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultArtifactDownloaderTest.java        11 May 2004 19:21:10 -0000      1.2
  +++ DefaultArtifactDownloaderTest.java        16 May 2004 15:58:10 -0000      1.3
  @@ -16,13 +16,12 @@
    * limitations under the License.
    */
   
  -
   import org.apache.maven.artifact.MavenArtifact;
   import org.apache.maven.artifact.downloader.ArtifactDownloader;
   import org.apache.maven.artifact.factory.MavenArtifactFactory;
   import org.apache.maven.project.AbstractProjectTestCase;
   import org.apache.maven.project.MavenProject;
  -import org.codehaus.plexus.util.FileUtils;
  +
   
   import java.io.File;
   import java.util.List;
  @@ -32,135 +31,103 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Michal Maczka</a> 
    * @version $Id$
    */
  -public class DefaultArtifactDownloaderTest
  -    extends AbstractProjectTestCase
  +public class DefaultArtifactDownloaderTest extends AbstractProjectTestCase
   {
  -    
  +
       private ArtifactDownloader artifactDownloader;
  -    
  +
       private MavenArtifactFactory artifactFactory;
  -    
  -    
  +
       public DefaultArtifactDownloaderTest( String testName )
       {
           super( testName );
       }
  -    
  -    
  -       
  +
       public void setUp() throws Exception
       {
           super.setUp();
  -        
  +
           artifactDownloader = ( ArtifactDownloader ) lookup( ArtifactDownloader.ROLE 
);
  -        
  -        assertNotNull( "Test artifactDownloader can't be null!", artifactDownloader 
);
  -        
  +
  +        assertNotNull( "Test artifactDownloader can't be null!",
  +                artifactDownloader );
  +
           artifactFactory = ( MavenArtifactFactory ) lookup( 
MavenArtifactFactory.ROLE );
  -        
  +
       }
   
  -  
  -    
  -    public void testArtifactDownloading( )       
  +    public void testArtifactDownloading()
       {
  -                        
  -        
  -        File f = new File( getLocalRepository(), 
"/maven-test/poms/maven-test-a-1.0.pom" );
   
  -        assertTrue( "Test file: '" + f.getAbsolutePath() + "' doesn't exist!", 
f.exists() );
  +        File f = new File( getLocalRepository(),
  +                "/maven-test/poms/maven-test-a-1.0.pom" );
   
  -        File tempLocalRepository = new File( basedir, "target/test-repo-local" );
  -        
  -        tempLocalRepository.mkdirs();
  +        assertTrue( "Test file: '" + f.getAbsolutePath() + "' doesn't exist!",
  +                f.exists() );
  +
  +        initLocalRepository();
           
  -        System.out.println( "Crated local repo: " + tempLocalRepository );
  +        MavenProject project = buildProject( f );
  +
  +        assertTrue( "Local repsoitory could not be crated", f.exists() );
  +
  +        initRemoteRepositories( project );
  +
  +        List artifacts = project.getArtifacts();
  +
  +        assertEquals( 2, artifacts.size() );
  +
  +        /*we are using a POM which looks like follows:
  +         <dependency>
  +         <groupId>maven-test</groupId>
  +         <artifactId>maven-test-b</artifactId>
  +         <version>1.0</version>
  +         </dependency>                    
  +         <dependency>
  +         <groupId>maven-test</groupId>
  +         <artifactId>maven-test-z</artifactId>
  +         <version>1.0</version>
  +         </dependency>
  +         */
  +
  +        MavenArtifact artifactB = ( MavenArtifact ) artifacts.get( 0 );
  +
  +        MavenArtifact artifactZ = ( MavenArtifact ) artifacts.get( 1 );
  +
  +        assertFalse( artifactB.exists() );
  +
  +        assertFalse( artifactZ.exists() );
  +
  +        // this one is in repo-1
  +        assertTrue( "B should have been downloaded", artifactDownloader
  +                .getRemoteArtifact( artifactB, project.getRepositories() ) );
  +
  +        assertTrue( "B should have been downloaded", artifactB.exists() );
  +
  +        // this one is in repo-2
  +        assertTrue( "Z should have been downloaded: " + artifactZ.getFile() , 
artifactDownloader
  +                .getRemoteArtifact( artifactZ, project.getRepositories() ) );
           
  -        try
  -        {
  -            
  -            // that's the only was I can influence MavenProjectBuilder
  -            System.setProperty( "maven.repo.local", tempLocalRepository.getPath()  
);
  -            
  -            try
  -            {
  -               FileUtils.deleteDirectory( tempLocalRepository  );
  -            }
  -            catch( Exception e)
  -            {
  -            }
  -            
  -            MavenProject project = projectBuilder.build( f );
  -                                              
  -            assertNotNull( "Project is null", project );
  -            
  -            assertTrue( "Local repsoitory could not be crated", f.exists() );
  -            
  -            File repo_1 = new File( basedir, "src/test/resources/remote-repo-1"  );
  -            
  -            File repo_2 = new File( basedir, "src/test/resources/remote-repo-2"  );
  -            
  -            project.addRepository( "file://" + repo_1.getPath()  );
  -            
  -            project.addRepository( "file://" + repo_2.getPath()  );
  -
  -            assertEquals( 2, project.getRepositories().size() );
  -            
  -            
  -            List artifacts = project.getArtifacts();
  -            
  -            assertEquals( 2,  artifacts.size() );
  -            
  -            /*we are using a POM which looks like follows:
  -            <dependency>
  -              <groupId>maven-test</groupId>
  -              <artifactId>maven-test-b</artifactId>
  -              <version>1.0</version>
  -            </dependency>                    
  -            <dependency>
  -              <groupId>maven-test</groupId>
  -              <artifactId>maven-test-z</artifactId>
  -              <version>1.0</version>
  -            </dependency>
  -           */
  -            
  -            MavenArtifact artifactB = ( MavenArtifact ) artifacts.get( 0 );
  -            
  -            MavenArtifact artifactZ = ( MavenArtifact ) artifacts.get( 1 );
  -            
  -            assertFalse( artifactB.exists() );
  -            
  -            assertFalse( artifactZ.exists() );
  -            
  -            // this one is in repo-1
  -            assertTrue( "B should have been downloaded", 
artifactDownloader.getRemoteArtifact( artifactB, project.getRepositories() ) );
  -
  -            assertTrue( "B should have been downloaded", artifactB.exists() );
  -            
  -            // this one is in repo-2
  -            assertTrue(  "Z should have been downloaded", 
artifactDownloader.getRemoteArtifact( artifactZ, project.getRepositories() ) );
  -            
  -            assertTrue( "Z should have been downloaded", artifactZ.exists() );
  -            
  -            // A has accompanying   md5 file
  -            assertTrue( "MD5 file for B should have been downloaded",  
artifactB.getChecksumFile().exists() );
  -                       
  -            //Z does not have md5 file
  -            assertFalse( "MD5 file for Z does not exist in any repo and should not 
be downloaded. File : " + artifactZ.getChecksumFile() + " exists.", 
artifactZ.getChecksumFile().exists() );
  -            
  -            // try to crate bizzare artifact and download it. this should fail.
  -            
  -            artifactB.getDependency().setGroupId( "bizzare" );
  -            
  -            assertFalse( "Not existing artifact cannot be downloaded", 
artifactDownloader.getRemoteArtifact( artifactB, project.getRepositories() ) );
  -            
  -            
  -        }
  -        catch ( Exception e )
  -        {  
  -             e.printStackTrace();
  -             
  -             fail( e.getMessage() );
  -        }
  +
  +        assertTrue( "Z should have been downloaded", artifactZ.exists() );
  +
  +        // A has accompanying  md5 file
  +        assertTrue( "MD5 file for B should have been downloaded", artifactB
  +                .getChecksumFile().exists() );
  +
  +        //Z does not have md5 file
  +        assertFalse(
  +                "MD5 file for Z does not exist in any repo and should not be 
downloaded. File : "
  +                        + artifactZ.getChecksumFile() + " exists.", artifactZ
  +                        .getChecksumFile().exists() );
  +
  +        // try to crate bizzare artifact and download it. this should fail.
  +
  +        artifactB.getDependency().setGroupId( "bizzare" );
  +
  +        assertFalse( "Not existing artifact cannot be downloaded",
  +                artifactDownloader.getRemoteArtifact( artifactB, project
  +                        .getRepositories() ) );
  +
       }
  -}
  +}
  \ No newline at end of file
  
  
  
  1.1                  
maven-components/maven-project/src/test/resources/local-repo/snapshot-test/poms/maven-test-snapshot-resolving-1.0.pom
  
  Index: maven-test-snapshot-resolving-1.0.pom
  ===================================================================
  <project>
    <groupId>snapshot-test</groupId>
    <artifactId>maven-test-snapshot-resolving</artifactId>
    <currentVersion>1.0</currentVersion>
    <dependencies>
      
      <!-- newer version of this snapshot is in remote repository -->
      <dependency>
        <groupId>snapshot-test</groupId>
        <artifactId>maven-snapshot-a</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
      
      <!-- newer version of this snapshot is in local repository -->
      <dependency>
        <groupId>snapshot-test</groupId>
        <artifactId>maven-snapshot-b</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
  
  
      <!-- this snapshot is missing in local repository but can be found in remote 
repository -->
      <dependency>
        <groupId>snapshot-test</groupId>
        <artifactId>maven-snapshot-c</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
      
      <!-- this snapshot is neither in local repository nor in any of remote 
repositories -->
      <dependency>
        <groupId>snapshot-test</groupId>
        <artifactId>maven-snapshot-d</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
  
      <!-- this snapshot is in the local repository but it was removed from all remote 
repositories -->
      <dependency>
        <groupId>snapshot-test</groupId>
        <artifactId>maven-snapshot-e</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
  
  
      
    </dependencies>
  </project>
  
  
  
  1.2       +6 -3      
maven-components/maven-project/src/main/java/org/apache/maven/artifact/downloader/DefaultArtifactDownloader.java
  
  Index: DefaultArtifactDownloader.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/artifact/downloader/DefaultArtifactDownloader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultArtifactDownloader.java    11 May 2004 19:21:10 -0000      1.1
  +++ DefaultArtifactDownloader.java    16 May 2004 15:58:10 -0000      1.2
  @@ -79,7 +79,7 @@
               
               wagon.connect(  repository  );
               
  -            return get( wagon, artifact );
  +            return getRemoteArtifact( artifact, wagon );
               
           }
           catch ( Exception e )
  @@ -110,7 +110,7 @@
        * @param wagon
        * @param artifact
        */
  -    private boolean get( Wagon wagon, MavenArtifact artifact ) 
  +    public boolean getRemoteArtifact( MavenArtifact artifact, Wagon wagon ) 
       {
           
           getLogger().info( "Trying to download: " + artifact.getUrlPath() + "  from 
" + wagon.getRepository().getUrl() );
  @@ -156,6 +156,9 @@
           return true;
                   
       }
  +
  +
  +    
   
       
   
  
  
  
  1.2       +11 -4     
maven-components/maven-project/src/main/java/org/apache/maven/artifact/downloader/ArtifactDownloader.java
  
  Index: ArtifactDownloader.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-project/src/main/java/org/apache/maven/artifact/downloader/ArtifactDownloader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArtifactDownloader.java   11 May 2004 19:21:10 -0000      1.1
  +++ ArtifactDownloader.java   16 May 2004 15:58:10 -0000      1.2
  @@ -3,6 +3,7 @@
   import java.util.List;
   
   import org.apache.maven.artifact.MavenArtifact;
  +import org.apache.maven.wagon.Wagon;
   import org.apache.maven.wagon.repository.Repository;
   
   
  @@ -18,7 +19,7 @@
   public interface ArtifactDownloader
   {
       /** Component role name*/
  -    public static final String ROLE = ArtifactDownloader.class.getName(  );
  +    String ROLE = ArtifactDownloader.class.getName(  );
   
       /**
        * Downloads given <code>artifact</code> from the maven remote repositories
  @@ -27,7 +28,7 @@
        * @param artifact the artifact to retrieve from the repositories.
        * @return true if the download is successful, <code>false</code> otherwise.
        */
  -    public boolean getRemoteArtifact( MavenArtifact artifact, Repository 
remoteRepository );
  +    boolean getRemoteArtifact( MavenArtifact artifact, Repository remoteRepository 
);
   
       /**
        *
  @@ -36,7 +37,13 @@
   
        * @return <code>true</code> if the from any of the repositories were 
succesful, <code>false</code> otherwise
        */
  -    public boolean getRemoteArtifact( MavenArtifact artifact, List repositories );
  +    boolean getRemoteArtifact( MavenArtifact artifact, List repositories );
  +
  +    /**
  +     * @param artifact
  +     * @param wagon
  +     */
  +    boolean getRemoteArtifact( MavenArtifact artifact, Wagon wagon );
   
   
   }
  
  
  

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

Reply via email to