[MRM-1360] move type population into Maven 2 plugin

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@921686 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2010-03-11 04:33:02 +00:00
parent 4330002cef
commit 5761f19b58
8 changed files with 105 additions and 85 deletions

View File

@ -20,6 +20,7 @@ package org.apache.maven.archiva.repository.content;
*/ */
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; 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.Maven2RepositoryPathTranslator;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.common.utils.VersionUtil;
@ -31,6 +32,8 @@ import org.apache.maven.archiva.repository.layout.LayoutException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List;
/** /**
* AbstractDefaultRepositoryContent - common methods for working with default (maven 2) layout. * AbstractDefaultRepositoryContent - common methods for working with default (maven 2) layout.
* *
@ -52,6 +55,11 @@ public abstract class AbstractDefaultRepositoryContent
private PathParser defaultPathParser = new DefaultPathParser(); private PathParser defaultPathParser = new DefaultPathParser();
/**
* @plexus.requirement role="org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider"
*/
protected List<? extends ArtifactMappingProvider> artifactMappingProviders;
public ArtifactReference toArtifactReference( String path ) public ArtifactReference toArtifactReference( String path )
throws LayoutException throws LayoutException
{ {
@ -132,6 +140,20 @@ public abstract class AbstractDefaultRepositoryContent
// to the facet or filename (for the original ID) // to the facet or filename (for the original ID)
private String constructId( String artifactId, String version, String classifier, String type ) private String constructId( String artifactId, String version, String classifier, String type )
{ {
String ext = null;
for ( ArtifactMappingProvider provider : artifactMappingProviders )
{
ext = provider.mapTypeToExtension( type );
if ( ext != null )
{
break;
}
}
if ( ext == null )
{
ext = type;
}
StringBuilder id = new StringBuilder(); StringBuilder id = new StringBuilder();
if ( ( version != null ) && ( type != null ) ) if ( ( version != null ) && ( type != null ) )
{ {
@ -142,7 +164,7 @@ public abstract class AbstractDefaultRepositoryContent
id.append( ARTIFACT_SEPARATOR ).append( classifier ); id.append( ARTIFACT_SEPARATOR ).append( classifier );
} }
id.append( "." ).append( ArtifactExtensionMapping.getExtension( type ) ); id.append( "." ).append( ext );
} }
return id.toString(); return id.toString();
} }

View File

@ -22,9 +22,6 @@ package org.apache.maven.archiva.repository.content;
import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider; 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.DefaultArtifactMappingProvider;
import java.util.HashMap;
import java.util.Map;
/** /**
* ArtifactExtensionMapping * ArtifactExtensionMapping
* *
@ -32,48 +29,21 @@ import java.util.Map;
*/ */
public class ArtifactExtensionMapping public class ArtifactExtensionMapping
{ {
public static final String MAVEN_ARCHETYPE = "maven-archetype";
public static final String MAVEN_PLUGIN = "maven-plugin";
public static final String MAVEN_ONE_PLUGIN = "maven-one-plugin"; public static final String MAVEN_ONE_PLUGIN = "maven-one-plugin";
private static final Map<String, String> typeToExtensionMap;
// TODO: won't support extensions - need to refactor away this class // TODO: won't support extensions - need to refactor away this class
private static final ArtifactMappingProvider mapping = new DefaultArtifactMappingProvider(); private static final ArtifactMappingProvider mapping = new DefaultArtifactMappingProvider();
static
{
typeToExtensionMap = new HashMap<String, String>();
typeToExtensionMap.put( "ejb-client", "jar" );
typeToExtensionMap.put( "ejb", "jar" );
typeToExtensionMap.put( "java-source", "jar" );
typeToExtensionMap.put( "javadoc", "jar" );
typeToExtensionMap.put( "test-jar", "jar" );
typeToExtensionMap.put( MAVEN_PLUGIN, "jar" );
typeToExtensionMap.put( MAVEN_ARCHETYPE, "jar" );
// TODO: move to maven 1 plugin
typeToExtensionMap.put( MAVEN_ONE_PLUGIN, "jar" );
typeToExtensionMap.put( "javadoc.jar", "jar" );
typeToExtensionMap.put( "uberjar", "jar" );
typeToExtensionMap.put( "distribution-tgz", "tar.gz" );
typeToExtensionMap.put( "distribution-zip", "zip" );
typeToExtensionMap.put( "aspect", "jar" );
}
public static String getExtension( String type ) public static String getExtension( String type )
{ {
// Try specialized types first. String ext = mapping.mapTypeToExtension( type );
if ( typeToExtensionMap.containsKey( type ) )
if ( ext == null )
{ {
return typeToExtensionMap.get( type ); ext = type;
} }
// Return type return ext;
return type;
} }
public static String mapExtensionAndClassifierToType( String classifier, String extension ) public static String mapExtensionAndClassifierToType( String classifier, String extension )
@ -86,35 +56,23 @@ public class ArtifactExtensionMapping
{ {
String value = mapping.mapClassifierAndExtensionToType( classifier, extension ); String value = mapping.mapClassifierAndExtensionToType( classifier, extension );
if ( value == null ) if ( value == null )
{
value = mapToMaven1Type( extension );
}
return value != null ? value : defaultExtension;
}
public static String mapExtensionToType( String extension )
{
String value = mapToMaven1Type( extension );
return value != null ? value : extension;
}
private static String mapToMaven1Type( String extension )
{ {
// TODO: Maven 1 plugin // TODO: Maven 1 plugin
String value = null; String value1 = null;
if ( "tar.gz".equals( extension ) ) if ( "tar.gz".equals( extension ) )
{ {
value = "distribution-tgz"; value1 = "distribution-tgz";
} }
else if ( "tar.bz2".equals( extension ) ) else if ( "tar.bz2".equals( extension ) )
{ {
value = "distribution-bzip"; value1 = "distribution-bzip";
} }
else if ( "zip".equals( extension ) ) else if ( "zip".equals( extension ) )
{ {
value = "distribution-zip"; value1 = "distribution-zip";
} }
return value; value = value1;
}
return value != null ? value : defaultExtension;
} }
} }

