diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java index 33931a527..154b7b29f 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java @@ -47,6 +47,7 @@ public abstract class AbstractLegacyRepositoryContent { typeToDirectoryMap = new HashMap(); typeToDirectoryMap.put( "ejb-client", "ejb" ); + typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_PLUGIN, "plugin" ); typeToDirectoryMap.put( "distribution-tgz", "distribution" ); typeToDirectoryMap.put( "distribution-zip", "distribution" ); } diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java index dc9f268b4..89206b68b 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java @@ -24,6 +24,7 @@ import org.apache.commons.lang.StringUtils; import java.io.File; import java.util.HashMap; import java.util.Map; +import java.util.regex.Pattern; /** * ArtifactExtensionMapping @@ -33,7 +34,13 @@ import java.util.Map; */ public class ArtifactExtensionMapping { - protected static final Map typeToExtensionMap; + public static final String MAVEN_ARCHETYPE = "maven-archetype"; + + public static final String MAVEN_PLUGIN = "maven-plugin"; + + private static final Map typeToExtensionMap; + + private static final Pattern mavenPluginPattern = Pattern.compile( "^(maven-.*-plugin)|(.*-maven-plugin)$" ); static { @@ -47,9 +54,8 @@ public class ArtifactExtensionMapping typeToExtensionMap.put( "javadoc", "jar" ); typeToExtensionMap.put( "aspect", "jar" ); typeToExtensionMap.put( "uberjar", "jar" ); - typeToExtensionMap.put( "plugin", "jar" ); - typeToExtensionMap.put( "maven-plugin", "jar" ); - typeToExtensionMap.put( "maven-archetype", "jar" ); + typeToExtensionMap.put( MAVEN_PLUGIN, "jar" ); + typeToExtensionMap.put( MAVEN_ARCHETYPE, "jar" ); } public static String getExtension( String type ) @@ -109,4 +115,15 @@ public class ArtifactExtensionMapping return normalizedName.substring( idx + 1 ); } } + + /** + * 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(); + } } diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java index 63a8a4310..59c68276a 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java @@ -147,8 +147,13 @@ public class DefaultPathParser // Set the type. artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) ); - - artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) ); + + // Special case for maven plugins + if ( StringUtils.equals( "jar", artifact.getType() ) && + ArtifactExtensionMapping.isMavenPlugin( artifact.getArtifactId() ) ) + { + artifact.setType( ArtifactExtensionMapping.MAVEN_PLUGIN ); + } } catch ( LayoutException e ) { @@ -181,4 +186,5 @@ public class DefaultPathParser return artifact; } + } diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java index e672f812f..2ccfe182f 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java @@ -38,7 +38,7 @@ public class FilenameParser private int offset; - private static final Pattern specialCases = Pattern.compile( "(maven-.*-plugin)|(maven-plugin)" ); + private static final Pattern mavenPluginPattern = Pattern.compile( "(maven-.*-plugin)|(.*-maven-plugin)" ); private static final Pattern extensionPattern = Pattern.compile( "(.tar.gz$)|(.tar.bz2$)|(.[a-z0-9]{1,4}$)", Pattern.CASE_INSENSITIVE ); @@ -143,7 +143,7 @@ public class FilenameParser StringBuffer ver = new StringBuffer(); // Any text upto the end of a special case is considered non-version. - Matcher specialMat = specialCases.matcher( name ); + Matcher specialMat = mavenPluginPattern.matcher( name ); if ( specialMat.find() ) { ver.append( name.substring( offset, specialMat.end() ) ); diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java index 92a8609b3..55beef581 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java @@ -127,25 +127,34 @@ public class LegacyPathParser } } + // Set Type artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) ); - + // Sanity Check: does it have an extension? if ( StringUtils.isEmpty( artifact.getType() ) ) { throw new LayoutException( INVALID_ARTIFACT_PATH + "no extension found." ); } - String trimPathType = expectedType.substring( 0, expectedType.length() - 1 ); - - // Sanity Check: does extension match pathType on path? - String expectedExtension = ArtifactExtensionMapping.getExtension( trimPathType ); - String actualExtension = parser.getExtension(); - - if ( !expectedExtension.equals( actualExtension ) ) + // Special Case with Maven Plugins + if ( StringUtils.equals( "jar", artifact.getType() ) && StringUtils.equals( "plugins", expectedType ) ) { - throw new LayoutException( INVALID_ARTIFACT_PATH + "mismatch on extension [" + actualExtension - + "] and layout specified type [" + expectedType + "] (which maps to extension: [" + expectedExtension - + "]) on path [" + path + "]" ); + artifact.setType( ArtifactExtensionMapping.MAVEN_PLUGIN ); + } + else + { + // Sanity Check: does extension match pathType on path? + String trimPathType = expectedType.substring( 0, expectedType.length() - 1 ); + + String expectedExtension = ArtifactExtensionMapping.getExtension( trimPathType ); + String actualExtension = parser.getExtension(); + + if ( !expectedExtension.equals( actualExtension ) ) + { + throw new LayoutException( INVALID_ARTIFACT_PATH + "mismatch on extension [" + actualExtension + + "] and layout specified type [" + expectedType + "] (which maps to extension: [" + + expectedExtension + "]) on path [" + path + "]" ); + } } return artifact; diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContentTestCase.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContentTestCase.java index a90f18a29..60ceb9c84 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContentTestCase.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContentTestCase.java @@ -257,6 +257,39 @@ public abstract class AbstractDefaultRepositoryContentTestCase assertLayout( path, groupId, artifactId, version, classifier, type ); } + + /** + * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. + * Example uses "test" in artifact Id, which is also part of the versionKeyword list. + */ + public void testGoodDetectMavenTestPlugin() + throws LayoutException + { + String groupId = "maven"; + String artifactId = "maven-test-plugin"; + String version = "1.8.2"; + String classifier = null; + String type = "maven-plugin"; + String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar"; + + assertLayout( path, groupId, artifactId, version, classifier, type ); + } + + /** + * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. + */ + public void testGoodDetectCoberturaMavenPlugin() + throws LayoutException + { + String groupId = "org.codehaus.mojo"; + String artifactId = "cobertura-maven-plugin"; + String version = "2.1"; + String classifier = null; + String type = "maven-plugin"; + String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar"; + + assertLayout( path, groupId, artifactId, version, classifier, type ); + } public void testToArtifactOnEmptyPath() { diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java index 405a26de9..1320c3db3 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java @@ -252,9 +252,70 @@ public abstract class AbstractLegacyRepositoryContentTestCase String groupId = "maven"; String artifactId = "maven-test-plugin"; String version = "1.8.2"; - String type = "jar"; + String type = "pom"; - String path = "maven/jars/maven-test-plugin-1.8.2.jar"; + String path = "maven/poms/maven-test-plugin-1.8.2.pom"; + + assertLayout( path, groupId, artifactId, version, type ); + } + + /** + * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. + * Example uses "test" in artifact Id, which is also part of the versionKeyword list. + */ + public void testGoodDetectPluginMavenTest() + throws LayoutException + { + String groupId = "maven"; + String artifactId = "maven-test-plugin"; + String version = "1.8.2"; + String type = "maven-plugin"; + String path = "maven/plugins/maven-test-plugin-1.8.2.jar"; + + assertLayout( path, groupId, artifactId, version, type ); + } + + /** + * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. + */ + public void testGoodDetectPluginAvalonMeta() + throws LayoutException + { + String groupId = "avalon-meta"; + String artifactId = "avalon-meta-plugin"; + String version = "1.1"; + String type = "maven-plugin"; + String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar"; + + assertLayout( path, groupId, artifactId, version, type ); + } + + /** + * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. + */ + public void testGoodDetectPluginCactusMaven() + throws LayoutException + { + String groupId = "cactus"; + String artifactId = "cactus-maven"; + String version = "1.7dev-20040815"; + String type = "maven-plugin"; + String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar"; + + assertLayout( path, groupId, artifactId, version, type ); + } + + /** + * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. + */ + public void testGoodDetectPluginGeronimoPackaging() + throws LayoutException + { + String groupId = "geronimo"; + String artifactId = "geronimo-packaging-plugin"; + String version = "1.0.1"; + String type = "maven-plugin"; + String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar"; assertLayout( path, groupId, artifactId, version, type ); } diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMappingTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMappingTest.java new file mode 100644 index 000000000..7390728f7 --- /dev/null +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMappingTest.java @@ -0,0 +1,58 @@ +package org.apache.maven.archiva.repository.content; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase; + +/** + * ArtifactExtensionMappingTest + * + * @author Joakim Erdfelt + * @version $Id$ + */ +public class ArtifactExtensionMappingTest +extends AbstractRepositoryLayerTestCase +{ + 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" ); + } + + private void assertMavenPlugin( String artifactId ) + { + assertTrue( "Should be detected as maven plugin: <" + artifactId + ">", + ArtifactExtensionMapping.isMavenPlugin( artifactId ) ); + } + + private void assertNotMavenPlugin( String artifactId ) + { + assertFalse( "Should NOT be detected as maven plugin: <" + artifactId + ">", + ArtifactExtensionMapping.isMavenPlugin( artifactId ) ); + } +} diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java index 5284d0663..8ceecbe0f 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java @@ -258,6 +258,39 @@ public class DefaultPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); } + /** + * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. + * Example uses "test" in artifact Id, which is also part of the versionKeyword list. + */ + public void testGoodDetectMavenTestPlugin() + throws LayoutException + { + String groupId = "maven"; + String artifactId = "maven-test-plugin"; + String version = "1.8.2"; + String classifier = null; + String type = "maven-plugin"; + String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar"; + + assertLayout( path, groupId, artifactId, version, classifier, type ); + } + + /** + * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. + */ + public void testGoodDetectCoberturaMavenPlugin() + throws LayoutException + { + String groupId = "org.codehaus.mojo"; + String artifactId = "cobertura-maven-plugin"; + String version = "2.1"; + String classifier = null; + String type = "maven-plugin"; + String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar"; + + assertLayout( path, groupId, artifactId, version, classifier, type ); + } + public void testToArtifactOnEmptyPath() { try @@ -309,7 +342,7 @@ public class DefaultPathParserTest /* expected path */ } } - + /** * Perform a path to artifact reference lookup, and verify the results. */ @@ -321,7 +354,7 @@ public class DefaultPathParserTest ArtifactReference testReference = DefaultPathParser.toArtifactReference( path ); assertArtifactReference( testReference, groupId, artifactId, version, classifier, type ); } - + private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId, String version, String classifier, String type ) { diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java index 4fdfa99e4..2ae322178 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java @@ -253,9 +253,70 @@ public class LegacyPathParserTest String groupId = "maven"; String artifactId = "maven-test-plugin"; String version = "1.8.2"; - String type = "jar"; + String type = "pom"; - String path = "maven/jars/maven-test-plugin-1.8.2.jar"; + String path = "maven/poms/maven-test-plugin-1.8.2.pom"; + + assertLayout( path, groupId, artifactId, version, type ); + } + + /** + * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. + * Example uses "test" in artifact Id, which is also part of the versionKeyword list. + */ + public void testGoodDetectPluginMavenTest() + throws LayoutException + { + String groupId = "maven"; + String artifactId = "maven-test-plugin"; + String version = "1.8.2"; + String type = "maven-plugin"; + String path = "maven/plugins/maven-test-plugin-1.8.2.jar"; + + assertLayout( path, groupId, artifactId, version, type ); + } + + /** + * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. + */ + public void testGoodDetectPluginAvalonMeta() + throws LayoutException + { + String groupId = "avalon-meta"; + String artifactId = "avalon-meta-plugin"; + String version = "1.1"; + String type = "maven-plugin"; + String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar"; + + assertLayout( path, groupId, artifactId, version, type ); + } + + /** + * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. + */ + public void testGoodDetectPluginCactusMaven() + throws LayoutException + { + String groupId = "cactus"; + String artifactId = "cactus-maven"; + String version = "1.7dev-20040815"; + String type = "maven-plugin"; + String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar"; + + assertLayout( path, groupId, artifactId, version, type ); + } + + /** + * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods. + */ + public void testGoodDetectPluginGeronimoPackaging() + throws LayoutException + { + String groupId = "geronimo"; + String artifactId = "geronimo-packaging-plugin"; + String version = "1.0.1"; + String type = "maven-plugin"; + String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar"; assertLayout( path, groupId, artifactId, version, type ); }