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).
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 )
{
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 );
// 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>" +
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" );
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 );
"//metadata/versioning/versions/version", metadataXml );
XMLAssert.assertXpathEvaluatesTo( "20070427033345", "//metadata/versioning/lastUpdated", metadataXml );
}
-
+
private void populateReleasedSnapshotsTest()
throws ArchivaDatabaseException
{