View File

@ -19,6 +19,7 @@ package org.apache.maven.archiva.repository.content;
* under the License. * under the License.
*/ */
import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.maven.archiva.common.utils.PathUtil; import org.apache.maven.archiva.common.utils.PathUtil;
import org.apache.maven.archiva.configuration.FileTypes; import org.apache.maven.archiva.configuration.FileTypes;
@ -33,6 +34,7 @@ import org.apache.maven.archiva.repository.layout.LayoutException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -41,8 +43,6 @@ import java.util.Set;
* *
* @version $Id$ * @version $Id$
* *
* @todo no need to be a component when filetypes is not
*
* @plexus.component * @plexus.component
* role="org.apache.maven.archiva.repository.ManagedRepositoryContent" * role="org.apache.maven.archiva.repository.ManagedRepositoryContent"
* role-hint="default" * role-hint="default"
@ -59,6 +59,12 @@ public class ManagedDefaultRepositoryContent
private ManagedRepositoryConfiguration repository; private ManagedRepositoryConfiguration repository;
public ManagedDefaultRepositoryContent()
{
// default to use if there are none supplied as components
this.artifactMappingProviders = Collections.singletonList( new DefaultArtifactMappingProvider() );
}
public void deleteVersion( VersionedReference reference ) public void deleteVersion( VersionedReference reference )
throws ContentNotFoundException throws ContentNotFoundException
{ {

View File

@ -330,6 +330,8 @@ public class RepositoryRequestTest
{ {
ManagedRepositoryContent repository = createManagedRepo( "default" ); ManagedRepositoryContent repository = createManagedRepo( "default" );
// TODO: this is a good test case for maven 1 -> maven 2 link, since m2 doesn't support the distribution-zip type
// Test (artifact) legacy to default - dual extension // Test (artifact) legacy to default - dual extension
// NOTE: The detection of a dual extension is flawed. // NOTE: The detection of a dual extension is flawed.
assertEquals( "org/project/example-presentation/3.2.xml/example-presentation-3.2.xml.zip", repoRequest assertEquals( "org/project/example-presentation/3.2.xml/example-presentation-3.2.xml.zip", repoRequest

View File

@ -19,15 +19,6 @@ package org.apache.maven.archiva.web.action;
* under the License. * under the License.
*/ */
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.Validateable; import com.opensymphony.xwork2.Validateable;
import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.Dependency; import org.apache.archiva.metadata.model.Dependency;
@ -36,14 +27,23 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.RepositoryContentFactory;
import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.RepositoryException;
import org.apache.maven.archiva.repository.layout.LayoutException;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/** /**
* Browse the repository. * Browse the repository.
* *
@ -381,7 +381,8 @@ public class ShowArtifactAction
{ {
repositoryId = artifact.getRepositoryId(); repositoryId = artifact.getRepositoryId();
// TODO: use metadata resolver capability instead // TODO: use metadata resolver capability instead - maybe the storage path could be stored in the metadata
// though keep in mind the request may not necessarily need to reflect the storage
ManagedRepositoryContent repo; ManagedRepositoryContent repo;
try try
{ {
@ -399,14 +400,15 @@ public class ShowArtifactAction
path = repo.toPath( ref ); path = repo.toPath( ref );
path = path.substring( 0, path.lastIndexOf( "/" ) + 1 ) + artifact.getId(); path = path.substring( 0, path.lastIndexOf( "/" ) + 1 ) + artifact.getId();
try // TODO: need to accommodate Maven 1 layout too. Non-maven repository formats will need to generate this
// facet (perhaps on the fly) if wanting to display the Maven 2 elements on the Archiva pages
String type = null;
MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet( MavenArtifactFacet.FACET_ID );
if ( facet != null )
{ {
type = repo.toArtifactReference( path ).getType(); type = facet.getType();
}
catch ( LayoutException e )
{
throw new RuntimeException( e );
} }
this.type = type;
namespace = artifact.getNamespace(); namespace = artifact.getNamespace();
project = artifact.getProject(); project = artifact.getProject();

View File

@ -40,7 +40,7 @@
<body> <body>
<s:set name="model" value="model"/> <s:set name="model" value="model"/>
<c:set var="mavenFacet" value="${model.facets['org.apache.archiva.metadata.repository.storage.maven2']}" /> <c:set var="mavenFacet" value="${model.facets['org.apache.archiva.metadata.repository.storage.maven2.project']}" />
<c:choose> <c:choose>
<c:when test="${mavenFacet.packaging == 'maven-plugin'}"> <c:when test="${mavenFacet.packaging == 'maven-plugin'}">
@ -126,7 +126,7 @@
</s:url> </s:url>
</c:set> </c:set>
<my:currentWWUrl url="${url}">Mailing Lists</my:currentWWUrl> <my:currentWWUrl url="${url}">Mailing Lists</my:currentWWUrl>
<%-- POSTPONED to 1.0-alpha-2 <%-- TODO
<redback:ifAnyAuthorized permissions="archiva-access-reports"> <redback:ifAnyAuthorized permissions="archiva-access-reports">
<c:set var="url"> <c:set var="url">
<s:url action="showArtifactReports"> <s:url action="showArtifactReports">

View File

@ -22,4 +22,6 @@ package org.apache.archiva.metadata.repository.storage.maven2;
public interface ArtifactMappingProvider public interface ArtifactMappingProvider
{ {
String mapClassifierAndExtensionToType( String classifier, String ext ); String mapClassifierAndExtensionToType( String classifier, String ext );
String mapTypeToExtension( String type );
} }

View File

@ -30,6 +30,8 @@ public class DefaultArtifactMappingProvider
{ {
private final Map<String, String> classifierAndExtensionToTypeMap; private final Map<String, String> classifierAndExtensionToTypeMap;
private final Map<String, String> typeToExtensionMap;
public DefaultArtifactMappingProvider() public DefaultArtifactMappingProvider()
{ {
classifierAndExtensionToTypeMap = new HashMap<String, String>(); classifierAndExtensionToTypeMap = new HashMap<String, String>();
@ -39,6 +41,27 @@ public class DefaultArtifactMappingProvider
classifierAndExtensionToTypeMap.put( "sources:jar", "java-source" ); classifierAndExtensionToTypeMap.put( "sources:jar", "java-source" );
classifierAndExtensionToTypeMap.put( "javadoc:jar", "javadoc" ); classifierAndExtensionToTypeMap.put( "javadoc:jar", "javadoc" );
classifierAndExtensionToTypeMap.put( "tests:jar", "test-jar" ); classifierAndExtensionToTypeMap.put( "tests:jar", "test-jar" );
typeToExtensionMap = new HashMap<String, String>();
// Maven 2.2.1 supplied types (excluding defaults where extension == type and no classifier)
typeToExtensionMap.put( "ejb-client", "jar" );
typeToExtensionMap.put( "ejb", "jar" );
typeToExtensionMap.put( "java-source", "jar" );
typeToExtensionMap.put( "javadoc", "jar" );
typeToExtensionMap.put( "test-jar", "jar" );
typeToExtensionMap.put( "maven-plugin", "jar" );
// Additional type
typeToExtensionMap.put( "maven-archetype", "jar" );
// TODO: move to maven 1 plugin
typeToExtensionMap.put( "maven-one-plugin", "jar" );
typeToExtensionMap.put( "javadoc.jar", "jar" );
typeToExtensionMap.put( "uberjar", "jar" );
typeToExtensionMap.put( "distribution-tgz", "tar.gz" );
typeToExtensionMap.put( "distribution-zip", "zip" );
typeToExtensionMap.put( "aspect", "jar" );
} }
public String mapClassifierAndExtensionToType( String classifier, String ext ) public String mapClassifierAndExtensionToType( String classifier, String ext )
@ -53,4 +76,9 @@ public class DefaultArtifactMappingProvider
} }
return classifierAndExtensionToTypeMap.get( classifier + ":" + ext ); return classifierAndExtensionToTypeMap.get( classifier + ":" + ext );
} }
public String mapTypeToExtension( String type )
{
return typeToExtensionMap.get( type );
}
} }