maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ogusa...@apache.org
Subject svn commit: r741460 - in /maven/mercury/trunk: mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/ mercury-repo/mercury-repo-local-m2/src/main/java/org/apache/maven/mercury/repository/local/m2/ mercury-repo/mercury-repo-remote-m2/src/ma...
Date Fri, 06 Feb 2009 07:40:17 GMT
Author: ogusakov
Date: Fri Feb  6 07:40:16 2009
New Revision: 741460

URL: http://svn.apache.org/viewvc?rev=741460&view=rev
Log:
[MERCURY-89] optimized local repository impl by switching to File APIs

Modified:
    maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/ComprehensiveRepositoryTest.java
    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-remote-m2/src/main/java/org/apache/maven/mercury/repository/remote/m2/RemoteRepositoryReaderM2.java

Modified: maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/ComprehensiveRepositoryTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/ComprehensiveRepositoryTest.java?rev=741460&r1=741459&r2=741460&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/ComprehensiveRepositoryTest.java
(original)
+++ maven/mercury/trunk/mercury-it/src/test/java/org/apache/maven/mercury/repository/tests/ComprehensiveRepositoryTest.java
Fri Feb  6 07:40:16 2009
@@ -348,6 +348,31 @@
         assertFalse( localRepo2Jar.exists() );
     }
     
