maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ogusa...@apache.org
Subject svn commit: r707524 - in /maven/mercury/trunk: mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/ mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/ mercury-it/src/test/java/org/apache/maven/mercury/depende...
Date Fri, 24 Oct 2008 01:58:42 GMT
Author: ogusakov
Date: Thu Oct 23 18:58:41 2008
New Revision: 707524

URL: http://svn.apache.org/viewvc?rev=707524&view=rev
Log:
first version of POM reader integration works fine

Added:
    maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java
Modified:
    maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionComparator.java
    maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/QualityTest.java
    maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/dependency/tests/DependencyTreeBuilderTest.java
    maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java
    maven/mercury/trunk/mercury-repo/mercury-repo-virtual/src/main/java/org/apache/maven/mercury/repository/virtual/Messages.properties
    maven/mercury/trunk/mercury-repo/mercury-repo-virtual/src/main/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReader.java
    maven/mercury/trunk/mercury-transport/mercury-transport-api/src/main/java/org/apache/maven/mercury/transport/api/Server.java

Added: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java?rev=707524&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java
(added)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java
Thu Oct 23 18:58:41 2008
@@ -0,0 +1,32 @@
+package org.apache.maven.mercury.artifact.version;
+
+import java.util.Comparator;
+
+import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * version comparator used elsewhere to keep version collections sorted
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class MetadataVersionComparator
+implements Comparator<ArtifactBasicMetadata>
+{
+  private static final Language _lang = new DefaultLanguage( MetadataVersionComparator.class
);
+  
+  public int compare( ArtifactBasicMetadata v1, ArtifactBasicMetadata v2 )
+  {
+    if( v1 == null || v2 == null )
+      throw new IllegalArgumentException( _lang.getMessage( "null.version.to.compare", v1
== null ? "null" : v1.toString(), v2 == null ? "null" : v2.toString() )  );
+    
+    DefaultArtifactVersion av1 = new DefaultArtifactVersion( v1.getVersion() );
+    DefaultArtifactVersion av2 = new DefaultArtifactVersion( v2.getVersion() );
+    
+    return av1.compareTo( av2 );
+  }
+
+}

Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionComparator.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionComparator.java?rev=707524&r1=707523&r2=707524&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionComparator.java
(original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionComparator.java
Thu Oct 23 18:58:41 2008
@@ -13,7 +13,7 @@
  *
  */
 public class VersionComparator
-    implements Comparator<String>
+implements Comparator<String>
 {
   private static final Language _lang = new DefaultLanguage( VersionComparator.class );
   

Modified: maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/QualityTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/QualityTest.java?rev=707524&r1=707523&r2=707524&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/QualityTest.java
(original)
+++ maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/QualityTest.java
Thu Oct 23 18:58:41 2008
@@ -19,8 +19,12 @@
   public void testEquality()
   {
     q = new Quality("LATEST");
-    
     assertTrue( q.equals( Quality.FIXED_LATEST_QUALITY ) );
     
+    q = new Quality("RELEASE");
+    assertTrue( q.equals( Quality.FIXED_RELEASE_QUALITY ) );
+    
+    q = new Quality("1.1-SNAPSHOT");
+    assertTrue( q.equals( Quality.SNAPSHOT_QUALITY ) );
   }
 }

Modified: maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/dependency/tests/DependencyTreeBuilderTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/dependency/tests/DependencyTreeBuilderTest.java?rev=707524&r1=707523&r2=707524&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/dependency/tests/DependencyTreeBuilderTest.java
(original)
+++ maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/dependency/tests/DependencyTreeBuilderTest.java
Thu Oct 23 18:58:41 2008
@@ -3,11 +3,17 @@
 import java.io.File;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
 
 import junit.framework.TestCase;
 
+import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.mercury.MavenDependencyProcessor;
+import org.apache.maven.mercury.artifact.Artifact;
 import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
 import org.apache.maven.mercury.artifact.ArtifactMetadata;
 import org.apache.maven.mercury.artifact.ArtifactScopeEnum;
@@ -16,10 +22,14 @@
 import org.apache.maven.mercury.metadata.MetadataTreeCircularDependencyException;
 import org.apache.maven.mercury.metadata.MetadataTreeException;
 import org.apache.maven.mercury.metadata.MetadataTreeNode;
+import org.apache.maven.mercury.repository.api.ArtifactResults;
 import org.apache.maven.mercury.repository.api.Repository;
+import org.apache.maven.mercury.repository.api.RepositoryException;
+import org.apache.maven.mercury.repository.api.RepositoryReader;
 import org.apache.maven.mercury.repository.local.m2.LocalRepositoryM2;
 import org.apache.maven.mercury.repository.local.m2.MetadataProcessorMock;
 import org.apache.maven.mercury.repository.remote.m2.RemoteRepositoryM2;
+import org.apache.maven.mercury.repository.virtual.VirtualRepositoryReader;
 import org.apache.maven.mercury.transport.api.Server;
 
 
@@ -33,21 +43,27 @@
 {
   private static final org.slf4j.Logger _log = org.slf4j.LoggerFactory.getLogger( DependencyTreeBuilderTest.class
); 
   
-  String repoUrl = "http://repository.sonatype.org/content/groups/public";
+//  String repoUrl = "http://repository.sonatype.org/content/groups/public";
+  String repoUrl = "http://nexus:8081/nexus/content/groups/public";
 
   File repoDir;
   
-  DependencyTreeBuilder mt;
+  DependencyTreeBuilder depBuilder;
   LocalRepositoryM2 localRepo;
   RemoteRepositoryM2 remoteRepo;
   List<Repository> reps;
   DependencyProcessor processor;
   
+  VirtualRepositoryReader vReader;
+  
   //----------------------------------------------------------------------------------------------
   @Override
   protected void setUp()
   throws Exception
   {
+    
+    Logger.getLogger("").setLevel(Level.ALL);
+
     repoDir = File.createTempFile( "local-repo-","-it");
     repoDir.delete();
     repoDir.mkdirs();
@@ -62,10 +78,16 @@
     Server server = new Server( "testRemoteRepo", new URL(repoUrl) );
     remoteRepo = new RemoteRepositoryM2(server);
     reps.add( remoteRepo );
+    
+//    Server central = new Server("central", new URL("http://repo1.maven.org/maven2") );
+//    RemoteRepositoryM2 centralRepo = new RemoteRepositoryM2(central);
+//    reps.add(centralRepo);
 
     processor = new MavenDependencyProcessor();
 
-    mt = new DependencyTreeBuilder( null, null, null, reps, processor );
+    depBuilder = new DependencyTreeBuilder( null, null, null, reps, processor );
+    
+    vReader = new VirtualRepositoryReader( reps, processor );
   }
   //----------------------------------------------------------------------------------------------
   @Override
@@ -82,27 +104,62 @@
   }
   //----------------------------------------------------------------------------------------------
   public void ntestResolveConflicts()
-  throws MetadataTreeException
+  throws Exception
   {
-    ArtifactMetadata md = new ArtifactMetadata( "org.codehaus.plexus:plexus-compiler:1.5.3"
);
+//    String artifactId = "org.testng:testng:5.7";
+    String artifactId = "asm:asm-xml:3.0";
+//  String artifactId = "org.apache.maven:maven-core:2.0.9";
+//  String artifactId = "qdox:qdox:1.6.1";
+    
     
-    MetadataTreeNode root = mt.buildTree( md );
+    ArtifactMetadata md = new ArtifactMetadata( artifactId );
+
+    MetadataTreeNode root = depBuilder.buildTree( md );
 
     assertNotNull( "null tree built", root );
     
 //    assertTrue( "wrong tree size, expected gte 4", 4 <= root.countNodes() );
 
-    List<ArtifactMetadata> res = mt.resolveConflicts( ArtifactScopeEnum.compile );
+    List<ArtifactMetadata> res = depBuilder.resolveConflicts( ArtifactScopeEnum.compile
);
+    
+    assertNotNull( res );
+    
+    assertTrue( res.size() > 1 );
     
-    assertNotNull( "null resolution", res );
+    System.out.println("\n---------------------------------\nclasspath: "+res);    
+    System.out.println("---------------------------------");    
+    for( ArtifactMetadata amd : res )
+    {
+      System.out.println(amd + ( amd.getTracker() == null ? " [no tracker]" : " ["+((RepositoryReader)amd.getTracker()).getRepository().getServer().toString()+"]"
) );
+    }
+    System.out.println("---------------------------------");    
 
-System.out.println("BigRes: "+res);    
     
 //    assertEquals( "wrong tree size", 3, res.size() );
     
 //    assertTrue( "no a:a:2 in the result", assertHasArtifact( res, "a:a:2" ) );
 //    assertTrue( "no b:b:1 in the result", assertHasArtifact( res, "b:b:1" ) );
 //    assertTrue( "no c:c:2 in the result", assertHasArtifact( res, "c:c:2" ) );
+    
+    
+    
+    ArtifactResults aRes = vReader.readArtifacts( res );
+    
+    assertNotNull( aRes );
+    
+    assertFalse( aRes.hasExceptions() );
+    
+    assertTrue( aRes.hasResults() );
+    
+    List<Artifact> artifacts = new ArrayList<Artifact>();
+    
+    for( ArtifactBasicMetadata abm : aRes.getResults().keySet() )
+      artifacts.addAll(  aRes.getResults(abm) );
+    
+    localRepo.getWriter().writeArtifacts( artifacts );
+    
+    System.out.println("Saved "+artifacts.size()+" artifacts to "+localRepo.getDirectory()
);
+    
   }
   //----------------------------------------------------------------------------------------------
   private static boolean assertHasArtifact( List<ArtifactMetadata> res, String gav
)

Modified: maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java?rev=707524&r1=707523&r2=707524&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java
(original)
+++ maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java
Thu Oct 23 18:58:41 2008
@@ -1,6 +1,7 @@
 package org.apache.maven.mercury.metadata;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
@@ -32,7 +33,7 @@
 {
   Language _lang = new DefaultLanguage(DependencyTreeBuilder.class);
   
-  private Set<MetadataTreeArtifactFilter> _filters;
+  private Collection<MetadataTreeArtifactFilter> _filters;
   private List<Comparator<MetadataTreeNode>> _comparators;
   private Map<String,ArtifactListProcessor> _processors;
   
@@ -55,7 +56,7 @@
    * @throws RepositoryException
    */
   public DependencyTreeBuilder(
-        Set<MetadataTreeArtifactFilter> filters
+        Collection<MetadataTreeArtifactFilter> filters
       , List<Comparator<MetadataTreeNode>> comparators
       , Map<String,ArtifactListProcessor> processors
       , List<Repository> repositories
@@ -224,7 +225,7 @@
     }
   }
   //-----------------------------------------------------
-  private boolean veto(ArtifactBasicMetadata md, Set<MetadataTreeArtifactFilter> filters
)
+  private boolean veto(ArtifactBasicMetadata md, Collection<MetadataTreeArtifactFilter>
filters )
   {
     if( filters != null && filters.size() > 1)
       for( MetadataTreeArtifactFilter filter : filters )

Modified: maven/mercury/trunk/mercury-repo/mercury-repo-virtual/src/main/java/org/apache/maven/mercury/repository/virtual/Messages.properties
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-virtual/src/main/java/org/apache/maven/mercury/repository/virtual/Messages.properties?rev=707524&r1=707523&r2=707524&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-virtual/src/main/java/org/apache/maven/mercury/repository/virtual/Messages.properties
(original)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-virtual/src/main/java/org/apache/maven/mercury/repository/virtual/Messages.properties
Thu Oct 23 18:58:41 2008
@@ -1,2 +1,3 @@
 error.reading.existing.artifact=Error {0} reading existing artifacts from repository {1}
-internal.error.sorting.query=internal error while sorting query {0} - buckets cannot be null

\ No newline at end of file
+internal.error.sorting.query=internal error while sorting query {0} - buckets cannot be null

+no.snapshots=cannot find snapshots for {0}, classifier {1}, type {2}
\ No newline at end of file

Modified: maven/mercury/trunk/mercury-repo/mercury-repo-virtual/src/main/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReader.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-virtual/src/main/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReader.java?rev=707524&r1=707523&r2=707524&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-virtual/src/main/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReader.java
(original)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-virtual/src/main/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReader.java
Thu Oct 23 18:58:41 2008
@@ -7,12 +7,17 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
+import java.util.TreeSet;
 
 import org.apache.maven.mercury.artifact.Artifact;
 import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
 import org.apache.maven.mercury.artifact.ArtifactMetadata;
+import org.apache.maven.mercury.artifact.Quality;
 import org.apache.maven.mercury.artifact.api.ArtifactListProcessor;
 import org.apache.maven.mercury.artifact.api.ArtifactListProcessorException;
+import org.apache.maven.mercury.artifact.version.MetadataVersionComparator;
+import org.apache.maven.mercury.artifact.version.VersionComparator;
 import org.apache.maven.mercury.builder.api.DependencyProcessor;
 import org.apache.maven.mercury.builder.api.MetadataReader;
 import org.apache.maven.mercury.builder.api.MetadataReaderException;
@@ -71,10 +76,11 @@
   throws RepositoryException
   {
     if( processor == null )
-      throw new RepositoryException( "null metadata processor" );
-    this._processor = processor;
+      this._processor = DependencyProcessor.NULL_PROCESSOR;
+    else
+      this._processor = processor;
 
-    if( repositories != null && repositories.size() > 0 )
+    if( ! Util.isEmpty( repositories ) )
       this._repositories.addAll( repositories );
   }
   //----------------------------------------------------------------------------------------------------------------------------
@@ -284,7 +290,7 @@
   /**
    * split query into repository buckets
    */
-  private Map< RepositoryReader, List<ArtifactBasicMetadata> > sortByRepo( Collection<ArtifactBasicMetadata>
query )
+  private Map< RepositoryReader, List<ArtifactBasicMetadata> > sortByRepo( Collection<?
extends ArtifactBasicMetadata> query )
   {
     HashMap< RepositoryReader, List<ArtifactBasicMetadata> > res = null;
     
@@ -335,7 +341,7 @@
     return res;
   }
   //----------------------------------------------------------------------------------------------------------------------------
-  public ArtifactResults readArtifacts( Collection<ArtifactBasicMetadata> query )
+  public ArtifactResults readArtifacts( Collection<? extends ArtifactBasicMetadata>
query )
   throws RepositoryException
   {
     ArtifactResults res = null;
@@ -417,6 +423,7 @@
   public byte[] readMetadata( ArtifactBasicMetadata bmd )
   throws MetadataReaderException
   {
+System.err.println("Asking for pom: "+bmd);
     return readRawData( bmd, "", "pom" );
   }
   //----------------------------------------------------------------------------------------------------------------------------
@@ -425,9 +432,16 @@
   public byte[] readRawData( ArtifactBasicMetadata bmd, String classifier, String type )
   throws MetadataReaderException
   {
+    
+    if( _log.isDebugEnabled() )
+      _log.debug( "request for "+bmd+", classifier="+classifier+", type="+type );
+System.err.println( "request for "+bmd+", classifier="+classifier+", type="+type );
+    
     if( bmd == null )
       throw new IllegalArgumentException("null bmd supplied");
     
+    ArtifactBasicMetadata bmdQuery = bmd;
+    
     try
     {
       init();
@@ -438,14 +452,71 @@
     }
     
     byte [] res = null;
+    Quality vq = new Quality( bmd.getVersion() );
+    
+    if( _log.isDebugEnabled() )
+      _log.debug( "quality calculated as "+vq.getQuality() == null ? "null" :vq.getQuality().name()
);
+System.err.println( "quality calculated as "+vq.getQuality() == null ? "null" :vq.getQuality().name()
);
+    
+    if( Quality.SNAPSHOT_QUALITY.equals( vq ) )
+    {
+      List<ArtifactBasicMetadata> query = new ArrayList<ArtifactBasicMetadata>(1);
+      query.add( bmd );
+      
+      try
+      {
+        ArtifactBasicResults vRes = readVersions( query );
+        if( Util.isEmpty( vRes ) )
+        {
+          if( _log.isDebugEnabled() )
+            _log.debug( "no snapshots found - throw exception" );
+System.err.println( "no snapshots found - throw exception" );
+          
+          throw new MetadataReaderException( _lang.getMessage( "no.snapshots", bmd.toString(),
classifier, type ) );
+        }
+          
+          
+        if( vRes.hasResults( bmd ) )
+        {
+          List<ArtifactBasicMetadata> versions = vRes.getResult( bmd );
+          
+          TreeSet<ArtifactBasicMetadata> snapshots = new TreeSet<ArtifactBasicMetadata>(
new MetadataVersionComparator() );
+          snapshots.addAll( versions );
+          
+          bmdQuery = snapshots.last();
+        }
+        else
+        {
+          if( _log.isDebugEnabled() )
+            _log.debug( "no snapshots found - throw exception" );
+System.err.println("no snapshots found - throw exception" );
+          
+          throw new MetadataReaderException( _lang.getMessage( "no.snapshots", bmd.toString(),
classifier, type ) );
+        }
+      }
+      catch( Exception e )
+      {
+        throw new MetadataReaderException(e);
+      }
+    }
     
     for( RepositoryReader rr : _repositoryReaders )
     {
-      res = rr.readRawData( bmd, classifier, type );
+      res = rr.readRawData( bmdQuery, classifier, type );
       if( res != null )
+      {
+        if( _log.isDebugEnabled() )
+          _log.debug( "data found in "+rr.getRepository().getServer()+", results shipped
back" );
+System.err.println( "data found in "+rr.getRepository().getServer()+", results shipped back"
);
+        
         return res;
+      }
     }
     
+    if( _log.isDebugEnabled() )
+      _log.debug( "no data found, returning null" );
+System.err.println( "no data found, returning null" );
+    
     return null;
   }
   //----------------------------------------------------------------------------------------------------------------------------

Modified: maven/mercury/trunk/mercury-transport/mercury-transport-api/src/main/java/org/apache/maven/mercury/transport/api/Server.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-transport/mercury-transport-api/src/main/java/org/apache/maven/mercury/transport/api/Server.java?rev=707524&r1=707523&r2=707524&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-transport/mercury-transport-api/src/main/java/org/apache/maven/mercury/transport/api/Server.java
(original)
+++ maven/mercury/trunk/mercury-transport/mercury-transport-api/src/main/java/org/apache/maven/mercury/transport/api/Server.java
Thu Oct 23 18:58:41 2008
@@ -229,4 +229,12 @@
     return requireTrustedServer;
   }
 
+  @Override
+  public String toString()
+  {
+    return id+": "+url;
+  }
+  
+  
+
 }



Mime
View raw message