You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by og...@apache.org on 2009/01/25 07:59:55 UTC

svn commit: r737485 - in /maven/mercury/trunk/mercury-repo: mercury-repo-local-m2/src/main/java/org/apache/maven/mercury/repository/local/m2/ mercury-repo-local-m2/src/test/java/org/apache/maven/mercury/repository/local/m2/ mercury-repo-remote-m2/src/m...

Author: ogusakov
Date: Sun Jan 25 06:59:55 2009
New Revision: 737485

URL: http://svn.apache.org/viewvc?rev=737485&view=rev
Log:
[MERCURY-78] fixed reading dependencies of a timestamped artifact

Modified:
    maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/main/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocation.java
    maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java
    maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/test/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocationtest.java
    maven/mercury/trunk/mercury-repo/mercury-repo-remote-m2/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java
    maven/mercury/trunk/mercury-repo/mercury-repo-virtual/src/main/java/org/apache/maven/mercury/repository/virtual/VirtualRepositoryReader.java

Modified: maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/main/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocation.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/main/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocation.java?rev=737485&r1=737484&r2=737485&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/main/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocation.java (original)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/main/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocation.java Sun Jan 25 06:59:55 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.maven.mercury.repository.local.m2;
 
+import org.apache.maven.mercury.artifact.Artifact;
 import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
 import org.apache.maven.mercury.artifact.version.DefaultArtifactVersion;
 import org.apache.maven.mercury.util.FileUtil;
@@ -87,9 +88,17 @@
     return getSeparatedPrefix() + getRelPomPath();
   }
   
+  public String getAbsGavPath()
+  {
+      if( prefix == null )
+          return null;
+
+    return getSeparatedPrefix() + getGavPath();
+  }
+  
   public String getGavPath()
   {
-    return getGaPath()+FileUtil.SEP+versionDir;
+    return getGaPath() + FileUtil.SEP + calculateVersionDir( version );
   }
   
   public String getBaseVersion()
@@ -101,7 +110,7 @@
     return dav.getBase();
   }
   
-  public String getVersionWithoutTS()
+  public String getVersionWithoutTS(  )
   {
     if( version == null )
       return null;
@@ -117,7 +126,35 @@
         return version.substring( 0, li2 );
     
     return version;
-        
+  }
+  
+  public static String stripTS( String ver  )
+  {
+    if( ver == null )
+      return null;
+    
+    int li = ver.lastIndexOf( '-' );
+    
+    if( li < 1 )
+        return ver;
+    
+    int li2 = ver.substring( 0, li ).lastIndexOf( '-' );
+    
+    if( li2 > 0 )
+        return ver.substring( 0, li2 );
+    
+    return ver;
+  }
+  //---------------------------------------------------------------------------------------------------------------
+  public static String calculateVersionDir( String ver )
+  {
+      if( ver == null )
+          return ver;
+      
+      if( ver.matches( ".+-\\d{8}\\.\\d{6}-\\d+" ) )
+          return stripTS( ver )+FileUtil.DASH+Artifact.SNAPSHOT_VERSION;
+      
+      return ver;
   }
   
   //---------------------------------------------------------
@@ -184,6 +221,7 @@
 
     return prefix+(prefix.endsWith( FileUtil.SEP ) ? "" : FileUtil.SEP);
   }
