]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1360] move type population into Maven 2 plugin
authorBrett Porter <brett@apache.org>
Wed, 10 Mar 2010 04:02:48 +0000 (04:02 +0000)
committerBrett Porter <brett@apache.org>
Wed, 10 Mar 2010 04:02:48 +0000 (04:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@921224 13f79535-47bb-0310-9956-ffa450edef68

23 files changed:
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml.md5
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/maven-metadata.xml.sha1
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-javadoc.jar [new file with mode: 0644]
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-javadoc.jar.md5 [new file with mode: 0644]
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-javadoc.jar.sha1 [new file with mode: 0644]
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-sources.jar [new file with mode: 0644]
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-sources.jar.md5 [new file with mode: 0644]
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-sources.jar.sha1 [new file with mode: 0644]
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.jar [new file with mode: 0644]
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.jar.md5 [new file with mode: 0644]
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.jar.sha1 [new file with mode: 0644]
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.pom [new file with mode: 0644]
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.pom.md5 [new file with mode: 0644]
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.pom.sha1 [new file with mode: 0644]
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml.md5
archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/maven-metadata.xml.sha1
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/ArtifactMappingProvider.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java

index d4f70fb8f9ffad51b9262a5cb413efea1e78d560..6f235cc768aa3a5d353b061d395a5d49a202418f 100644 (file)
@@ -19,6 +19,9 @@ package org.apache.maven.archiva.repository.content;
  * under the License.
  */
 
+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;
 import java.util.regex.Pattern;
@@ -40,21 +43,28 @@ public class ArtifactExtensionMapping
 
     private static final Pattern mavenPluginPattern = Pattern.compile( "^(maven-.*-plugin)|(.*-maven-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( "distribution-tgz", "tar.gz" );
-        typeToExtensionMap.put( "distribution-zip", "zip" );
         typeToExtensionMap.put( "java-source", "jar" );
-        typeToExtensionMap.put( "javadoc.jar", "jar" );
         typeToExtensionMap.put( "javadoc", "jar" );
-        typeToExtensionMap.put( "aspect", "jar" );
-        typeToExtensionMap.put( "uberjar", "jar" );
+        typeToExtensionMap.put( "test-jar", "jar" );
         typeToExtensionMap.put( MAVEN_PLUGIN, "jar" );
-        typeToExtensionMap.put( MAVEN_ONE_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 )
@@ -62,7 +72,7 @@ public class ArtifactExtensionMapping
         // Try specialized types first.
         if ( typeToExtensionMap.containsKey( type ) )
         {
-            return (String) typeToExtensionMap.get( type );
+            return typeToExtensionMap.get( type );
         }
 
         // Return type
@@ -88,36 +98,37 @@ public class ArtifactExtensionMapping
     public static String mapExtensionAndClassifierToType( String classifier, String extension,
                                                            String defaultExtension )
     {
-        if ( "sources".equals( classifier ) )
-        {
-            return "java-source";
-        }
-        else if ( "javadoc".equals( classifier ) )
+        String value = mapping.mapClassifierAndExtensionToType( classifier, extension );
+        if ( value == null )
         {
-            return "javadoc";
+            value = mapToMaven1Type( extension );
         }
-        return mapExtensionToType( extension, defaultExtension );
+        return value != null ? value : defaultExtension;
     }
 
     public static String mapExtensionToType( String extension )
     {
-        return mapExtensionToType( extension, extension );
+        String value = mapToMaven1Type( extension );
+
+        return value != null ? value : extension;
     }
 
-    private static String mapExtensionToType( String extension, String defaultExtension )
+    private static String mapToMaven1Type( String extension )
     {
+        // TODO: Maven 1 plugin
+        String value = null;
         if ( "tar.gz".equals( extension ) )
         {
-            return "distribution-tgz";
+            value = "distribution-tgz";
         }
         else  if ( "tar.bz2".equals( extension ) )
         {
-            return "distribution-bzip";
+            value = "distribution-bzip";
         }
         else  if ( "zip".equals( extension ) )
         {
-            return "distribution-zip";
+            value = "distribution-zip";
         }
-        return defaultExtension;
+        return value;
     }
 }
index 89f58d5257b6882abf3a382b45f9a8ca31d59be4..dee64e3fed3a7305e94dcd8363da156f69a683cf 100644 (file)
@@ -5,9 +5,9 @@
   <version>1.0-SNAPSHOT</version>
   <versioning>
     <snapshot>
-      <timestamp>20100308.230825</timestamp>
-      <buildNumber>1</buildNumber>
+      <timestamp>20100310.014828</timestamp>
+      <buildNumber>2</buildNumber>
     </snapshot>
-    <lastUpdated>20100308230825</lastUpdated>
+    <lastUpdated>20100310014828</lastUpdated>
   </versioning>
 </metadata>
diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-javadoc.jar b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-javadoc.jar
new file mode 100644 (file)
index 0000000..5aab069
Binary files /dev/null and b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-javadoc.jar differ
diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-javadoc.jar.md5 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-javadoc.jar.md5
new file mode 100644 (file)
index 0000000..f6be27c
--- /dev/null
@@ -0,0 +1 @@
+e034e44b0d9f3968ebfbc66c71b41ba0
\ No newline at end of file
diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-javadoc.jar.sha1 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-javadoc.jar.sha1
new file mode 100644 (file)
index 0000000..56fd634
--- /dev/null
@@ -0,0 +1 @@
+ca8d1408b05d125d0307dbd23063e5aa04235d35
\ No newline at end of file
diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-sources.jar b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-sources.jar
new file mode 100644 (file)
index 0000000..4863d8a
Binary files /dev/null and b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-sources.jar differ
diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-sources.jar.md5 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-sources.jar.md5
new file mode 100644 (file)
index 0000000..35b216f
--- /dev/null
@@ -0,0 +1 @@
+a47f0edab0271fc55a3db38098f5f78a
\ No newline at end of file
diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-sources.jar.sha1 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2-sources.jar.sha1
new file mode 100644 (file)
index 0000000..818b1e1
--- /dev/null
@@ -0,0 +1 @@
+af4c914ef8f80be2a8241fb4d40cff11f4348c0f
\ No newline at end of file
diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.jar b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.jar
new file mode 100644 (file)
index 0000000..3176aff
Binary files /dev/null and b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.jar differ
diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.jar.md5 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.jar.md5
new file mode 100644 (file)
index 0000000..3a6bb7d
--- /dev/null
@@ -0,0 +1 @@
+37786de9e272ed6db8541855e0e2d5dc
\ No newline at end of file
diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.jar.sha1 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.jar.sha1
new file mode 100644 (file)
index 0000000..0e08bb6
--- /dev/null
@@ -0,0 +1 @@
+bb1ca7834422926d0cb79ef303b715bc17f41661
\ No newline at end of file
diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.pom b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.pom
new file mode 100644 (file)
index 0000000..65ed8cf
--- /dev/null
@@ -0,0 +1,24 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>com.example.test</groupId>
+  <artifactId>test-artifact</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <name>test-artifact</name>
+  <url>http://maven.apache.org</url>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <distributionManagement>
+    <repository>
+      <id>test</id>
+      <url>file:${basedir}/repository</url>
+    </repository>
+  </distributionManagement>
+</project>
diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.pom.md5 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.pom.md5
new file mode 100644 (file)
index 0000000..78a9c26
--- /dev/null
@@ -0,0 +1 @@
+0612c49b1ac80983bfda08616330a4b8
\ No newline at end of file
diff --git a/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.pom.sha1 b/archiva-modules/metadata/test-repository/src/main/resources/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100310.014828-2.pom.sha1
new file mode 100644 (file)
index 0000000..f2385b6
--- /dev/null
@@ -0,0 +1 @@
+156d6062060743bf28df306e067914d3d692b571
\ No newline at end of file
index 2678fa1dc0aef0e14d5c487bd216d7d31bb4b7ff..2eee6af0dcfc26563fcf5fe0904c44a2c45476d9 100644 (file)
@@ -4,9 +4,10 @@
   <artifactId>test-artifact</artifactId>
   <version>1.0-SNAPSHOT</version>
   <versioning>
+    <release>1.0-SNAPSHOT</release>
     <versions>
       <version>1.0-SNAPSHOT</version>
     </versions>
-    <lastUpdated>20100308230825</lastUpdated>
+    <lastUpdated>20100310014828</lastUpdated>
   </versioning>
 </metadata>
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/ArtifactMappingProvider.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/ArtifactMappingProvider.java
new file mode 100644 (file)
index 0000000..b53bbdc
--- /dev/null
@@ -0,0 +1,25 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * 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.
+ */
+
+public interface ArtifactMappingProvider
+{
+    String mapClassifierAndExtensionToType( String classifier, String ext );
+}
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java
new file mode 100644 (file)
index 0000000..88048e9
--- /dev/null
@@ -0,0 +1,50 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @plexus.component role="org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider" role-hint="default"
+ */
+public class DefaultArtifactMappingProvider
+    implements ArtifactMappingProvider
+{
+    private final Map<String,String> classifierAndExtensionToTypeMap;
+
+    public DefaultArtifactMappingProvider()
+    {
+        classifierAndExtensionToTypeMap = new HashMap<String,String>();
+
+        // Maven 2.2.1 supplied types (excluding defaults where extension == type and no classifier)
+        classifierAndExtensionToTypeMap.put( "client:jar", "ejb-client" );
+        classifierAndExtensionToTypeMap.put( "sources:jar", "java-source" );
+        classifierAndExtensionToTypeMap.put( "javadoc:jar", "javadoc" );
+        classifierAndExtensionToTypeMap.put( "tests:jar", "test-jar" );
+    }
+
+    public String mapClassifierAndExtensionToType( String classifier, String ext )
+    {
+        classifier = classifier != null ? classifier : "";
+        ext = ext != null ? ext : "";
+        return classifierAndExtensionToTypeMap.get( classifier + ":" + ext );
+    }
+}
index e96fabfa3ae0005fca8b7588a28174ab53bc8c1a..2ff02478fce5f455ad73c203d61724ca219f90dd 100644 (file)
@@ -1,13 +1,5 @@
 package org.apache.archiva.metadata.repository.storage.maven2;
 
-import org.apache.archiva.metadata.model.ArtifactMetadata;
-import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
-import org.apache.maven.archiva.common.utils.VersionUtil;
-
-import java.io.File;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -27,6 +19,15 @@ import java.util.regex.Pattern;
  * under the License.
  */
 
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
+import org.apache.maven.archiva.common.utils.VersionUtil;
+
+import java.io.File;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /**
  * @plexus.component role="org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator" role-hint="maven2"
  */
@@ -39,6 +40,11 @@ public class Maven2RepositoryPathTranslator
 
     private static final Pattern TIMESTAMP_PATTERN = Pattern.compile( "([0-9]{8}.[0-9]{6})-([0-9]+).*" );
 
+    /**
+     * @plexus.requirement role="org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider"
+     */
+    private List<ArtifactMappingProvider> artifactMappingProviders;
+
     public File toFile( File basedir, String namespace, String projectId, String projectVersion, String filename )
     {
         return new File( basedir, toPath( namespace, projectId, projectVersion, filename ) );
@@ -180,6 +186,8 @@ public class Maven2RepositoryPathTranslator
                 m.matches();
                 String timestamp = m.group( 1 );
                 String buildNumber = m.group( 2 );
+                facet.setTimestamp( timestamp );
+                facet.setBuildNumber( Integer.valueOf( buildNumber ) );
                 version = idSubStrFromVersion.substring( 0, mainVersionLength ) + timestamp + "-" + buildNumber;
             }
             catch ( IllegalStateException e )
@@ -246,8 +254,25 @@ public class Maven2RepositoryPathTranslator
         metadata.setVersion( version );
 
         facet.setClassifier( classifier );
-        // TODO: migrate here from ArtifactExtensionMapping and make extensible
-//        facet.setType(  );
+
+        // we use our own provider here instead of directly accessing Maven's artifact handlers as it has no way
+        // to select the correct order to apply multiple extensions mappings to a preferred type
+        // TODO: this won't allow the user to decide order to apply them if there are conflicts or desired changes -
+        //       perhaps the plugins could register missing entries in configuration, then we just use configuration
+        //       here?
+
+        String type = null;
+        for ( ArtifactMappingProvider mapping : artifactMappingProviders )
+        {
+            type = mapping.mapClassifierAndExtensionToType( classifier, ext );
+            if ( type != null )
+            {
+                break;
+            }
+        }
+
+        // use extension as default
+        facet.setType( type != null ? type : ext );
         metadata.addFacet( facet );
 
         return metadata;
index b8580eaac020c762029d20077544c55109aa08f5..1084bc0f7a5cfa10779d9247be91f002d391d244 100644 (file)
@@ -133,7 +133,6 @@ public class Maven2RepositoryMetadataResolverTest
         assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
     }
 
