[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
This commit is contained in:
Maria Odea B. Ching 2007-11-07 09:02:58 +00:00
parent f72ae8a302
commit c7cd97bf16
3 changed files with 52 additions and 18 deletions

View 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).
@ -154,6 +156,38 @@ public class VersionUtil
}
}
/**
* <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 )
{
Matcher m = UNIQUE_SNAPSHOT_PATTERN.matcher( version );

View File

@ -136,7 +136,7 @@ public class CleanupReleasedSnapshotsRepositoryPurge
for ( String version : snapshotVersions )
{
if ( VersionComparator.getInstance().compare( version, highestReleasedVersion ) < 0 )
if( releasedVersions.contains( VersionUtil.getReleaseVersion( version ) ) )
{
versionRef.setVersion( version );
repository.deleteVersion( versionRef );

View File

@ -112,14 +112,14 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
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 );