+
   public void setPrefix( String prefix )
   {
     this.prefix = prefix;

Modified: maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java?rev=737485&r1=737484&r2=737485&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java (original)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/main/java/org/apache/maven/mercury/repository/local/m2/LocalRepositoryReaderM2.java Sun Jan 25 06:59:55 2009
@@ -125,34 +125,35 @@
 
             File[] files = gaDir.listFiles();
 
-            // find latest
-            for ( File vf : files )
-            {
-                if ( vf.isFile() )
-                    continue;
-
-                String vn = vf.getName();
-
-                // RELEASE?
-                if ( noSnapshots && vn.endsWith( Artifact.SNAPSHOT_VERSION ) )
-                    continue;
-
-                if ( loc.getVersion() == null )
-                {
-                    loc.setVersion( vn );
-                    tempDav = new DefaultArtifactVersion( vn );
-                    continue;
-                }
-
-                tempDav2 = new DefaultArtifactVersion( vn );
-                if ( tempDav2.compareTo( tempDav ) > 0 )
-                {
-                    loc.setVersion( vn );
-                    tempDav = tempDav2;
+            if( files != null && files.length > 0 )
+                // find latest
+                for ( File vf : files )
+                {
+                    if ( vf.isFile() )
+                        continue;
+    
+                    String vn = vf.getName();
+    
+                    // RELEASE?
+                    if ( noSnapshots && vn.endsWith( Artifact.SNAPSHOT_VERSION ) )
+                        continue;
+    
+                    if ( loc.getVersion() == null )
+                    {
+                        loc.setVersion( vn );
+                        tempDav = new DefaultArtifactVersion( vn );
+                        continue;
+                    }
+    
+                    tempDav2 = new DefaultArtifactVersion( vn );
+                    if ( tempDav2.compareTo( tempDav ) > 0 )
+                    {
+                        loc.setVersion( vn );
+                        tempDav = tempDav2;
+                    }
+    
                 }
 
-            }
-
             if ( loc.getVersion() == null )
             {
 //                res.addError( bmd, new RepositoryException( LANG.getMessage( "gav.not.found", bmd.toString(),
@@ -378,7 +379,7 @@
         for ( ArtifactBasicMetadata bmd : query )
         {
             String pomPath =
-                bmd.getGroupId().replace( '.', '/' ) + "/" + bmd.getArtifactId() + "/" + bmd.getVersion() + "/"
+                bmd.getGroupId().replace( '.', '/' ) + "/" + bmd.getArtifactId() + "/" + ArtifactLocation.calculateVersionDir( bmd.getVersion() ) + "/"
                     + bmd.getArtifactId() + '-' + bmd.getVersion() + ".pom";
 
             pomFile = new File( _repoDir, pomPath );
@@ -421,7 +422,7 @@
             return true;
 
         // no real SNAPSHOT file, let's try to find one
-        File gavDir = new File( loc.getGavPath() );
+        File gavDir = new File( loc.getAbsGavPath() );
         File[] files = gavDir.listFiles();
         loc.setVersion( null );
         DefaultArtifactVersion tempDav = null;
@@ -429,34 +430,35 @@
 
         int aLen = loc.getBaseName().length();
 
-        // find latest
-        for ( File vf : files )
-        {
-            if ( vf.isFile() )
-                continue;
-
-            String vn = vf.getName().substring( aLen + 1 );
-
-            // no snapshots
-            if ( vn.endsWith( Artifact.SNAPSHOT_VERSION ) )
-                continue;
-
-            if ( loc.getVersion() == null )
-            {
-                loc.setVersion( vn );
-                tempDav = new DefaultArtifactVersion( vn );
-                continue;
-            }
-
-            tempDav2 = new DefaultArtifactVersion( vn );
-            if ( tempDav2.compareTo( tempDav ) > 0 )
+        if( files != null && files.length > 0 )
+            // find latest
+            for ( File vf : files )
             {
-                loc.setVersion( vn );
-                tempDav = tempDav2;
+                if ( vf.isFile() )
+                    continue;
+    
+                String vn = vf.getName().substring( aLen + 1 );
+    
+                // no snapshots
+                if ( vn.endsWith( Artifact.SNAPSHOT_VERSION ) )
+                    continue;
+    
+                if ( loc.getVersion() == null )
+                {
+                    loc.setVersion( vn );
+                    tempDav = new DefaultArtifactVersion( vn );
+                    continue;
+                }
+    
+                tempDav2 = new DefaultArtifactVersion( vn );
+                if ( tempDav2.compareTo( tempDav ) > 0 )
+                {
+                    loc.setVersion( vn );
+                    tempDav = tempDav2;
+                }
+    
             }
 
-        }
-
         if ( loc.getVersion() == null )
         {
 //            res.addError( bmd, new RepositoryException( LANG.getMessage( "snapshot.not.found", bmd.toString(),
@@ -556,24 +558,19 @@
     public byte[] readRawData( ArtifactBasicMetadata bmd, String classifier, String type )
         throws MetadataReaderException
     {
-        return readRawData( relPathOf( bmd, classifier, type, null ) );
+        return readRawData( relPathOf( bmd, classifier, type ) );
     }
 
     // ---------------------------------------------------------------------------------------------------------------
-    private static String relPathOf( ArtifactBasicMetadata bmd, String classifier, String type,
-                                     DefaultArtifactVersion inDav )
+    private static String relPathOf( ArtifactBasicMetadata bmd, String classifier, String type )
     {
-        DefaultArtifactVersion dav = inDav;
-        if ( inDav == null )
-            dav = new DefaultArtifactVersion( bmd.getVersion() );
-        Quality aq = dav.getQuality();
-        boolean isSnapshot = aq.equals( Quality.SNAPSHOT_QUALITY ) || aq.equals( Quality.SNAPSHOT_TS_QUALITY );
-
         String bmdPath =
-            bmd.getGroupId().replace( '.', '/' ) + '/' + bmd.getArtifactId() + '/'
-                + ( isSnapshot ? dav.getBase() + '-' + Artifact.SNAPSHOT_VERSION : bmd.getVersion() );
+            bmd.getGroupId().replace( '.', '/' ) + '/' + bmd.getArtifactId() + '/' + ArtifactLocation.calculateVersionDir( bmd.getVersion() );
 
         String path = bmdPath + '/' + bmd.getBaseName( classifier ) + '.' + ( type == null ? bmd.getType() : type );
+        
+if( LOG.isDebugEnabled() )
+    LOG.debug( bmd.toString()+" path is "+ path);
 
         return path;
     }

Modified: maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/test/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocationtest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/test/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocationtest.java?rev=737485&r1=737484&r2=737485&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/test/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocationtest.java (original)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-local-m2/src/test/java/org/apache/maven/mercury/repository/local/m2/ArtifactLocationtest.java Sun Jan 25 06:59:55 2009
@@ -62,6 +62,35 @@
         
         assertEquals( "3.0-20080920.0156007", chop );
     }
+    
+    public void testChopTSstatic()
+    throws Exception
+    {
+        String chop = ArtifactLocation.calculateVersionDir( "3.0-alpha-1-20080920.015600-7" );
+        
+        assertEquals( "3.0-alpha-1-SNAPSHOT", chop );
+
+        
+        chop = ArtifactLocation.calculateVersionDir( "3.0-20080920.015600-7" );
+        
+        assertEquals( "3.0-SNAPSHOT", chop );
+        
+
+        chop = ArtifactLocation.calculateVersionDir( "3.0-20080920.01560-7" );
+        
+        assertEquals( "3.0-20080920.01560-7", chop );
+
+        
+        chop = ArtifactLocation.calculateVersionDir( "3.0-20080920.015600" );
+        
+        assertEquals( "3.0-20080920.015600", chop );
+
+        
+        chop = ArtifactLocation.calculateVersionDir( "3.0" );
+        
+        assertEquals( "3.0", chop );
+
+    }
 
 
 }

Modified: maven/mercury/trunk/mercury-repo/mercury-repo-remote-m2/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-repo/mercury-repo-remote-m2/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java?rev=737485&r1=737484&r2=737485&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-repo/mercury-repo-remote-m2/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java (original)
+++ maven/mercury/trunk/mercury-repo/mercury-repo-remote-m2/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java Sun Jan 25 06:59:55 2009
@@ -617,7 +617,7 @@
       mod = new ArtifactBasicMetadata();
       mod.setGroupId( bmd.getGroupId() );
       mod.setArtifactId( bmd.getArtifactId() );
-      mod.setVersion( bmd.getVersion() );
+      mod.setVersion( ArtifactLocation.calculateVersionDir( bmd.getVersion() ) );
       mod.setClassifier( classifier );
       mod.setType( type );
 
@@ -626,8 +626,8 @@
         res = _mdCache.findRaw( mod );
         if( res != null )
         {
-//if( _log.isDebugEnabled() )
-//  _log.debug( "found "+bmd+" in the cache" );
+if( LOG.isDebugEnabled() )
+  LOG.debug( "found "+bmd+" in the cache" );
           return res;
         }
       }
@@ -638,12 +638,23 @@
       }
     }
     