+    public void testWriteReadSnapshotLocal()
+    throws Exception
+    {
+        String name = "org.apache.maven:maven-core:2.0.9-SNAPSHOT";
+        
+        File af = new File( _resourceBase, "maven-core-2.0.9.jar" );
+        File ap = new File( _resourceBase, "maven-core-2.0.9.pom" );
+        
+        File aJar1 = new File( _lbase1, "org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-SNAPSHOT.jar");
+        File aJar2 = new File( _lbase2, "org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-SNAPSHOT.jar");
+        
+        assertFalse( aJar1.exists() );
+        assertFalse( aJar2.exists() );
+        
+        writeArtifact( name, af, ap, _lr2 );
+        
+        assertFalse( aJar1.exists() );
+        assertTrue( aJar2.exists() );
+        
+        List<Artifact> al = readArtifact( name, _lrs );
+
+        assertTrue( aJar1.exists() );
+        assertTrue( aJar2.exists() );
+    }
+    
     public void testWriteTimestampReadSnapshotSingleRepo()
     throws Exception
     {
@@ -359,6 +384,75 @@
         File ap = new File( _resourceBase, "maven-core-2.0.9.pom" );
         
         writeArtifact( nameTS1, af, ap, _rr2 );
+        writeArtifact( nameTS2, af, ap, _rr2 );
+        
+        List<Artifact> al = readArtifact( nameSN, _rrs );
+        
+        System.out.println(al);
+        
+        assertNotNull( al );
+        
+        assertEquals( 1, al.size() );
+        
+        Artifact aSN = al.get( 0 );
+        
+        assertNotNull( aSN.getFile() );
+        
+        assertTrue( aSN.getFile().exists() );
+        
+        assertEquals( "2.0.9-20090204.232324-24", aSN.getVersion() );
+    }
+    
+    public void testWriteTimestampReadSnapshotSingleRepoSN()
+    throws Exception
+    {
+        String nameTS1 = "org.apache.maven:maven-core:2.0.9-20090204.232323-23";
+        String nameTS2 = "org.apache.maven:maven-core:2.0.9-20090204.232324-24";
+        String nameSN = "org.apache.maven:maven-core:2.0.9-SNAPSHOT";
+        
+        File af = new File( _resourceBase, "maven-core-2.0.9.jar" );
+        File ap = new File( _resourceBase, "maven-core-2.0.9.pom" );
+        
+        writeArtifact( nameTS1, af, ap, _rr2 );
+        writeArtifact( nameTS2, af, ap, _rr2 );
+        writeArtifact( nameSN, af, ap, _rr2 );
+        
+        List<ArtifactBasicMetadata> vl = readVersions( nameSN, _rrs );
+        
+        System.out.println(vl);
+        
+        assertNotNull( vl );
+        
+        assertEquals( 1, vl.size() );
+        
+        List<Artifact> al = readArtifact( nameSN, _rrs );
+        
+        System.out.println(al);
+        
+        assertNotNull( al );
+        
+        assertEquals( 1, al.size() );
+        
+        Artifact aSN = al.get( 0 );
+        
+        assertNotNull( aSN.getFile() );
+        
+        assertTrue( aSN.getFile().exists() );
+        
+        assertEquals( "2.0.9-SNAPSHOT", aSN.getVersion() );
+    }
+    
+    public void testWriteTimestampReadSnapshot2Repos()
+    throws Exception
+    {
+        String nameTS1 = "org.apache.maven:maven-core:2.0.9-20090204.232323-23";
+        String nameTS2 = "org.apache.maven:maven-core:2.0.9-20090204.232324-24";
+        String nameSN = "org.apache.maven:maven-core:2.0.9-SNAPSHOT";
+        
+        File af = new File( _resourceBase, "maven-core-2.0.9.jar" );
+        File ap = new File( _resourceBase, "maven-core-2.0.9.pom" );
+        
+        writeArtifact( nameTS1, af, ap, _rr2 );
         writeArtifact( nameTS2, af, ap, _rr1 );
         
         List<ArtifactBasicMetadata> vl = readVersions( nameSN, _rrs );
@@ -382,5 +476,173 @@
         assertNotNull( aSN.getFile() );
         
         assertTrue( aSN.getFile().exists() );
+        
+        assertEquals( "2.0.9-20090204.232324-24", aSN.getVersion() );
+    }
+    
+    public void testWriteTimestampReadSnapshot2ReposReversed()
+    throws Exception
+    {
+        String nameTS1 = "org.apache.maven:maven-core:2.0.9-20090204.232323-23";
+        String nameTS2 = "org.apache.maven:maven-core:2.0.9-20090204.232324-24";
+        String nameSN = "org.apache.maven:maven-core:2.0.9-SNAPSHOT";
+        
+        File af = new File( _resourceBase, "maven-core-2.0.9.jar" );
+        File ap = new File( _resourceBase, "maven-core-2.0.9.pom" );
+        
+        writeArtifact( nameTS1, af, ap, _rr1 );
+        writeArtifact( nameTS2, af, ap, _rr2 );
+        
+        List<ArtifactBasicMetadata> vl = readVersions( nameSN, _rrs );
+        
+        System.out.println(vl);
+        
+        assertNotNull( vl );
+        
+        assertEquals( 1, vl.size() );
+        
+        List<Artifact> al = readArtifact( nameSN, _rrs );
+        
+        System.out.println(al);
+        
+        assertNotNull( al );
+        
+        assertEquals( 1, al.size() );
+        
+        Artifact aSN = al.get( 0 );
+        
+        assertNotNull( aSN.getFile() );
+        
+        assertTrue( aSN.getFile().exists() );
+        
+        assertEquals( "2.0.9-20090204.232324-24", aSN.getVersion() );
+    }
+    
+    public void testLatest()
+    throws Exception
+    {
+        String nameTS1 = "org.apache.maven:maven-core:2.0.9-20090204.232323-23";
+        String nameTS2 = "org.apache.maven:maven-core:2.0.9-20090204.232324-24";
+        String nameRL = "org.apache.maven:maven-core:2.0.8";
+        String nameLT = "org.apache.maven:maven-core:LATEST";
+        
+        File af = new File( _resourceBase, "maven-core-2.0.9.jar" );
+        File ap = new File( _resourceBase, "maven-core-2.0.9.pom" );
+        
+        writeArtifact( nameTS1, af, ap, _rr2 );
+        writeArtifact( nameTS2, af, ap, _rr1 );
+        writeArtifact( nameRL, af, ap, _rr2 );
+        
+        List<Artifact> al = readArtifact( nameLT, _rrs );
+        
+        System.out.println(al);
+        
+        assertNotNull( al );
+        
+        assertEquals( 1, al.size() );
+        
+        Artifact aSN = al.get( 0 );
+        
+        assertNotNull( aSN.getFile() );
+        
+        assertTrue( aSN.getFile().exists() );
+        
+        assertEquals( "2.0.9-20090204.232324-24", aSN.getVersion() );
+    }
+    
+    public void testLatestLocal()
+    throws Exception
+    {
+        String nameTS1 = "org.apache.maven:maven-core:2.0.9-20090204.232323-23";
+        String nameTS2 = "org.apache.maven:maven-core:2.0.9-20090204.232324-24";
+        String nameRL = "org.apache.maven:maven-core:2.0.8";
+        String nameLT = "org.apache.maven:maven-core:LATEST";
+        
+        File af = new File( _resourceBase, "maven-core-2.0.9.jar" );
+        File ap = new File( _resourceBase, "maven-core-2.0.9.pom" );
+        
+        writeArtifact( nameTS1, af, ap, _lr2 );
+        writeArtifact( nameTS2, af, ap, _lr1 );
+        writeArtifact( nameRL, af, ap, _lr2 );
+        
+        List<Artifact> al = readArtifact( nameLT, _lrs );
+        
+        System.out.println(al);
+        
+        assertNotNull( al );
+        
+        assertEquals( 1, al.size() );
+        
+        Artifact aSN = al.get( 0 );
+        
+        assertNotNull( aSN.getFile() );
+        
+        assertTrue( aSN.getFile().exists() );
+        
+        assertEquals( "2.0.9-20090204.232324-24", aSN.getVersion() );
+    }
+    
+    public void testRelease()
+    throws Exception
+    {
+        String nameTS1 = "org.apache.maven:maven-core:2.0.9-20090204.232323-23";
+        String nameTS2 = "org.apache.maven:maven-core:2.0.9-20090204.232324-24";
+        String nameRL = "org.apache.maven:maven-core:2.0.8";
+        String name = "org.apache.maven:maven-core:RELEASE";
+        
+        File af = new File( _resourceBase, "maven-core-2.0.9.jar" );
+        File ap = new File( _resourceBase, "maven-core-2.0.9.pom" );
+        
+        writeArtifact( nameTS1, af, ap, _rr2 );
+        writeArtifact( nameTS2, af, ap, _rr1 );
+        writeArtifact( nameRL, af, ap, _rr2 );
+        
+        List<Artifact> al = readArtifact( name, _rrs );
+        
+        System.out.println(al);
+        
+        assertNotNull( al );
+        
+        assertEquals( 1, al.size() );
+        
+        Artifact aSN = al.get( 0 );
+        
+        assertNotNull( aSN.getFile() );
+        
+        assertTrue( aSN.getFile().exists() );
+        
+        assertEquals( "2.0.8", aSN.getVersion() );
+    }
+    
+    public void testReleaseLocal()
+    throws Exception
+    {
+        String nameTS1 = "org.apache.maven:maven-core:2.0.9-20090204.232323-23";
+        String nameTS2 = "org.apache.maven:maven-core:2.0.9-20090204.232324-24";
+        String nameRL = "org.apache.maven:maven-core:2.0.8";
+        String name = "org.apache.maven:maven-core:RELEASE";
+        
+        File af = new File( _resourceBase, "maven-core-2.0.9.jar" );
+        File ap = new File( _resourceBase, "maven-core-2.0.9.pom" );
+        
+        writeArtifact( nameTS1, af, ap, _lr2 );
+        writeArtifact( nameTS2, af, ap, _lr1 );
+        writeArtifact( nameRL, af, ap, _lr2 );
+        
+        List<Artifact> al = readArtifact( name, _lrs );
+        
+        System.out.println(al);
+        
+        assertNotNull( al );
+        
+        assertEquals( 1, al.size() );
+        
+        Artifact aSN = al.get( 0 );
+        
+        assertNotNull( aSN.getFile() );
+        
+        assertTrue( aSN.getFile().exists() );
+        
+        assertEquals( "2.0.8", aSN.getVersion() );
     }
 }

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=741460&r1=741459&r2=741460&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
Fri Feb  6 07:40:16 2009
@@ -145,6 +145,24 @@
     
     return ver;
   }
