diff options
author | Brett Porter <brett@apache.org> | 2010-03-10 14:35:31 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2010-03-10 14:35:31 +0000 |
commit | f97e798940891576765cca72287069eb984a5a78 (patch) | |
tree | 8477a84086de569b2f762e99f4682cacca6008c4 /archiva-modules/archiva-base/archiva-repository-layer | |
parent | 2211cb809df3365b1e646d27661264ddb9ca8b6f (diff) | |
download | archiva-f97e798940891576765cca72287069eb984a5a78.tar.gz archiva-f97e798940891576765cca72287069eb984a5a78.zip |
[MRM-1282] Repository Path Translation consolidation
- DefaultPathParser now a shell around RepositoryPathTranslator, for refactoring away
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@921366 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-repository-layer')
4 files changed, 43 insertions, 105 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java index 6f235cc76..16177da46 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java @@ -24,7 +24,6 @@ import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMapp import java.util.HashMap; import java.util.Map; -import java.util.regex.Pattern; /** * ArtifactExtensionMapping @@ -41,8 +40,6 @@ public class ArtifactExtensionMapping private static final Map<String, String> typeToExtensionMap; - private static final Pattern mavenPluginPattern = Pattern.compile( "^(maven-.*-plugin)|(.*-maven-plugin)$" ); - // TODO: won't support extensions - need to refactor away this class private static final ArtifactMappingProvider mapping = new DefaultArtifactMappingProvider(); @@ -79,17 +76,6 @@ public class ArtifactExtensionMapping return type; } - /** - * Determine if a given artifact Id conforms to the naming scheme for a maven plugin. - * - * @param artifactId the artifactId to test. - * @return true if this artifactId conforms to the naming scheme for a maven plugin. - */ - public static boolean isMavenPlugin( String artifactId ) - { - return mavenPluginPattern.matcher( artifactId ).matches(); - } - public static String mapExtensionAndClassifierToType( String classifier, String extension ) { return mapExtensionAndClassifierToType( classifier, extension, extension ); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java index abea4a6b7..1c478f08c 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java @@ -24,8 +24,8 @@ import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider; import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider; import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator; +import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.layout.LayoutException; @@ -71,80 +71,13 @@ public class DefaultPathParser implements PathParser artifact.setGroupId( metadata.getNamespace() ); artifact.setArtifactId( metadata.getProject() ); artifact.setVersion( metadata.getVersion() ); - - // TODO: use Maven facet instead - String filename = metadata.getId(); - FilenameParser parser = new FilenameParser( filename ); - artifact.setArtifactId( parser.expect( artifact.getArtifactId() ) ); - if ( artifact.getArtifactId() == null ) - { - throw new LayoutException( INVALID_ARTIFACT_PATH + "filename format is invalid, " - + "should start with artifactId as stated in path." ); - } - String baseVersion = VersionUtil.getBaseVersion( metadata.getVersion() ); - artifact.setVersion( parser.expect( baseVersion ) ); - if ( artifact.getVersion() == null ) + MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID ); + if ( facet != null ) { - // We working with a snapshot? - if ( VersionUtil.isSnapshot( baseVersion ) ) - { - artifact.setVersion( parser.nextVersion() ); - if ( !VersionUtil.isUniqueSnapshot( artifact.getVersion() ) ) - { - throw new LayoutException( INVALID_ARTIFACT_PATH + "filename format is invalid," - + "expected timestamp format in filename." ); - } - } - else - { - throw new LayoutException( INVALID_ARTIFACT_PATH + "filename format is invalid, " - + "expected version as stated in path." ); - } + artifact.setClassifier( facet.getClassifier() ); + artifact.setType( facet.getType() ); } - switch(parser.seperator()) - { - case '-': - // Definately a classifier. - artifact.setClassifier( parser.remaining() ); - - // Set the type. - artifact.setType( ArtifactExtensionMapping.mapExtensionAndClassifierToType( artifact.getClassifier(), parser.getExtension() ) ); - break; - case '.': - // We have an dual extension possibility. - String extension = parser.remaining() + '.' + parser.getExtension(); - artifact.setType( extension ); - break; - case 0: - // End of the filename, only a simple extension left. - Set the type. - String type = ArtifactExtensionMapping.mapExtensionToType( parser.getExtension() ); - if ( type == null ) - { - throw new LayoutException( "Invalid artifact: no type was specified" ); - } - artifact.setType( type ); - break; - } - if ( StringUtils.equals( "jar", artifact.getType() ) && - ArtifactExtensionMapping.isMavenPlugin( artifact.getArtifactId() ) ) - { - artifact.setType( ArtifactExtensionMapping.MAVEN_PLUGIN ); - } - - // Sanity Checks. - - // Do we have a snapshot version? - if ( VersionUtil.isSnapshot( artifact.getVersion() ) ) - { - // Rules are different for SNAPSHOTS - if ( !VersionUtil.isGenericSnapshot( baseVersion ) ) - { - String filenameBaseVersion = VersionUtil.getBaseVersion( artifact.getVersion() ); - throw new LayoutException( "Invalid snapshot artifact location, version directory should be " - + filenameBaseVersion ); - } - } - + return artifact; } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMappingTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMappingTest.java index b8de803eb..3201b4833 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMappingTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMappingTest.java @@ -19,39 +19,57 @@ package org.apache.maven.archiva.repository.content; * under the License. */ +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; +import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider; +import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator; +import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase; +import java.util.Collections; + /** - * ArtifactExtensionMappingTest + * ArtifactExtensionMappingTest * * @version $Id$ */ public class ArtifactExtensionMappingTest -extends AbstractRepositoryLayerTestCase + extends AbstractRepositoryLayerTestCase { + private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator( + Collections.<ArtifactMappingProvider>emptyList() ); + public void testIsMavenPlugin() { - assertMavenPlugin( "maven-test-plugin" ); - assertMavenPlugin( "maven-clean-plugin" ); - assertMavenPlugin( "cobertura-maven-plugin" ); - assertMavenPlugin( "maven-project-info-reports-plugin" ); - assertMavenPlugin( "silly-name-for-a-maven-plugin" ); - - assertNotMavenPlugin( "maven-plugin-api" ); - assertNotMavenPlugin( "foo-lib" ); - assertNotMavenPlugin( "another-maven-plugin-api" ); - assertNotMavenPlugin( "secret-maven-plugin-2" ); + assertMavenPlugin( "maven-test-plugin" ); + assertMavenPlugin( "maven-clean-plugin" ); + assertMavenPlugin( "cobertura-maven-plugin" ); + assertMavenPlugin( "maven-project-info-reports-plugin" ); + assertMavenPlugin( "silly-name-for-a-maven-plugin" ); + + assertNotMavenPlugin( "maven-plugin-api" ); + assertNotMavenPlugin( "foo-lib" ); + assertNotMavenPlugin( "another-maven-plugin-api" ); + assertNotMavenPlugin( "secret-maven-plugin-2" ); } - + private void assertMavenPlugin( String artifactId ) { - assertTrue( "Should be detected as maven plugin: <" + artifactId + ">", - ArtifactExtensionMapping.isMavenPlugin( artifactId ) ); + assertEquals( "Should be detected as maven plugin: <" + artifactId + ">", "maven-plugin", getTypeFromArtifactId( + artifactId ) ); } - + + private String getTypeFromArtifactId( String artifactId ) + { + ArtifactMetadata artifact = pathTranslator.getArtifactFromId( null, "groupId", artifactId, "1.0", + artifactId + "-1.0.jar" ); + MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet( MavenArtifactFacet.FACET_ID ); + return facet.getType(); + } + private void assertNotMavenPlugin( String artifactId ) { - assertFalse( "Should NOT be detected as maven plugin: <" + artifactId + ">", - ArtifactExtensionMapping.isMavenPlugin( artifactId ) ); + assertFalse( "Should NOT be detected as maven plugin: <" + artifactId + ">", "maven-plugin".equals( + getTypeFromArtifactId( artifactId ) ) ); } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java index bb8fcbd38..97a50418e 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java @@ -36,6 +36,7 @@ public class DefaultPathParserTest public void testBadPathMissingType() { + // TODO: should we allow this instead? assertBadPath( "invalid/invalid/1/invalid-1", "missing type" ); } |