+    mod = new ArtifactBasicMetadata( bmd.getGroupId()+":"+bmd.getArtifactId()+":"+bmd.getVersion()
+                                     +":" + (classifier==null?"":classifier)
+                                     +":" + (type == null ? bmd.getType() : type )
+                                     );
+    
+//    ArtifactLocation loc = new ArtifactLocation( "", mod );
+    
+//    String bmdPath = loc.getAbsPath();
+    
     String bmdPath = bmd.getGroupId().replace( '.', '/' )
                     + '/'+bmd.getArtifactId()
                     + '/'+bmd.getVersion()
                     + '/'+bmd.getBaseName(classifier)
                     + '.' + (type == null ? bmd.getType() : type )
                     ;
+if( LOG.isDebugEnabled() )
+    LOG.debug( "calculated raw path as "+bmdPath );
     
     res = readRawData( bmdPath );
     

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=737485&r1=737484&r2=737485&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 Sun Jan 25 06:59:55 2009
@@ -96,9 +96,9 @@
     /** minimum # of queue elements to consider parallelization */
     private static int MIN_PARALLEL = 5;
 
-    private static final Language _lang = new DefaultLanguage( VirtualRepositoryReader.class );
+    private static final Language LANG = new DefaultLanguage( VirtualRepositoryReader.class );
 
