[MRM-1448] additional '.' in the classifier & extension should be attributed to the extension instead of the classifier.

Note that existing records will not be updated - the repository may need to be re-scanned to reflect the change.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1054034 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2010-12-31 00:53:23 +00:00
parent 8aacc3cd0b
commit 91a012ebdd
3 changed files with 71 additions and 16 deletions

View File

@ -34,11 +34,13 @@ import java.util.Collections;
/** /**
* DefaultPathParser is a parser for maven 2 (default layout) paths to ArtifactReference. * DefaultPathParser is a parser for maven 2 (default layout) paths to ArtifactReference.
* *
* TODO: remove in favour of path translator, this is just delegating for the most part * TODO: remove in favour of path translator, this is just delegating for the most part, but won't accommodate other
* extensions like NPanday
* *
* @version $Id$ * @version $Id$
*/ */
public class DefaultPathParser implements PathParser public class DefaultPathParser
implements PathParser
{ {
private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: "; private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: ";
@ -47,6 +49,7 @@ public class DefaultPathParser implements PathParser
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @see org.apache.maven.archiva.repository.content.PathParser#toArtifactReference(java.lang.String) * @see org.apache.maven.archiva.repository.content.PathParser#toArtifactReference(java.lang.String)
*/ */
public ArtifactReference toArtifactReference( String path ) public ArtifactReference toArtifactReference( String path )
@ -77,7 +80,7 @@ public class DefaultPathParser implements PathParser
artifact.setClassifier( facet.getClassifier() ); artifact.setClassifier( facet.getClassifier() );
artifact.setType( facet.getType() ); artifact.setType( facet.getType() );
} }
return artifact; return artifact;
} }

View File

