From: Maria Odea B. Ching Date: Wed, 7 Nov 2007 09:02:58 +0000 (+0000) Subject: [MRM-576] X-Git-Tag: archiva-1.0-beta-4~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c7cd97bf168f75c532ecabbe48b326e3b98407f2;p=archiva.git [MRM-576] - 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 --- diff --git a/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/VersionUtil.java b/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/VersionUtil.java index 07aadf674..7ac85e2ac 100644 --- a/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/VersionUtil.java +++ b/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/VersionUtil.java @@ -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 ); + /** *

* 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; } } + + /** + *

+ * Get the release version of the snapshot version. + *

+ * + *

+ * 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 + *

+ * + * @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 ) { diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java index cfe735861..066542424 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java @@ -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 ); diff --git a/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java b/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java index a775a6233..55f53bf3c 100644 --- a/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java +++ b/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java @@ -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 = "2.2" + @@ -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 = "2.0.2" + + String expectedVersions = "2.0.3-SNAPSHOT" + "2.0.4-SNAPSHOT"; 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 {