-    private static final IMercuryLogger _log = MercuryLoggerManager.getLogger( VirtualRepositoryReader.class );
+    private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( VirtualRepositoryReader.class );
 
     // ----------------------------------------------------------------------------------------------------------------------------
     private List<Repository> _repositories = new ArrayList<Repository>( 8 );
@@ -284,8 +284,8 @@
                     
                     if( repoRes != null && repoRes.hasExceptions() )
                     {
-                        if( _log.isWarnEnabled() )
-                            _log.warn( repoRes.getExceptions().toString() );
+                        if( LOG.isWarnEnabled() )
+                            LOG.warn( repoRes.getExceptions().toString() );
                     }
 
                     if ( repoRes != null && repoRes.hasResults() )
@@ -329,7 +329,7 @@
                             }
                             catch ( VersionException e )
                             {
-                                throw new RepositoryException( _lang.getMessage( "query.element.bad.version",
+                                throw new RepositoryException( LANG.getMessage( "query.element.bad.version",
                                                                                  key.toString(), e.getMessage() ) );
                             }
 
@@ -420,6 +420,9 @@
 
                         if ( _eventManager != null )
                             eventRead.setInfo( eventRead.getInfo() + ", found: " + md.getDependencies() );
+                        
+                        if( LOG.isDebugEnabled() )
+                            LOG.debug( bmd+" dependecies found : " + md.getDependencies() );
 
                         return md;
                     }
@@ -524,7 +527,7 @@
             List<ArtifactBasicMetadata> rejects = buckets == null ? null : buckets.get( RepositoryReader.NULL_READER );
 
             if ( buckets == null )
-                throw new RepositoryException( _lang.getMessage( "internal.error.sorting.query", query.toString() ) );
+                throw new RepositoryException( LANG.getMessage( "internal.error.sorting.query", query.toString() ) );
 
             init();
 
@@ -552,7 +555,7 @@
                     ArtifactResults rrRes = rr.readArtifacts( rrQuery );
 
                     if ( rrRes.hasExceptions() )
-                        throw new RepositoryException( _lang.getMessage( "error.reading.existing.artifact",
+                        throw new RepositoryException( LANG.getMessage( "error.reading.existing.artifact",
                                                                          rrRes.getExceptions().toString(),
                                                                          rr.getRepository().getId() ) );
 
@@ -655,8 +658,8 @@
     public byte[] readMetadata( ArtifactBasicMetadata bmd )
         throws MetadataReaderException
     {
-        if ( _log.isDebugEnabled() )
-            _log.debug( "Asking for pom: " + bmd );
+        if ( LOG.isDebugEnabled() )
+            LOG.debug( "Asking for pom: " + bmd );
 
         return readRawData( bmd, "", "pom" );
     }
@@ -671,8 +674,8 @@
         GenericEvent event = null;
         String eventTag = null;
 
-        if ( _log.isDebugEnabled() )
-            _log.debug( "request for " + bmd + ", classifier=" + classifier + ", type=" + type );
+        if ( LOG.isDebugEnabled() )
+            LOG.debug( "request for " + bmd + ", classifier=" + classifier + ", type=" + type );
 
         if ( bmd == null )
             throw new IllegalArgumentException( "null bmd supplied" );
@@ -701,8 +704,8 @@
             byte[] res = null;
             Quality vq = new Quality( bmd.getVersion() );
 
-            if ( _log.isDebugEnabled() )
-                _log.debug( "quality calculated as " + vq.getQuality() == null ? "null" : vq.getQuality().name() );
+            if ( LOG.isDebugEnabled() )
+                LOG.debug( "quality calculated as " + vq.getQuality() == null ? "null" : vq.getQuality().name() );
 
             if ( Quality.SNAPSHOT_QUALITY.equals( vq ) )
             {
@@ -714,10 +717,10 @@
                     ArtifactBasicResults vRes = readVersions( query );
                     if ( Util.isEmpty( vRes ) )
                     {
-                        if ( _log.isDebugEnabled() )
-                            _log.debug( "no snapshots found - throw exception" );
+                        if ( LOG.isDebugEnabled() )
+                            LOG.debug( "no snapshots found - throw exception" );
 
-                        throw new MetadataReaderException( _lang.getMessage( "no.snapshots", bmd.toString(),
+                        throw new MetadataReaderException( LANG.getMessage( "no.snapshots", bmd.toString(),
                                                                              classifier, type ) );
                     }
 
@@ -733,10 +736,10 @@
                     }
                     else
                     {
-                        if ( _log.isDebugEnabled() )
-                            _log.debug( "no snapshots found - throw exception" );
+                        if ( LOG.isDebugEnabled() )
+                            LOG.debug( "no snapshots found - throw exception" );
 
-                        throw new MetadataReaderException( _lang.getMessage( "no.snapshots", bmd.toString(),
+                        throw new MetadataReaderException( LANG.getMessage( "no.snapshots", bmd.toString(),
                                                                              classifier, type ) );
                     }
                 }
@@ -760,8 +763,8 @@
                     res = rr.readRawData( bmdQuery, classifier, type );
                     if ( res != null )
                     {
-                        if ( _log.isDebugEnabled() )
-                            _log.debug( bmdQuery + " found in " + rr.getRepository().getServer() );
+                        if ( LOG.isDebugEnabled() )
+                            LOG.debug( bmdQuery + " found in " + rr.getRepository().getServer() );
 
                         if ( _eventManager != null )
                             eventRead.setInfo( eventRead.getInfo() );
@@ -782,8 +785,8 @@
                 }
             }
 
-            if ( _log.isDebugEnabled() )
-                _log.debug( "no data found, returning null" );
+            if ( LOG.isDebugEnabled() )
+                LOG.debug( "no data found, returning null" );
 
             return null;
         }