archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r921686 - in /archiva/trunk/archiva-modules: archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ a...
Date Thu, 11 Mar 2010 04:33:03 GMT
Author: brett
Date: Thu Mar 11 04:33:02 2010
New Revision: 921686

URL: http://svn.apache.org/viewvc?rev=921686&view=rev
Log:
[MRM-1360] move type population into Maven 2 plugin

Modified:
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/ArtifactMappingProvider.java
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java?rev=921686&r1=921685&r2=921686&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java
(original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java
Thu Mar 11 04:33:02 2010
@@ -20,6 +20,7 @@ package org.apache.maven.archiva.reposit
  */
 
 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;
@@ -31,6 +32,8 @@ import org.apache.maven.archiva.reposito
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.List;
+
 /**
  * AbstractDefaultRepositoryContent - common methods for working with default (maven 2) layout.
  *
@@ -52,6 +55,11 @@ public abstract class AbstractDefaultRep
 
     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
     {
@@ -132,6 +140,20 @@ public abstract class AbstractDefaultRep
     //       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 ) )
         {
@@ -142,7 +164,7 @@ public abstract class AbstractDefaultRep
                 id.append( ARTIFACT_SEPARATOR ).append( classifier );
             }
 
-            id.append( "." ).append( ArtifactExtensionMapping.getExtension( type ) );
+            id.append( "." ).append( ext );
         }
         return id.toString();
     }

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java?rev=921686&r1=921685&r2=921686&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
(original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
Thu Mar 11 04:33:02 2010
@@ -22,9 +22,6 @@ package org.apache.maven.archiva.reposit
 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
  *
@@ -32,48 +29,21 @@ import java.util.Map;
  */
 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
)
@@ -87,34 +57,22 @@ public class ArtifactExtensionMapping
         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;
-    }
 }

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java?rev=921686&r1=921685&r2=921686&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java
(original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java
Thu Mar 11 04:33:02 2010
@@ -19,6 +19,7 @@ package org.apache.maven.archiva.reposit
  * 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;
@@ -33,6 +34,7 @@ import org.apache.maven.archiva.reposito
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -41,8 +43,6 @@ 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"
@@ -59,6 +59,12 @@ public class ManagedDefaultRepositoryCon
 
     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
     {

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java?rev=921686&r1=921685&r2=921686&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java
Thu Mar 11 04:33:02 2010
@@ -330,6 +330,8 @@ public class RepositoryRequestTest
     {
         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

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java?rev=921686&r1=921685&r2=921686&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
Thu Mar 11 04:33:02 2010
@@ -19,15 +19,6 @@ package org.apache.maven.archiva.web.act
  * 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;
@@ -36,14 +27,23 @@ import org.apache.archiva.metadata.model
 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.
  *
@@ -381,7 +381,8 @@ public class ShowArtifactAction
         {
             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
             {
@@ -399,14 +400,15 @@ public class ShowArtifactAction
             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();

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp?rev=921686&r1=921685&r2=921686&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp
Thu Mar 11 04:33:02 2010
@@ -40,7 +40,7 @@
 <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'}">
@@ -126,7 +126,7 @@
         </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">

Modified: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/ArtifactMappingProvider.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/ArtifactMappingProvider.java?rev=921686&r1=921685&r2=921686&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/ArtifactMappingProvider.java
(original)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/ArtifactMappingProvider.java
Thu Mar 11 04:33:02 2010
@@ -22,4 +22,6 @@ package org.apache.archiva.metadata.repo
 public interface ArtifactMappingProvider
 {
     String mapClassifierAndExtensionToType( String classifier, String ext );
+
+    String mapTypeToExtension( String type );
 }

Modified: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java?rev=921686&r1=921685&r2=921686&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java
(original)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java
Thu Mar 11 04:33:02 2010
@@ -30,6 +30,8 @@ public class DefaultArtifactMappingProvi
 {
     private final Map<String, String> classifierAndExtensionToTypeMap;
 
+    private final Map<String, String> typeToExtensionMap;
+
     public DefaultArtifactMappingProvider()
     {
         classifierAndExtensionToTypeMap = new HashMap<String, String>();
@@ -39,6 +41,27 @@ public class DefaultArtifactMappingProvi
         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 )
@@ -53,4 +76,9 @@ public class DefaultArtifactMappingProvi
         }
         return classifierAndExtensionToTypeMap.get( classifier + ":" + ext );
     }
+
+    public String mapTypeToExtension( String type )
+    {
+        return typeToExtensionMap.get( type );
+    }
 }



Mime
View raw message