+  
+  public static String getTS( 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( li2+1 );
+    
+    return ver;
+  }
   //---------------------------------------------------------------------------------------------------------------
   public static String calculateVersionDir( String ver )
   {

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=741460&r1=741459&r2=741460&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
Fri Feb  6 07:40:16 2009
@@ -19,18 +19,22 @@
 package org.apache.maven.mercury.repository.local.m2;
 
 import java.io.File;
+import java.io.FileFilter;
 import java.io.FileInputStream;
+import java.io.FilenameFilter;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.TreeSet;
 
 import org.apache.maven.mercury.artifact.Artifact;
 import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
 import org.apache.maven.mercury.artifact.DefaultArtifact;
 import org.apache.maven.mercury.artifact.Quality;
 import org.apache.maven.mercury.artifact.version.DefaultArtifactVersion;
+import org.apache.maven.mercury.artifact.version.VersionComparator;
 import org.apache.maven.mercury.artifact.version.VersionException;
 import org.apache.maven.mercury.artifact.version.VersionRange;
 import org.apache.maven.mercury.artifact.version.VersionRangeFactory;
@@ -118,46 +122,34 @@
         // RELEASE = LATEST - SNAPSHOTs
         if ( Artifact.RELEASE_VERSION.equals( loc.getVersion() ) || Artifact.LATEST_VERSION.equals(
loc.getVersion() ) )
         {
-            boolean noSnapshots = Artifact.RELEASE_VERSION.equals( loc.getVersion() );
+            final boolean noSnapshots = Artifact.RELEASE_VERSION.equals( loc.getVersion()
);
             loc.setVersion( null );
-            DefaultArtifactVersion tempDav = null;
-            DefaultArtifactVersion tempDav2 = null;
+            
+            final TreeSet<String> ts = new TreeSet<String>( new VersionComparator()
);
 
-            File[] files = gaDir.listFiles();
-
-            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 )
+            gaDir.listFiles(
+                     new FilenameFilter()
+                     {
+                        public boolean accept( File dir, String name )
+                        {   
+                            if( new File(dir,name).isDirectory() )
+                            {
+                                if( noSnapshots && name.endsWith( Artifact.SNAPSHOT_VERSION
) )
+                                    return false;
+                                
+                                ts.add( name );
+                                return true;
+                            }
+                            return false;
+                        }
+                         
+                     }
+                           );
+            
+            if( !ts.isEmpty() )
+                loc.setVersion( ts.last() );
+            else
             {
-//                res.addError( bmd, new RepositoryException( LANG.getMessage( "gav.not.found",
bmd.toString(),
-//                                                                             loc.getGaPath()
) ) );
                 if( LOG.isErrorEnabled() )
                     LOG.error( LANG.getMessage( "gav.not.found", bmd.toString(), loc.getGaPath()
) );
                 return null;
