]> source.dussan.org Git - archiva.git/commitdiff
[MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactRefere...
authorJoakim Erdfelt <joakime@apache.org>
Mon, 22 Oct 2007 20:00:55 +0000 (20:00 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Mon, 22 Oct 2007 20:00:55 +0000 (20:00 +0000)
Added ability in default and legacy layouts to detect the 'maven-plugin' type.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@587224 13f79535-47bb-0310-9956-ffa450edef68

archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContentTestCase.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMappingTest.java [new file with mode: 0644]
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java

index 33931a52775e5a3636e1f8c4ea7f1ecbf2436da7..154b7b29f16df2e0ddf3d8d967a11b6b7f4c2fca 100644 (file)
@@ -47,6 +47,7 @@ public abstract class AbstractLegacyRepositoryContent
     {
         typeToDirectoryMap = new HashMap<String, String>();
         typeToDirectoryMap.put( "ejb-client", "ejb" );
+        typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_PLUGIN, "plugin" );
         typeToDirectoryMap.put( "distribution-tgz", "distribution" );
         typeToDirectoryMap.put( "distribution-zip", "distribution" );
     }
index dc9f268b43d5365ab458188cc8ca26a100c4b0e9..89206b68b5e02da1d6e91e9f5671f7cbf4f1509c 100644 (file)
@@ -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<String, String> typeToExtensionMap;
+    public static final String MAVEN_ARCHETYPE = "maven-archetype";
+
+    public static final String MAVEN_PLUGIN = "maven-plugin";
+    
+    private static final Map<String, String> 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();
+    }
 }
index 63a8a4310bb64ce7a137fe99eb6c212917deb036..59c68276a2b0c4a0cbcf2bfef8bd03a291392ec1 100644 (file)
@@ -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;
     }
+    
 }
index e672f812f940f35a076df059f36315b72dda3f31..2ccfe182fa10375f2a8cdf7672575b7b05f64918 100644 (file)
@@ -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() ) );
index 92a8609b331b3979b3f840d3550e2bea205e684d..55beef581635e6e0bebdc3cf4df28ef19bf5cfd1 100644 (file)
@@ -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;
index a90f18a29dae10638f6a55fdea7b6edd88eb656d..60ceb9c844c411a2765422eeb06878721bb661fb 100644 (file)
@@ -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()
     {
index 405a26de95c65ee3af9a4afb6d94fba4c15c73e4..1320c3db3370b7e206905746518ac7c70bbd323b 100644 (file)
@@ -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/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";
 
-        String path = "maven/jars/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 (file)
index 0000000..7390728
--- /dev/null
@@ -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 <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @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 ) );
+    }
+}
index 5284d06631a46a971cc076e3c671a70543dfb5ef..8ceecbe0fe71565d24a861adddf96a8903d5e7f1 100644 (file)
@@ -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 )
     {
index 4fdfa99e4b19e18f24418fce7bb3a701d828b8f7..2ae322178619bd76350088592c7ff483e7edd404 100644 (file)
@@ -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/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";
 
-        String path = "maven/jars/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 );
     }