-    // TODO: test snapshot, rest of artifacts
     public void testGetArtifactMetadata()
         throws Exception
     {
@@ -156,8 +155,7 @@ public class Maven2RepositoryMetadataResolverTest
         assertEquals( 0, facet.getBuildNumber() );
         assertNull( facet.getTimestamp() );
         assertEquals( "sources", facet.getClassifier() );
-        // TODO
-//        assertEquals( "java-source", facet.getType() );
+        assertEquals( "java-source", facet.getType() );
 
         artifactMetadata = artifacts.get( 1 );
         assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
@@ -165,8 +163,7 @@ public class Maven2RepositoryMetadataResolverTest
         assertEquals( 0, facet.getBuildNumber() );
         assertNull( facet.getTimestamp() );
         assertNull( facet.getClassifier() );
-        // TODO
-//        assertEquals( "jar", facet.getType() );
+        assertEquals( "jar", facet.getType() );
 
         artifactMetadata = artifacts.get( 2 );
         assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
@@ -174,8 +171,72 @@ public class Maven2RepositoryMetadataResolverTest
         assertEquals( 0, facet.getBuildNumber() );
         assertNull( facet.getTimestamp() );
         assertNull( facet.getClassifier() );
-        // TODO
-//        assertEquals( "pom", facet.getType() );
+        assertEquals( "pom", facet.getType() );
+    }
+
+    public void testGetArtifactMetadataSnapshots()
+        throws Exception
+    {
+        Collection<ArtifactMetadata> testArtifacts = resolver.getArtifacts( TEST_REPO_ID, "com.example.test",
+                                                                            "test-artifact", "1.0-SNAPSHOT" );
+        List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( testArtifacts );
+        Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
+        {
+            public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
+            {
+                return o1.getId().compareTo( o2.getId() );
+            }
+        } );
+
+        assertEquals( 6, artifacts.size() );
+
+        ArtifactMetadata artifactMetadata = artifacts.get( 0 );
+        assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
+        MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+        assertEquals( 1, facet.getBuildNumber() );
+        assertEquals( "20100308.230825", facet.getTimestamp() );
+        assertNull( facet.getClassifier() );
+        assertEquals( "jar", facet.getType() );
+
+        artifactMetadata = artifacts.get( 1 );
+        assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
+        facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+        assertEquals( 1, facet.getBuildNumber() );
+        assertEquals( "20100308.230825", facet.getTimestamp() );
+        assertNull( facet.getClassifier() );
+        assertEquals( "pom", facet.getType() );
+
+        artifactMetadata = artifacts.get( 2 );
+        assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
+        facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+        assertEquals( 2, facet.getBuildNumber() );
+        assertEquals( "20100310.014828", facet.getTimestamp() );
+        assertEquals( "javadoc", facet.getClassifier() );
+        assertEquals( "javadoc", facet.getType() );
+
+        artifactMetadata = artifacts.get( 3 );
+        assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
+        facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+        assertEquals( 2, facet.getBuildNumber() );
+        assertEquals( "20100310.014828", facet.getTimestamp() );
+        assertEquals( "sources", facet.getClassifier() );
+        assertEquals( "java-source", facet.getType() );
+
+        artifactMetadata = artifacts.get( 4 );
+        assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
+        facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+        assertEquals( 2, facet.getBuildNumber() );
+        assertEquals( "20100310.014828", facet.getTimestamp() );
+        assertNull( facet.getClassifier() );
+        assertEquals( "jar", facet.getType() );
+
+        artifactMetadata = artifacts.get( 5 );
+        assertEquals( "test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId() );
+        facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+        assertEquals( 2, facet.getBuildNumber() );
+        assertEquals( "20100310.014828", facet.getTimestamp() );
+        assertNull( facet.getClassifier() );
+        assertEquals( "pom", facet.getType() );
     }
 
     private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )