[MRM-596]

applied patch submitted by nicolas de loof

- remove the assertion that legacy path have no classifier. Simply have no way to support unstandard classifiers.
- automatically use "-javadoc" and "-sources" classifiers for path with types "javadoc.jars" and "java-sources". Check for the classifier to 
be detected in the version string and remove it.


git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@596620 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2007-11-20 11:12:47 +00:00
parent 4edbcd1a9d
commit 9cc410a27c
8 changed files with 121 additions and 121 deletions

View File

@ -35,10 +35,6 @@ import java.util.Map;
*/
public abstract class AbstractLegacyRepositoryContent
{
private static final String DIR_JAVADOC = "javadoc.jars";
private static final String DIR_JAVA_SOURCE = "java-sources";
private static final String PATH_SEPARATOR = "/";
private static final Map<String, String> typeToDirectoryMap;
@ -50,6 +46,7 @@ public abstract class AbstractLegacyRepositoryContent
typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_PLUGIN, "plugin" );
typeToDirectoryMap.put( "distribution-tgz", "distribution" );
typeToDirectoryMap.put( "distribution-zip", "distribution" );
typeToDirectoryMap.put( "javadoc", "javadoc.jar" );
}
public ArtifactReference toArtifactReference( String path )
@ -104,21 +101,6 @@ public abstract class AbstractLegacyRepositoryContent
private String getDirectory( String classifier, String type )
{
// Special Cases involving type + classifier
if ( "jar".equals( type ) && StringUtils.isNotBlank( classifier ) )
{
if ( "sources".equals( classifier ) )
{
return DIR_JAVA_SOURCE;
}
if ( "javadoc".equals( classifier ) )
{
return DIR_JAVADOC;
}
}
// Special Cases involving only type.
String dirname = (String) typeToDirectoryMap.get( type );
if ( dirname != null )

View File

@ -157,6 +157,19 @@ public class LegacyPathParser
}
}
String classifier = ArtifactClassifierMapping.getClassifier( artifact.getType() );
if ( classifier != null )
{
String version = artifact.getVersion();
if ( ! version.endsWith( "-" + classifier ) )
{
throw new LayoutException( INVALID_ARTIFACT_PATH + expectedType + " artifacts must use the classifier " + classifier );
}
version = version.substring( 0, version.length() - classifier.length() - 1 );
artifact.setVersion( version );
artifact.setClassifier( classifier );
}
return artifact;
}
}

View File

@ -72,7 +72,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String type = "jar";
String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -89,7 +89,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String type = "jar";
String path = "javax/jars/comm-3.0-u1.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -111,7 +111,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
* the version spec? or the classifier?
*/
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
public void testGoodCommonsLang()
@ -123,7 +123,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String type = "jar";
String path = "commons-lang/jars/commons-lang-2.1.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
public void testGoodDerby()
@ -135,7 +135,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String type = "jar";
String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -167,11 +167,12 @@ public abstract class AbstractLegacyRepositoryContentTestCase
{
String groupId = "com.foo.lib";
String artifactId = "foo-lib";
String version = "2.1-alpha-1-javadoc";
String version = "2.1-alpha-1";
String type = "javadoc";
String path = "com.foo.lib/javadocs/foo-lib-2.1-alpha-1-javadoc.jar";
String classifier = "javadoc";
String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, classifier, type );
}
/**
@ -183,11 +184,12 @@ public abstract class AbstractLegacyRepositoryContentTestCase
{
String groupId = "com.foo.lib";
String artifactId = "foo-lib";
String version = "2.1-alpha-1-sources";
String version = "2.1-alpha-1";
String type = "java-source"; // oddball type-spec (should result in jar extension)
String classifier = "sources";
String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, classifier, type );
}
public void testGoodFooTool()
@ -199,7 +201,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String type = "jar";
String path = "com.foo/jars/foo-tool-1.0.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
public void testGoodGeronimoEjbSpec()
@ -211,7 +213,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String type = "jar";
String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
public void testGoodLdapClientsPom()
@ -223,7 +225,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String type = "pom";
String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -239,7 +241,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String type = "jar";
String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -256,7 +258,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String path = "maven/poms/maven-test-plugin-1.8.2.pom";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -272,7 +274,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String type = "maven-plugin";
String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -287,7 +289,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String type = "maven-plugin";
String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -302,7 +304,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String type = "maven-plugin";
String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -317,16 +319,17 @@ public abstract class AbstractLegacyRepositoryContentTestCase
String type = "maven-plugin";
String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* Perform a roundtrip through the layout routines to determine success.
* @param classifier TODO
*/
private void assertLayout( String path, String groupId, String artifactId, String version, String type )
private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, String type )
throws LayoutException
{
ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, type );
ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
// --- Artifact Tests.
// Artifact to Path
@ -336,14 +339,14 @@ public abstract class AbstractLegacyRepositoryContentTestCase
// Path to Artifact Reference.
ArtifactReference testReference = toArtifactReference( path );
assertArtifactReference( testReference, groupId, artifactId, version, type );
assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
// And back again, using test Reference from previous step.
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) );
}
private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
String version, String type )
String version, String classifier, String type )
{
String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + type;
@ -352,17 +355,17 @@ public abstract class AbstractLegacyRepositoryContentTestCase
assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
assertEquals( expectedId + " - Type", type, actualReference.getType() );
// legacy has no classifier.
assertNull( expectedId + " - classifier", actualReference.getClassifier() );
}
protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String type )
protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier, String type )
{
ArtifactReference artifact = new ArtifactReference();
artifact.setGroupId( groupId );
artifact.setArtifactId( artifactId );
artifact.setVersion( version );
artifact.setClassifier( classifier );
artifact.setType( type );
assertNotNull( artifact );
return artifact;

View File

@ -71,7 +71,7 @@ public class LegacyPathParserTest
String type = "distribution-zip";
String path = "org.project/zips/example-presentation-3.2.xml.zip";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -88,7 +88,7 @@ public class LegacyPathParserTest
String type = "jar";
String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -105,7 +105,7 @@ public class LegacyPathParserTest
String type = "jar";
String path = "javax/jars/comm-3.0-u1.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -127,7 +127,7 @@ public class LegacyPathParserTest
* the version spec? or the classifier?
*/
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
public void testGoodCommonsLang()
@ -139,7 +139,7 @@ public class LegacyPathParserTest
String type = "jar";
String path = "commons-lang/jars/commons-lang-2.1.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
public void testGoodDerby()
@ -151,7 +151,7 @@ public class LegacyPathParserTest
String type = "jar";
String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -183,11 +183,12 @@ public class LegacyPathParserTest
{
String groupId = "com.foo.lib";
String artifactId = "foo-lib";
String version = "2.1-alpha-1-javadoc";
String version = "2.1-alpha-1";
String type = "javadoc";
String path = "com.foo.lib/javadocs/foo-lib-2.1-alpha-1-javadoc.jar";
String classifier = "javadoc";
String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, classifier, type );
}
/**
@ -199,11 +200,12 @@ public class LegacyPathParserTest
{
String groupId = "com.foo.lib";
String artifactId = "foo-lib";
String version = "2.1-alpha-1-sources";
String version = "2.1-alpha-1";
String type = "java-source"; // oddball type-spec (should result in jar extension)
String classifier= "sources";
String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, classifier, type );
}
public void testGoodFooTool()
@ -215,7 +217,7 @@ public class LegacyPathParserTest
String type = "jar";
String path = "com.foo/jars/foo-tool-1.0.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
public void testGoodGeronimoEjbSpec()
@ -227,7 +229,7 @@ public class LegacyPathParserTest
String type = "jar";
String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
public void testGoodLdapClientsPom()
@ -239,7 +241,7 @@ public class LegacyPathParserTest
String type = "pom";
String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -255,7 +257,7 @@ public class LegacyPathParserTest
String type = "jar";
String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -272,7 +274,7 @@ public class LegacyPathParserTest
String path = "maven/poms/maven-test-plugin-1.8.2.pom";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -288,7 +290,7 @@ public class LegacyPathParserTest
String type = "maven-plugin";
String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -303,7 +305,7 @@ public class LegacyPathParserTest
String type = "maven-plugin";
String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -318,7 +320,7 @@ public class LegacyPathParserTest
String type = "maven-plugin";
String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
@ -333,22 +335,23 @@ public class LegacyPathParserTest
String type = "maven-plugin";
String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
assertLayout( path, groupId, artifactId, version, type );
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* Perform a path to artifact reference lookup, and verify the results.
* @param classifier TODO
*/
private void assertLayout( String path, String groupId, String artifactId, String version, String type )
private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, String type )
throws LayoutException
{
// Path to Artifact Reference.
ArtifactReference testReference = LegacyPathParser.toArtifactReference( path );
assertArtifactReference( testReference, groupId, artifactId, version, type );
assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
}
private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
String version, String type )
String version, String classifier, String type )
{
String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + type;
@ -357,9 +360,8 @@ public class LegacyPathParserTest
assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
assertEquals( expectedId + " - Type", type, actualReference.getType() );
// legacy has no classifier.
assertNull( expectedId + " - classifier", actualReference.getClassifier() );
}
protected void assertBadPath( String path, String reason )

View File

@ -49,8 +49,8 @@ public class ManagedLegacyRepositoryContentTest
{
assertVersions( "org.apache.maven", "testing", new String[] {
"UNKNOWN",
"1.0-javadoc",
"1.0-sources",
// "1.0-javadoc",
// "1.0-sources",
"1.0",
"1.0-20050611.112233-1" } );
}
@ -59,8 +59,8 @@ public class ManagedLegacyRepositoryContentTest
throws Exception
{
assertVersions( "org.apache.maven", "testing", "1.0", new String[] {
"1.0-javadoc",
"1.0-sources",
// "1.0-javadoc",
// "1.0-sources",
"1.0",
"1.0-20050611.112233-1" } );
}
@ -119,7 +119,7 @@ public class ManagedLegacyRepositoryContentTest
public void testGetRelatedArtifacts()
throws Exception
{
ArtifactReference reference = createArtifact( "org.apache.maven", "testing", "1.0", "jar" );
ArtifactReference reference = createArtifact( "org.apache.maven", "testing", "1.0", null, "jar" );
Set<ArtifactReference> related = repoContent.getRelatedArtifacts( reference );
assertNotNull( related );
@ -129,7 +129,7 @@ public class ManagedLegacyRepositoryContentTest
"org.apache.maven/java-sources/testing-1.0-sources.jar",
"org.apache.maven/jars/testing-1.0-20050611.112233-1.jar",
"org.apache.maven/poms/testing-1.0.pom",
"org.apache.maven/javadocs/testing-1.0-javadoc.jar" };
"org.apache.maven/javadoc.jars/testing-1.0-javadoc.jar" };
StringBuffer relatedDebugString = new StringBuffer();
relatedDebugString.append( "[" );

View File

@ -112,8 +112,8 @@ public class RepositoryRequestTest
public void testValidLegacyCommonsLangJavadoc()
throws Exception
{
assertValid( "commons-lang/jars/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", "2.1-javadoc",
null, "javadoc" );
assertValid( "commons-lang/javadoc.jars/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", "2.1",
"javadoc", "javadoc" );
}
public void testValidDefaultCommonsLangJavadoc()