@@ -414,7 +406,7 @@
     }
 
     // ---------------------------------------------------------------------------------------------------------------
-    private static boolean findLatestSnapshot( ArtifactBasicMetadata bmd, ArtifactLocation
loc, AbstractRepOpResult res )
+    private static boolean findLatestSnapshot( ArtifactBasicMetadata bmd, final ArtifactLocation
loc, AbstractRepOpResult res )
     {
         File binary = new File( loc.getAbsPath() );
 
@@ -423,51 +415,41 @@
 
         // no real SNAPSHOT file, let's try to find one
         File gavDir = new File( loc.getAbsGavPath() );
-        File[] files = gavDir.listFiles();
-        loc.setVersion( null );
-        DefaultArtifactVersion tempDav = null;
-        DefaultArtifactVersion tempDav2 = null;
-
-        int aLen = loc.getBaseName().length();
-
-        if( files != null && files.length > 0 )
-            // 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 )
-                {
-                    loc.setVersion( vn );
-                    tempDav = tempDav2;
-                }
-    
-            }
-
-        if ( loc.getVersion() == null )
+        
+        final String regEx = Artifact.SNAPSHOT_TS_REGEX+"\\."+bmd.getCheckedType();
+        
+        final TreeSet<String> ts = new TreeSet<String>( new VersionComparator()
);
+        
+        File[] files = gavDir.listFiles( new FilenameFilter()
+                                        {
+                                            public boolean accept( File dir, String name
)
+                                            {
+                                                if( name.matches( regEx ) )
+                                                {
+                                                    int pos = loc.getBaseName().length();
+                                                    
+                                                    String ver = name.substring( pos+1, name.lastIndexOf(
'.' ) );
+                                                    
+                                                    ts.add( ver );
+                                                    
+                                                    return true;
+                                                }
+
+                                                return false;
+                                            }
+                                            
+                                        }
+                                      );
+        
+        if( ts.isEmpty() )
         {
-//            res.addError( bmd, new RepositoryException( LANG.getMessage( "snapshot.not.found",
bmd.toString(),
-//                                                                         gavDir.getAbsolutePath()
) ) );
             if( LOG.isErrorEnabled() )
                 LOG.error( LANG.getMessage( "snapshot.not.found", bmd.toString(), gavDir.getAbsolutePath()
)  );
-                
+            
             return false;
         }
+        
+        loc.setVersion( ts.last() );
 
         return true;
     }

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=741460&r1=741459&r2=741460&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
Fri Feb  6 07:40:16 2009
@@ -498,11 +498,18 @@
     
     gam.getVersions().clear();
     
+    boolean requestRelease = bmd.getVersion().endsWith( Artifact.RELEASE_VERSION );
+    // GA metadata version scan
     for( String v : vRes )
     {
         String toAdd;
         
-        if( v.endsWith( Artifact.SNAPSHOT_VERSION )  )
+        boolean foundSnapshot = v.endsWith( Artifact.SNAPSHOT_VERSION );
+        
+        if( requestRelease && foundSnapshot )
+            continue;
+        
+        if( foundSnapshot )
         {
             boolean snFound = false;
             ArtifactBasicMetadata snMd = new ArtifactBasicMetadata( bmd.toString() );



Mime
View raw message