[MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.

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
This commit is contained in:
Joakim Erdfelt 2007-10-22 20:00:55 +00:00
parent 603860fca9
commit 1c0f8cd18e
10 changed files with 304 additions and 25 deletions

View 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" );
}

View 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();
}
}

View 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;
}
}

View 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() ) );

View 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;

View 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()
{

View 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/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 );
}

View File

@ -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 ) );
}
}

View 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 )
{

View 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/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 );
}