@ -27,6 +27,8 @@ import org.apache.maven.archiva.repository.layout.LayoutException;
/** /**
* DefaultPathParserTest * DefaultPathParserTest
* *
* TODO: move to path translator tests
*
* @version $Id$ * @version $Id$
*/ */
public class DefaultPathParserTest public class DefaultPathParserTest
@ -42,7 +44,8 @@ public class DefaultPathParserTest
public void testBadPathReleaseInSnapshotDir() public void testBadPathReleaseInSnapshotDir()
{ {
assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", "non snapshot artifact inside of a snapshot dir" ); assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar",
"non snapshot artifact inside of a snapshot dir" );
} }
public void testBadPathTimestampedSnapshotNotInSnapshotDir() public void testBadPathTimestampedSnapshotNotInSnapshotDir()
@ -88,9 +91,49 @@ public class DefaultPathParserTest
assertLayout( path, groupId, artifactId, version, classifier, type ); assertLayout( path, groupId, artifactId, version, classifier, type );
} }
public void testGoodButDualExtensionsWithClassifier()
throws LayoutException
{
String groupId = "org.project";
String artifactId = "example-presentation";
String version = "3.2";
String classifier = "extras";
String type = "xml.zip";
String path = "org/project/example-presentation/3.2/example-presentation-3.2-extras.xml.zip";
assertLayout( path, groupId, artifactId, version, classifier, type );
}
public void testGoodButDualExtensionsTarGz()
throws LayoutException
{
String groupId = "org.project";
String artifactId = "example-distribution";
String version = "1.3";
String classifier = null;
String type = "tar.gz"; // no longer using distribution-tgz / distribution-zip in maven 2
String path = "org/project/example-distribution/1.3/example-distribution-1.3.tar.gz";
assertLayout( path, groupId, artifactId, version, classifier, type );
}
public void testGoodButDualExtensionsTarGzAndClassifier()
throws LayoutException
{
String groupId = "org.project";
String artifactId = "example-distribution";
String version = "1.3";
String classifier = "bin";
String type = "tar.gz"; // no longer using distribution-tgz / distribution-zip in maven 2
String path = "org/project/example-distribution/1.3/example-distribution-1.3-bin.tar.gz";
assertLayout( path, groupId, artifactId, version, classifier, type );
}
/** /**
* [MRM-432] Oddball version spec. * [MRM-432] Oddball version spec.
* Example of an oddball / unusual version spec. * Example of an oddball / unusual version spec.
*
* @throws LayoutException * @throws LayoutException
*/ */
public void testGoodButOddVersionSpecGanymedSsh2() public void testGoodButOddVersionSpecGanymedSsh2()
@ -109,6 +152,7 @@ public class DefaultPathParserTest
/** /**
* [MRM-432] Oddball version spec. * [MRM-432] Oddball version spec.
* Example of an oddball / unusual version spec. * Example of an oddball / unusual version spec.
*
* @throws LayoutException * @throws LayoutException
*/ */
public void testGoodButOddVersionSpecJavaxComm() public void testGoodButOddVersionSpecJavaxComm()
@ -148,6 +192,7 @@ public class DefaultPathParserTest
/** /**
* [MRM-432] Oddball version spec. * [MRM-432] Oddball version spec.
* Example of an oddball / unusual version spec. * Example of an oddball / unusual version spec.
*
* @throws LayoutException * @throws LayoutException
*/ */
public void testGoodButOddVersionSpecJavaxPersistence() public void testGoodButOddVersionSpecJavaxPersistence()
@ -252,13 +297,15 @@ public class DefaultPathParserTest
String version = "0.3"; String version = "0.3";
String classifier = null; String classifier = null;
String type = "pom"; String type = "pom";
String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom"; String path =
"com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
assertLayout( path, groupId, artifactId, version, classifier, type ); assertLayout( path, groupId, artifactId, version, classifier, type );
} }
/** /**
* Test the classifier, and java-source type spec. * Test the classifier, and java-source type spec.
*
* @throws LayoutException * @throws LayoutException
*/ */
public void testGoodFooLibSources() public void testGoodFooLibSources()
@ -276,6 +323,7 @@ public class DefaultPathParserTest
/** /**
* A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory. * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
*
* @throws LayoutException * @throws LayoutException
*/ */
public void testGoodSnapshotMavenTest() public void testGoodSnapshotMavenTest()
@ -286,13 +334,15 @@ public class DefaultPathParserTest
String version = "3.1-beta-1-20050831.101112-42"; String version = "3.1-beta-1-20050831.101112-42";
String classifier = null; String classifier = null;
String type = "jar"; String type = "jar";
String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar"; String path =
"org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
assertLayout( path, groupId, artifactId, version, classifier, type ); assertLayout( path, groupId, artifactId, version, classifier, type );
} }
/** /**
* A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory. * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
*
* @throws LayoutException * @throws LayoutException
*/ */
public void testGoodLongSnapshotMavenTest() public void testGoodLongSnapshotMavenTest()
@ -309,16 +359,17 @@ public class DefaultPathParserTest
} }
/** /**
* A timestamped versioned artifact but without release version part. Like on axiom trunk. * A timestamped versioned artifact but without release version part. Like on axiom trunk.
*/ */
public void testBadSnapshotWithoutReleasePart() public void testBadSnapshotWithoutReleasePart()
{ {
assertBadPath( "org/apache/ws/commons/axiom/axiom/SNAPSHOT/axiom-20070912.093446-2.pom", assertBadPath( "org/apache/ws/commons/axiom/axiom/SNAPSHOT/axiom-20070912.093446-2.pom",
"snapshot version without release part"); "snapshot version without release part" );
} }
/** /**
* A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory. * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
*
* @throws LayoutException * @throws LayoutException
*/ */
public void testClassifiedSnapshotMavenTest() public void testClassifiedSnapshotMavenTest()
@ -451,8 +502,8 @@ public class DefaultPathParserTest
private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId, private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
String version, String classifier, String type ) String version, String classifier, String type )
{ {
String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier String expectedId =
+ ":" + type; "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
assertNotNull( expectedId + " - Should not be null.", actualReference ); assertNotNull( expectedId + " - Should not be null.", actualReference );
@ -471,7 +522,8 @@ public class DefaultPathParserTest
try try
{ {
parser.toArtifactReference( path ); parser.toArtifactReference( path );
fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); fail(
"Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
} }
catch ( LayoutException e ) catch ( LayoutException e )
{ {

View File

@ -166,7 +166,7 @@ public class Maven2RepositoryPathTranslator
if ( !id.startsWith( projectId + "-" ) ) if ( !id.startsWith( projectId + "-" ) )
{ {
throw new IllegalArgumentException( "Not a valid artifact path in a Maven 2 repository, filename '" + id + throw new IllegalArgumentException( "Not a valid artifact path in a Maven 2 repository, filename '" + id +
"' doesn't start with artifact ID '" + projectId + "'" ); "' doesn't start with artifact ID '" + projectId + "'" );
} }
MavenArtifactFacet facet = new MavenArtifactFacet(); MavenArtifactFacet facet = new MavenArtifactFacet();
@ -228,9 +228,9 @@ public class Maven2RepositoryPathTranslator
char c = id.charAt( index ); char c = id.charAt( index );
if ( c == '-' ) if ( c == '-' )
{ {
// classifier up until last '.' // classifier up until '.'
int extIndex = id.lastIndexOf( '.' ); int extIndex = id.indexOf( '.', index );
if ( extIndex > index ) if ( extIndex >= 0 )
{ {
classifier = id.substring( index + 1, extIndex ); classifier = id.substring( index + 1, extIndex );
ext = id.substring( extIndex + 1 ); ext = id.substring( extIndex + 1 );