mirror of https://github.com/apache/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
This commit is contained in:
parent
f72ae8a302
commit
c7cd97bf16
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue