From 5a92d221189abd1d62684f043fe9656f5898bf47 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Mon, 21 Dec 2009 12:12:58 +0000 Subject: [PATCH] [MRM-1282] make sure snapshot artifact versions are processed correctly git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@892790 13f79535-47bb-0310-9956-ffa450edef68 --- .../Maven2RepositoryMetadataResolver.java | 21 ++++++++++++++++++- .../Maven2RepositoryMetadataResolverTest.java | 14 +++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java index 05290b5ae..e0ec1fe27 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java @@ -28,6 +28,8 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; @@ -482,7 +484,24 @@ public class Maven2RepositoryMetadataResolver log.error( "Unable to checksum file " + file + ": " + e.getMessage() ); } metadata.setSize( file.length() ); - metadata.setVersion( projectVersion ); + + // TODO: very crude, migrate the functionality from the repository-layer here + if ( VersionUtil.isGenericSnapshot( projectVersion ) ) + { + String mainVersion = + projectVersion.substring( 0, projectVersion.length() - 8 ); // 8 is length of "SNAPSHOT" + System.out.println( file.getName() + " " + mainVersion ); + Matcher m = Pattern.compile( projectId + "-" + mainVersion + "([0-9]{8}.[0-9]{6}-[0-9]+).*" ).matcher( + file.getName() ); + m.matches(); + String version = mainVersion + m.group( 1 ); + + metadata.setVersion( version ); + } + else + { + metadata.setVersion( projectVersion ); + } artifacts.add( metadata ); } } diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java index d9aca1fc4..eca561b52 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java @@ -359,6 +359,20 @@ public class Maven2RepositoryMetadataResolverTest assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 ); } + public void testGetArtifactsTimestampedSnapshots() + { + List artifacts = new ArrayList( + resolver.getArtifacts( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" ) ); + assertEquals( 1, artifacts.size() ); + + ArtifactMetadata artifact = artifacts.get( 0 ); + assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() ); + assertEquals( "com.example.test", artifact.getNamespace() ); + assertEquals( "missing-metadata", artifact.getProject() ); + assertEquals( "1.0-20091101.112233-1", artifact.getVersion() ); + assertEquals( TEST_REPO_ID, artifact.getRepositoryId() ); + } + private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 ) { assertEquals( id, artifact.getId() ); -- 2.39.5