[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
This commit is contained in:
Brett Porter 2009-12-21 12:12:58 +00:00
parent e4c08941e9
commit 5a92d22118
2 changed files with 34 additions and 1 deletions

View File

@ -28,6 +28,8 @@
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 Collection<ArtifactMetadata> getArtifacts( String repoId, String namespac
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 );
}
}

View File

@ -359,6 +359,20 @@ public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
}
public void testGetArtifactsTimestampedSnapshots()
{
List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
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() );