*/
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.commons.lang.StringUtils;
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.List;
+
/**
* AbstractDefaultRepositoryContent - common methods for working with default (maven 2) layout.
*
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 )
throws LayoutException
{
// to the facet or filename (for the original ID)
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();
if ( ( version != null ) && ( type != null ) )
{
id.append( ARTIFACT_SEPARATOR ).append( classifier );
}
- id.append( "." ).append( ArtifactExtensionMapping.getExtension( type ) );
+ id.append( "." ).append( ext );
}
return id.toString();
}
import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* 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";
-
- private static final Map<String, String> typeToExtensionMap;
+ public static final String MAVEN_ONE_PLUGIN = "maven-one-plugin";
// TODO: won't support extensions - need to refactor away this class
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 )
{
- // Try specialized types first.
- if ( typeToExtensionMap.containsKey( type ) )
+ String ext = mapping.mapTypeToExtension( type );
+
+ if ( ext == null )
{
- return typeToExtensionMap.get( type );
+ ext = type;
}
- // Return type
- return type;
+ return ext;
}
public static String mapExtensionAndClassifierToType( String classifier, String extension )
String value = mapping.mapClassifierAndExtensionToType( classifier, extension );
if ( value == null )
{
- value = mapToMaven1Type( extension );
+ // TODO: Maven 1 plugin
+ String value1 = null;
+ if ( "tar.gz".equals( extension ) )
+ {
+ value1 = "distribution-tgz";
+ }
+ else if ( "tar.bz2".equals( extension ) )
+ {
+ value1 = "distribution-bzip";
+ }
+ else if ( "zip".equals( extension ) )
+ {
+ value1 = "distribution-zip";
+ }
+ value = value1;
}
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
- String value = null;
- if ( "tar.gz".equals( extension ) )
- {
- value = "distribution-tgz";
- }
- else if ( "tar.bz2".equals( extension ) )
- {
- value = "distribution-bzip";
- }
- else if ( "zip".equals( extension ) )
- {
- value = "distribution-zip";
- }
- return value;
- }
}
* under the License.
*/
+import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
import org.apache.commons.io.FileUtils;
import org.apache.maven.archiva.common.utils.PathUtil;
import org.apache.maven.archiva.configuration.FileTypes;
import java.io.File;
import java.io.IOException;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
*
* @version $Id$
*
- * @todo no need to be a component when filetypes is not
- *
* @plexus.component
* role="org.apache.maven.archiva.repository.ManagedRepositoryContent"
* role-hint="default"
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 )
throws ContentNotFoundException
{
{
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
// NOTE: The detection of a dual extension is flawed.
assertEquals( "org/project/example-presentation/3.2.xml/example-presentation-3.2.xml.zip", repoRequest
* 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 org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.Dependency;
import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.MetadataResolutionException;
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.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.RepositoryContentFactory;
import org.apache.maven.archiva.repository.RepositoryException;
-import org.apache.maven.archiva.repository.layout.LayoutException;
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.
*
{
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;
try
{
path = repo.toPath( ref );
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();
- }
- catch ( LayoutException e )
- {
- throw new RuntimeException( e );
+ type = facet.getType();
}
+ this.type = type;
namespace = artifact.getNamespace();
project = artifact.getProject();
<body>
<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:when test="${mavenFacet.packaging == 'maven-plugin'}">
</s:url>
</c:set>
<my:currentWWUrl url="${url}">Mailing Lists</my:currentWWUrl>
- <%-- POSTPONED to 1.0-alpha-2
+ <%-- TODO
<redback:ifAnyAuthorized permissions="archiva-access-reports">
<c:set var="url">
<s:url action="showArtifactReports">
public interface ArtifactMappingProvider
{
String mapClassifierAndExtensionToType( String classifier, String ext );
+
+ String mapTypeToExtension( String type );
}
{
private final Map<String, String> classifierAndExtensionToTypeMap;
+ private final Map<String, String> typeToExtensionMap;
+
public DefaultArtifactMappingProvider()
{
classifierAndExtensionToTypeMap = new HashMap<String, String>();
classifierAndExtensionToTypeMap.put( "sources:jar", "java-source" );
classifierAndExtensionToTypeMap.put( "javadoc:jar", "javadoc" );
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 )
}
return classifierAndExtensionToTypeMap.get( classifier + ":" + ext );
}
+
+ public String mapTypeToExtension( String type )
+ {
+ return typeToExtensionMap.get( type );
+ }
}