]> source.dussan.org Git - archiva.git/commitdiff
[MRM-576]
authorMaria Odea B. Ching <oching@apache.org>
Wed, 7 Nov 2007 09:02:58 +0000 (09:02 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Wed, 7 Nov 2007 09:02:58 +0000 (09:02 +0000)
- modified logic for deleting released snapshots, delete only if there exists a released version of that snapshot not when there is a
higher released/snapshot version
- adjusted tests

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@592657 13f79535-47bb-0310-9956-ffa450edef68

archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/VersionUtil.java
archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java
archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java

index 07aadf6746908fcb9baaa728f9e2c8d094ca9ca3..7ac85e2ac89fdd2cc10638814edaf5fa1875a30a 100644 (file)
@@ -65,6 +65,8 @@ public class VersionUtil
 
     public static final Pattern TIMESTAMP_PATTERN = Pattern.compile( "^([0-9]{8})\\.([0-9]{6})$" );
 
+    public static final Pattern GENERIC_SNAPSHOT_PATTERN = Pattern.compile( "^(.*)-" + SNAPSHOT );
+    
     /**
      * <p>
      * Tests if the unknown string contains elements that identify it as a version string (or not).
@@ -153,6 +155,38 @@ public class VersionUtil
             return version;
         }
     }
+    
+    /**
+     * <p>
+     * Get the release version of the snapshot version.
+     * </p>
+     * 
+     * <p>
+     * If snapshot version is 1.0-SNAPSHOT, then release version would be 1.0
+     * And if snapshot version is 1.0-20070113.163208-1.jar, then release version would still be 1.0
+     * </p>
+     * 
+     * @param snapshotVersion
+     * @return
+     */
+    public static String getReleaseVersion( String snapshotVersion )
+    {
+        Matcher m = UNIQUE_SNAPSHOT_PATTERN.matcher( snapshotVersion );
+        
+        if( isGenericSnapshot( snapshotVersion ) )
+        {
+            m = GENERIC_SNAPSHOT_PATTERN.matcher( snapshotVersion );
+        }
+                
+        if ( m.matches() )
+        {   
+            return m.group( 1 );
+        }
+        else
+        {        
+            return snapshotVersion;
+        }
+    }
 
     public static boolean isUniqueSnapshot( String version )
     {             
index cfe735861b20881a654f48e3dbb4e3bd957a2688..06654242401905f558d8af015b5223b4da08ded3 100644 (file)
@@ -133,17 +133,17 @@ public class CleanupReleasedSnapshotsRepositoryPurge
             VersionedReference versionRef = new VersionedReference();
             versionRef.setGroupId( artifact.getGroupId() );
             versionRef.setArtifactId( artifact.getArtifactId() );
-
+            
             for ( String version : snapshotVersions )
-            {
-                if ( VersionComparator.getInstance().compare( version, highestReleasedVersion ) < 0 )
+            {   
+                if( releasedVersions.contains( VersionUtil.getReleaseVersion( version ) ) )
                 {
                     versionRef.setVersion( version );
                     repository.deleteVersion( versionRef );
                     needsMetadataUpdate = true;
                 }
-            }
-
+            }           
+                        
             if ( needsMetadataUpdate )
             {
                 updateMetadata( artifact );
index a775a6233b2fae6fe946e842e8ba605e6a6cee90..55f53bf3c58d44aafd5836efcf58b6a5b2199096 100644 (file)
@@ -88,7 +88,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
 
         // check if metadata file was updated
         File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" );
-
+        
         String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null );
         
         String expectedVersions = "<expected><versions><version>2.2</version>" +
@@ -111,15 +111,15 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
         repoPurge.process( PATH_TO_HIGHER_SNAPSHOT_EXISTS );
         
         String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-source-plugin";
-
-        // check if the snapshot was removed
-        assertDeleted( projectRoot + "/2.0.3-SNAPSHOT" );
-        assertDeleted( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar" );
-        assertDeleted( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.md5" );
-        assertDeleted( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.sha1" );
-        assertDeleted( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom" );
-        assertDeleted( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.md5" );
-        assertDeleted( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.sha1" );
+        
+        // check if the snapshot was not removed
+        assertExists( projectRoot + "/2.0.3-SNAPSHOT" );
+        assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar" );
+        assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.md5" );
+        assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.sha1" );
+        assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom" );
+        assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.md5" );
+        assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.sha1" );
 
         // check if the released version was not removed
         assertExists( projectRoot + "/2.0.4-SNAPSHOT" );
@@ -130,12 +130,12 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
         assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.md5" );
         assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.sha1" );
 
-        // check if metadata file was updated
+        // check if metadata file was not updated (because nothing was removed)
         File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" );
 
         String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null );
         
-        String expectedVersions = "<expected><versions><version>2.0.2</version>" +
+        String expectedVersions = "<expected><versions><version>2.0.3-SNAPSHOT</version>" +
                        "<version>2.0.4-SNAPSHOT</version></versions></expected>";
         
         XMLAssert.assertXpathEvaluatesTo( "2.0.4-SNAPSHOT", "//metadata/versioning/latest", metadataXml );
@@ -143,7 +143,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
                                      "//metadata/versioning/versions/version", metadataXml );
         XMLAssert.assertXpathEvaluatesTo( "20070427033345", "//metadata/versioning/lastUpdated", metadataXml );
     }
-
+    
     private void populateReleasedSnapshotsTest()
         throws ArchivaDatabaseException
     {