maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject cvs commit: maven-components/maven-artifact/src/test/java/org/apache/maven/project AbstractProjectTestCase.java
Date Mon, 14 Jun 2004 17:07:16 GMT
jvanzyl     2004/06/14 10:07:15

  Modified:    maven-artifact pom.xml
               maven-artifact/src/main/java/org/apache/maven/artifact/downloader
                        DefaultArtifactDownloader.java
               maven-artifact/src/main/java/org/apache/maven/artifact/resolver
                        DefaultArtifactResolver.java
               maven-artifact/src/main/java/org/apache/maven/artifact/snapshot
                        DefaultSnapshotResolver.java
               maven-artifact/src/main/resources/META-INF/plexus
                        components.xml
               maven-artifact/src/test/java/org/apache/maven/artifact/downloader
                        DefaultArtifactDownloaderTest.java
               maven-artifact/src/test/java/org/apache/maven/artifact/snapshot
                        DefaultSnapshotResolverTest.java
               maven-artifact/src/test/java/org/apache/maven/project
                        AbstractProjectTestCase.java
  Log:
  o fully decoupling maven-artifact from maven-core
  
  Revision  Changes    Path
  1.2       +0 -5      maven-components/maven-artifact/pom.xml
  
  Index: pom.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/pom.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- pom.xml	11 Jun 2004 15:12:24 -0000	1.1
  +++ pom.xml	14 Jun 2004 17:07:15 -0000	1.2
  @@ -21,11 +21,6 @@
       </dependency>
       <dependency>
         <groupId>maven</groupId>
  -      <artifactId>maven-project</artifactId>
  -      <version>2.0-SNAPSHOT</version>
  -    </dependency>    
  -    <dependency>
  -      <groupId>maven</groupId>
         <artifactId>wagon-api</artifactId>
         <version>0.9-SNAPSHOT</version>
       </dependency>
  
  
  
  1.2       +1 -4      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/downloader/DefaultArtifactDownloader.java
  
  Index: DefaultArtifactDownloader.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/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 Jun 2004 15:12:24 -0000	1.1
  +++ DefaultArtifactDownloader.java	14 Jun 2004 17:07:15 -0000	1.2
  @@ -6,7 +6,6 @@
   
   import org.apache.maven.artifact.MavenArtifact;
   import org.apache.maven.artifact.repository.RepositoryUtils;
  -import org.apache.maven.artifact.factory.MavenArtifactFactory;
   import org.apache.maven.wagon.ResourceDoesNotExistException;
   import org.apache.maven.wagon.TransferFailedException;
   import org.apache.maven.wagon.Wagon;
  @@ -29,8 +28,6 @@
       implements ArtifactDownloader
   {
       private WagonManager wagonManager;
  -
  -    private MavenArtifactFactory artifactFactory;
   
       public boolean getRemoteArtifact( MavenArtifact artifact, List repositories )
       {
  
  
  
  1.2       +42 -5     maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
  
  Index: DefaultArtifactResolver.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultArtifactResolver.java	11 Jun 2004 15:12:25 -0000	1.1
  +++ DefaultArtifactResolver.java	14 Jun 2004 17:07:15 -0000	1.2
  @@ -1,8 +1,8 @@
   package org.apache.maven.artifact.resolver;
   
   import org.apache.maven.artifact.MavenArtifact;
  +import org.apache.maven.artifact.GenericMavenArtifact;
   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;
   
  @@ -15,15 +15,13 @@
   public class DefaultArtifactResolver
       implements ArtifactResolver
   {
  -    private MavenArtifactFactory artifactFactory;
  -    
       private ArtifactDownloader artifactDownloader;
   
       private SnapshotResolver snapshotResolver;
       
       public MavenArtifact getArtifact( Dependency dependency, String localRepository, List
repositories )
       {
  -       MavenArtifact retValue =  artifactFactory.createArtifact( dependency, localRepository
);
  +       MavenArtifact retValue =  createArtifact( dependency, localRepository );
   
          if ( retValue.isSnapshot() )
          {
  @@ -66,5 +64,44 @@
       public MavenArtifact getPomArtifact( Dependency dependency, String localRepository,
List repositories )
       {
           return getArtifact( dependency, "pom", localRepository, repositories );
  +    }
  +
  +    public MavenArtifact createArtifact( Dependency dependency )
  +    {
  +        if (    dependency.getType() == null
  +             || dependency.getType().trim().length() == 0
  +             || dependency.getType().equals( "jar" )
  +             || dependency.getType().equals( "test" ) )
  +        {
  +            dependency.setType( "jar" );
  +            return new GenericMavenArtifact( dependency );
  +        }
  +        else
  +        {
  +            return new GenericMavenArtifact( dependency );
  +        }
  +    }
  +
  +    public MavenArtifact createArtifact( Dependency dependency, String mavenRepoLocal )
  +    {
  +
  +        MavenArtifact retValue = null;
  +
  +        if (    dependency.getType() == null
  +             || dependency.getType().trim().length() == 0
  +             || dependency.getType().equals( "jar" )
  +             || dependency.getType().equals( "test" ) )
  +        {
  +            dependency.setType( "jar" );
  +            retValue = new GenericMavenArtifact( dependency );
  +        }
  +        else
  +        {
  +            retValue = new GenericMavenArtifact( dependency );
  +        }
  +
  +        retValue.setPath( mavenRepoLocal + retValue.generatePath() );
  +
  +        return retValue;
       }
   }
  
  
  
  1.2       +3 -1      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/snapshot/DefaultSnapshotResolver.java
  
  Index: DefaultSnapshotResolver.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/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 Jun 2004 15:12:25 -0000	1.1
  +++ DefaultSnapshotResolver.java	14 Jun 2004 17:07:15 -0000	1.2
  @@ -21,6 +21,8 @@
   public class DefaultSnapshotResolver
       implements SnapshotResolver
   {
  +    //@todo why do we need wagonManager and artifact downloader here?
  +
       private WagonManager wagonManager;
   
       private ArtifactDownloader artifactDownloader;
  
  
  
  1.2       +0 -38     maven-components/maven-artifact/src/main/resources/META-INF/plexus/components.xml
  
  Index: components.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/resources/META-INF/plexus/components.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- components.xml	11 Jun 2004 15:12:25 -0000	1.1
  +++ components.xml	14 Jun 2004 17:07:15 -0000	1.2
  @@ -1,44 +1,10 @@
   <component-set>
     <components>
       <component>
  -      <role>org.apache.maven.project.MavenProjectBuilder</role>
  -      <implementation>org.apache.maven.project.DefaultMavenProjectBuilder</implementation>
  -      <requirements>
  -        <requirement>
  -          <role>org.apache.maven.project.ModelInheritanceAssembler</role>
  -        </requirement>
  -        <requirement>
  -          <role>org.apache.maven.artifact.collector.ArtifactCollector</role>
  -        </requirement>        
  -        <requirement>
  -          <role>org.apache.maven.artifact.factory.MavenArtifactFactory</role>
  -        </requirement>
  -        <requirement>
  -          <role>org.apache.maven.wagon.manager.WagonManager</role>
  -        </requirement>
  -      </requirements>
  -    </component>
  -    <component>
  -      <role>org.apache.maven.artifact.factory.MavenArtifactFactory</role>
  -      <implementation>org.apache.maven.artifact.factory.DefaultMavenArtifactFactory</implementation>
  -    </component>
  -    <component>
  -      <role>org.apache.maven.artifact.collector.ArtifactCollector</role>
  -      <implementation>org.apache.maven.artifact.collector.DefaultArtifactCollector</implementation>
  -      <requirements>
  -        <requirement>
  -          <role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
  -        </requirement>             
  -      </requirements>
  -    </component>
  -    <component>
         <role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
         <implementation>org.apache.maven.artifact.resolver.DefaultArtifactResolver</implementation>
         <requirements>
           <requirement>
  -          <role>org.apache.maven.artifact.factory.MavenArtifactFactory</role>
  -        </requirement>
  -        <requirement>
             <role>org.apache.maven.artifact.downloader.ArtifactDownloader</role>
           </requirement>
           <requirement>
  @@ -55,10 +21,6 @@
           </requirement>
         </requirements>
       </component>        
  -    <component>
  -      <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>
  
  
  
  1.2       +20 -33    maven-components/maven-artifact/src/test/java/org/apache/maven/artifact/downloader/DefaultArtifactDownloaderTest.java
  
  Index: DefaultArtifactDownloaderTest.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/test/java/org/apache/maven/artifact/downloader/DefaultArtifactDownloaderTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultArtifactDownloaderTest.java	11 Jun 2004 15:12:25 -0000	1.1
  +++ DefaultArtifactDownloaderTest.java	14 Jun 2004 17:07:15 -0000	1.2
  @@ -17,16 +17,14 @@
    */
   
   import org.apache.maven.artifact.MavenArtifact;
  -import org.apache.maven.artifact.factory.MavenArtifactFactory;
  +import org.apache.maven.model.Model;
   import org.apache.maven.project.AbstractProjectTestCase;
  -import org.apache.maven.project.MavenProject;
   
   import java.io.File;
   import java.util.List;
   
   /**
  - * 
  - * @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a> 
  + * @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a>
    * @version $Id$
    */
   public class DefaultArtifactDownloaderTest
  @@ -34,8 +32,6 @@
   {
       private ArtifactDownloader artifactDownloader;
   
  -    private MavenArtifactFactory artifactFactory;
  -
       public DefaultArtifactDownloaderTest( String testName )
       {
           super( testName );
  @@ -46,11 +42,9 @@
       {
           super.setUp();
   
  -        artifactDownloader = ( ArtifactDownloader ) lookup( ArtifactDownloader.ROLE );
  +        artifactDownloader = (ArtifactDownloader) lookup( ArtifactDownloader.ROLE );
   
           assertNotNull( "Test artifactDownloader can't be null!", artifactDownloader );
  -
  -        artifactFactory = ( MavenArtifactFactory ) lookup( MavenArtifactFactory.ROLE );
       }
   
       public void testArtifactDownloading()
  @@ -58,17 +52,17 @@
       {
           File f = new File( getLocalRepository(), "/maven-test/poms/maven-test-a-1.0.pom"
);
   
  +         Model model = getModel( f );
  +
           assertTrue( "Test file: '" + f.getAbsolutePath() + "' doesn't exist!", f.exists()
);
   
           initLocalRepository();
  -        
  -        MavenProject project = buildProject( f, true, false );
   
           assertTrue( "Local repsoitory could not be crated", f.exists() );
   
  -        initRemoteRepositories( project );
  +        List repos = initRemoteRepositories( model );
   
  -        List artifacts = project.getArtifacts();
  +        List artifacts = getArtifacts( model );
   
           //2 artifact
           assertEquals( 2, artifacts.size() );
  @@ -86,44 +80,37 @@
            </dependency>
            */
   
  -        MavenArtifact artifactB = ( MavenArtifact ) artifacts.get( 0 );
  +        MavenArtifact artifactB = (MavenArtifact) artifacts.get( 0 );
   
  -        MavenArtifact artifactZ = ( MavenArtifact ) artifacts.get( 1 );
  +        MavenArtifact artifactZ = (MavenArtifact) artifacts.get( 1 );
   
  -        assertFalse( artifactB.exists() );
  +        //assertFalse( artifactB.exists() );
   
  -        assertFalse( artifactZ.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", artifactDownloader.getRemoteArtifact(
artifactB, repos ) );
   
           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() ) );
  -        
  +        assertTrue( "Z should have been downloaded: " + artifactZ.getFile(), artifactDownloader.getRemoteArtifact(
artifactZ, repos ) );
  +
   
           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() );
  +        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() );
  +        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() ) );
  -
  +        assertFalse( "Not existing artifact cannot be downloaded", artifactDownloader.getRemoteArtifact(
artifactB, repos ) );
       }
   }
  
  
  
  1.2       +14 -15    maven-components/maven-artifact/src/test/java/org/apache/maven/artifact/snapshot/DefaultSnapshotResolverTest.java
  
  Index: DefaultSnapshotResolverTest.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/test/java/org/apache/maven/artifact/snapshot/DefaultSnapshotResolverTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultSnapshotResolverTest.java	11 Jun 2004 15:12:25 -0000	1.1
  +++ DefaultSnapshotResolverTest.java	14 Jun 2004 17:07:15 -0000	1.2
  @@ -16,14 +16,14 @@
    * limitations under the License.
    */
   
  -import java.io.File;
  -import java.util.List;
  -
   import org.apache.maven.artifact.MavenArtifact;
  +import org.apache.maven.model.Model;
   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;
  +
   /**
    * @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a>
    * @version $Id$
  @@ -49,6 +49,7 @@
                          snapshotResolver );
       }
   
  +
       public void testSnapshotResolving()
           throws Exception
       {
  @@ -58,21 +59,19 @@
   
           System.setProperty( "maven.repo.local", getLocalRepository() );
   
  -        MavenProject project = buildProject( f );
  -
  -        assertEquals( project.getLocalRepository(), getLocalRepository() );
  +        Model model = getModel( f );
   
  -        List artifacts = project.getArtifacts();
  +        List artifacts = getArtifacts( model );
   
           assertEquals( 5, artifacts.size() );
   
  -        initRemoteRepositories( project );
  +        List repos = initRemoteRepositories( model );
   
           //  0 newer version of this snapshot is in remote repository
   
           MavenArtifact a = (MavenArtifact) artifacts.get( 0 );
   
  -        snapshotResolver.resolveSnapshotArtifact( a, project.getRepositories() );
  +        snapshotResolver.resolveSnapshotArtifact( a, repos );
   
           assertEquals( "remote", getContent( a ) );
   
  @@ -82,7 +81,7 @@
   
           MavenArtifact b = (MavenArtifact) artifacts.get( 1 );
   
  -        snapshotResolver.resolveSnapshotArtifact( b, project.getRepositories() );
  +        snapshotResolver.resolveSnapshotArtifact( b, repos );
   
           assertEquals( "local", getContent( b ) );
   
  @@ -92,7 +91,7 @@
   
           MavenArtifact c = (MavenArtifact) artifacts.get( 2 );
   
  -        snapshotResolver.resolveSnapshotArtifact( c, project.getRepositories() );
  +        snapshotResolver.resolveSnapshotArtifact( c, repos );
   
           assertEquals( "remote", getContent( c ) );
   
  @@ -102,7 +101,7 @@
   
           MavenArtifact d = (MavenArtifact) artifacts.get( 3 );
   
  -        snapshotResolver.resolveSnapshotArtifact( d, project.getRepositories() );
  +        snapshotResolver.resolveSnapshotArtifact( d, repos );
   
           assertEquals( null, getContent( d ) );
   
  @@ -112,7 +111,7 @@
   
           MavenArtifact e = (MavenArtifact) artifacts.get( 4 );
   
  -        snapshotResolver.resolveSnapshotArtifact( e, project.getRepositories() );
  +        snapshotResolver.resolveSnapshotArtifact( e, repos );
   
           assertEquals( "local", getContent( e ) );
   
  
  
  
  1.2       +44 -25    maven-components/maven-artifact/src/test/java/org/apache/maven/project/AbstractProjectTestCase.java
  
  Index: AbstractProjectTestCase.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/test/java/org/apache/maven/project/AbstractProjectTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractProjectTestCase.java	11 Jun 2004 15:12:25 -0000	1.1
  +++ AbstractProjectTestCase.java	14 Jun 2004 17:07:15 -0000	1.2
  @@ -1,16 +1,24 @@
   package org.apache.maven.project;
   
   import java.io.File;
  +import java.io.FileReader;
  +import java.util.List;
  +import java.util.ArrayList;
  +import java.util.Iterator;
   
   import org.codehaus.plexus.PlexusTestCase;
   import org.codehaus.plexus.util.FileUtils;
  +import org.apache.maven.model.Repository;
  +import org.apache.maven.model.Model;
  +import org.apache.maven.model.Dependency;
  +import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
  +import org.apache.maven.artifact.GenericMavenArtifact;
  +import org.apache.maven.artifact.MavenArtifact;
   
   public class AbstractProjectTestCase
       extends PlexusTestCase
   {
  -    protected MavenProjectBuilder projectBuilder;
  -
  -    private String localRepository = System.getProperty( "basedir" ) + "/target/test-classes/local-repo";
  +    protected String localRepository = System.getProperty( "basedir" ) + "/target/test-classes/local-repo";
   
       public AbstractProjectTestCase( String testName )
       {
  @@ -21,10 +29,6 @@
           throws Exception
       {
           super.setUp();
  -
  -        projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
  -
  -        assertNotNull( "Test projectBuilder can't be null!", projectBuilder );
       }
   
       public String getLocalRepository()
  @@ -55,40 +59,55 @@
           System.setProperty( "maven.repo.local", tempLocalRepository.getPath() );
       }
   
  -    protected MavenProject buildProject( File f, boolean useParentPom, boolean followTransitiveDeps
 )
  -       throws Exception
  +    protected Model getModel( File f )
  +        throws Exception
       {
  -        MavenProject project = null;
  -
  -        project = projectBuilder.build( f, useParentPom, followTransitiveDeps );
  +        MavenXpp3Reader reader = new MavenXpp3Reader();
   
  -        assertNotNull( "Project is null", project );
  -
  -        return project;
  +        Model model = reader.read( new FileReader( f ) );
   
  +        return model;
       }
   
  -    protected MavenProject buildProject( File f  )
  -        throws Exception
  +    protected List getArtifacts( Model model )
       {
  -          return buildProject(  f, true, false );
  +        List artifacts = new ArrayList();
  +
  +        for ( Iterator i = model.getDependencies().iterator(); i.hasNext(); )
  +        {
  +            Dependency d = (Dependency) i.next();
  +
  +            MavenArtifact artifact = new GenericMavenArtifact( d );
  +
  +            artifact.setPath( localRepository + artifact.generatePath() );
  +
  +            artifacts.add( artifact );
  +        }
  +
  +        return artifacts;
       }
   
  -    protected void initRemoteRepositories( MavenProject project )
  +    protected List initRemoteRepositories( Model model )
  +        throws Exception
       {
  -        //we will remove ibiblio
  -        project.getRepositories().clear();
  +        List repositories = model.getRepositories();
   
           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() );
  +        Repository r = new Repository();
   
  -        project.addRepository( "file://" + repo_2.getPath() );
  +        r.setUrl( "file://" + repo_1.getAbsolutePath());
   
  -        assertEquals( 2, project.getRepositories().size() );
  -    }
  +        repositories.add( r );
  +
  +        r = new Repository();
   
  +        r.setUrl( "file://" + repo_2.getAbsolutePath() );
   
  +        repositories.add( r );
  +
  +        return repositories;
  +    }
   }
  
  
  

Mime
View raw message