]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1282] start to implement maven metadata for artifacts, splitting from existing...
authorBrett Porter <brett@apache.org>
Tue, 9 Mar 2010 08:00:25 +0000 (08:00 +0000)
committerBrett Porter <brett@apache.org>
Tue, 9 Mar 2010 08:00:25 +0000 (08:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@920722 13f79535-47bb-0310-9956-ffa450edef68

17 files changed:
archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/artifactInfo.jspf
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/FacetedMetadata.java [new file with mode: 0644]
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionMetadata.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
archiva-modules/plugins/problem-reports/pom.xml
archiva-modules/plugins/problem-reports/src/test/resources/META-INF/spring-context.xml [deleted file]
archiva-modules/plugins/problem-reports/src/test/resources/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest-context.xml [new file with mode: 0644]
archiva-modules/pom.xml

index fec93b15eec628526df450e2d969c340ed857713..82d9adaa87f5f5ab1ae4d8eeacf1e78b8b2d0e96 100644 (file)
@@ -19,12 +19,6 @@ package org.apache.archiva.consumers.metadata;
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
 import org.apache.archiva.checksum.ChecksumAlgorithm;
 import org.apache.archiva.checksum.ChecksummedFile;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
@@ -51,6 +45,12 @@ import org.codehaus.plexus.registry.RegistryListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
 /**
  * Take an artifact off of disk and put it into the metadata repository.
  *
@@ -185,6 +185,7 @@ public class ArchivaMetadataCreationConsumer
             createVersionMetadata = true;
         }
 
+        // TODO: merge with storage implementation, add Maven facet        
         ArtifactMetadata artifactMeta = new ArtifactMetadata();
         artifactMeta.setRepositoryId( repository.getId() );
         artifactMeta.setNamespace( artifact.getGroupId() );
index 2c4fdc513c3a04b595e12f11de7d16051971a570..69c5b7cb9f4965d311e6272eaeef66e1178b6e80 100644 (file)
@@ -19,7 +19,7 @@
 
 <%@ taglib prefix="s" uri="/struts-tags" %>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
-<%@ taglib prefix="archiva"   uri="/WEB-INF/taglib.tld" %>
+<%@ taglib prefix="archiva" uri="/WEB-INF/taglib.tld" %>
 <%@ taglib prefix="redback" uri="http://plexus.codehaus.org/redback/taglib-1.0"  %>
 
 <html>
@@ -98,7 +98,7 @@
   <c:if test="${not empty projectVersions}">
     <%-- show shared project information (MRM-1041) TODO - share JSP code with artifactInfo.jspf --%>
 
-    <c:set var="mavenFacet" value="${sharedModel.facets['org.apache.archiva.metadata.repository.storage.maven2']}" />
+    <c:set var="mavenFacet" value="${sharedModel.facets['org.apache.archiva.metadata.repository.storage.maven2.project']}" />
     <h2>Versions</h2>
     <div id="nameColumn" class="versions">  
       <a class="expand" href="#">Artifact Info</a>      
 </div>
 
 </body>
-</html>
\ No newline at end of file
+</html>
index c256bf6435023b08f1f17569271c86bf47192f70..edfc8c8502827e7f6f849fda52ba8027988ce1c0 100644 (file)
@@ -43,7 +43,7 @@
   <blockquote>${model.description}</blockquote>
 </c:if>
 
-<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']}" />
 <table class="infoTable">
   <tr>
     <th>Repository</th>
index aee6c4b6b51e4f74a14c30ef486b3073753fad3b..b5b7307cda9f0941422ef172a3a2c58d0a692341 100644 (file)
@@ -22,6 +22,7 @@ package org.apache.archiva.metadata.model;
 import java.util.Date;
 
 public class ArtifactMetadata
+    extends FacetedMetadata
 {
     private String id;
     
diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/FacetedMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/FacetedMetadata.java
new file mode 100644 (file)
index 0000000..a3df5e3
--- /dev/null
@@ -0,0 +1,54 @@
+package org.apache.archiva.metadata.model;
+
+/*
+ * 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.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+public class FacetedMetadata
+{
+    private Map<String, MetadataFacet> facets = new HashMap<String, MetadataFacet>();
+
+    public void addFacet( MetadataFacet metadataFacet )
+    {
+        this.facets.put( metadataFacet.getFacetId(), metadataFacet );
+    }
+
+    public MetadataFacet getFacet( String facetId )
+    {
+        return this.facets.get( facetId );
+    }
+
+    public Map<String, MetadataFacet> getFacets()
+    {
+        return facets;
+    }
+
+    public Collection<MetadataFacet> getFacetList()
+    {
+        return this.facets.values();
+    }
+
+    public Collection<String> getFacetIds()
+    {
+        return this.facets.keySet();
+    }
+}
index 9973c45c4efaeb382eeeca105a360667f27a0e7a..b61135e783343281355d5a793bd2fe4d8db20e87 100644 (file)
@@ -20,12 +20,10 @@ package org.apache.archiva.metadata.model;
  */
 
 import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 public class ProjectVersionMetadata
+    extends FacetedMetadata
 {
     private String id;
 
@@ -45,8 +43,6 @@ public class ProjectVersionMetadata
 
     private List<License> licenses = new ArrayList<License>();
 
-    private Map<String, MetadataFacet> facets = new HashMap<String, MetadataFacet>();
-
     private List<MailingList> mailingLists = new ArrayList<MailingList>();
 
     private List<Dependency> dependencies = new ArrayList<Dependency>();
@@ -153,31 +149,6 @@ public class ProjectVersionMetadata
         this.licenses.add( license );
     }
 
-    public void addFacet( MetadataFacet metadataFacet )
-    {
-        this.facets.put( metadataFacet.getFacetId(), metadataFacet );
-    }
-
-    public MetadataFacet getFacet( String facetId )
-    {
-        return this.facets.get( facetId );
-    }
-
-    public Map<String, MetadataFacet> getFacets()
-    {
-        return facets;
-    }
-
-    public Collection<MetadataFacet> getFacetList()
-    {
-        return this.facets.values();
-    }
-
-    public Collection<String> getFacetIds()
-    {
-        return this.facets.keySet();
-    }
-
     public void setMailingLists( List<MailingList> mailingLists )
     {
         this.mailingLists = mailingLists;
index 39dc8144101797be62ddd4a3ce3363955b8fcf77..d712980f064950f90bcb7043b51d0e4ea15e275e 100644 (file)
@@ -149,6 +149,7 @@ public class Maven2RepositoryMetadataResolver
             }
         }
 
+        // TODO: won't work well with some other layouts, might need to convert artifact parts to ID by path translator
         String id = projectId + "-" + artifactVersion + ".pom";
         File file = pathTranslator.toFile( basedir, namespace, projectId, projectVersion, id );
 
@@ -499,7 +500,8 @@ public class Maven2RepositoryMetadataResolver
     private ArtifactMetadata getArtifactFromFile( String repoId, String namespace, String projectId,
                                                   String projectVersion, File file )
     {
-        ArtifactMetadata metadata = pathTranslator.getArtifactFromId( repoId, namespace, projectId, projectVersion, file.getName() );
+        ArtifactMetadata metadata = pathTranslator.getArtifactFromId( repoId, namespace, projectId, projectVersion,
+                                                                      file.getName() );
 
         metadata.setWhenGathered( new Date() );
         metadata.setFileLastModified( file.lastModified() );
index acec739cf68be89edd1052d244fb845163068f26..e67a8e121f732d2dae4b93e2ab4973b09b5a3ff7 100644 (file)
@@ -39,6 +39,8 @@ public class Maven2RepositoryPathTranslator
 
     private static final char GROUP_SEPARATOR = '.';
 
+    private static final Pattern TIMESTAMP_PATTERN = Pattern.compile( "([0-9]{8}.[0-9]{6})-([0-9]+).*" );
+
     public File toFile( File basedir, String namespace, String projectId, String projectVersion, String filename )
     {
         return new File( basedir, toPath( namespace, projectId, projectVersion, filename ) );
@@ -133,28 +135,6 @@ public class Maven2RepositoryPathTranslator
         return mainVersion + m.group( 1 );
     }
 
-    public ArtifactMetadata getArtifactFromId( String repoId, String namespace, String projectId, String projectVersion,
-                                               String id )
-    {
-        ArtifactMetadata metadata = new ArtifactMetadata();
-        metadata.setId( id );
-        metadata.setProject( projectId );
-        metadata.setNamespace( namespace );
-        metadata.setRepositoryId( repoId );
-
-        if ( VersionUtil.isGenericSnapshot( projectVersion ) )
-        {
-            String version = parseTimestampedVersionFromId( projectId, projectVersion, id );
-
-            metadata.setVersion( version );
-        }
-        else
-        {
-            metadata.setVersion( projectVersion );
-        }
-        return metadata;
-    }
-
     public ArtifactMetadata getArtifactForPath( String repoId, String relativePath )
     {
         String[] parts = relativePath.replace( '\\', '/' ).split( "/" );
@@ -171,31 +151,51 @@ public class Maven2RepositoryPathTranslator
         String artifactId = parts[--len];
         String groupId = StringUtils.join( Arrays.copyOfRange( parts, 0, len ), '.' );
 
-        if ( !id.startsWith( artifactId + "-" ) )
+        return getArtifactFromId( repoId, groupId, artifactId, baseVersion, id );
+    }
+
+    public ArtifactMetadata getArtifactFromId( String repoId, String namespace, String projectId, String projectVersion,
+                                               String id )
+    {
+        if ( !id.startsWith( projectId + "-" ) )
         {
             throw new IllegalArgumentException( "Not a valid artifact path in a Maven 2 repository, filename '" + id +
-                "' doesn't start with artifact ID '" + artifactId + "'" );
+                "' doesn't start with artifact ID '" + projectId + "'" );
         }
 
-        int index = artifactId.length() + 1;
+        MavenArtifactFacet facet = new MavenArtifactFacet();
+
+        int index = projectId.length() + 1;
         String version;
-        if ( id.substring( index ).startsWith( baseVersion ) && !VersionUtil.isUniqueSnapshot( baseVersion ) )
+        String idSubStrFromVersion = id.substring( index );
+        if ( idSubStrFromVersion.startsWith( projectVersion ) && !VersionUtil.isUniqueSnapshot( projectVersion ) )
         {
             // non-snapshot versions, or non-timestamped snapshot versions
-            version = baseVersion;
+            version = projectVersion;
         }
-        else if ( VersionUtil.isGenericSnapshot( baseVersion ) )
+        else if ( VersionUtil.isGenericSnapshot( projectVersion ) )
         {
             // timestamped snapshots
             try
             {
-                version = parseTimestampedVersionFromId( artifactId, baseVersion, id );
+                int mainVersionLength = projectVersion.length() - 8; // 8 is length of "SNAPSHOT"
+                if ( mainVersionLength == 0 )
+                {
+                    throw new IllegalArgumentException(
+                        "Timestamped snapshots must contain the main version, filename was '" + id + "'" );
+                }
+
+                Matcher m = TIMESTAMP_PATTERN.matcher( idSubStrFromVersion.substring( mainVersionLength ) );
+                m.matches();
+                String timestamp = m.group( 1 );
+                String buildNumber = m.group( 2 );
+                version = idSubStrFromVersion.substring( 0, mainVersionLength ) + timestamp + "-" + buildNumber;
             }
             catch ( IllegalStateException e )
             {
                 throw new IllegalArgumentException(
                     "Not a valid artifact path in a Maven 2 repository, filename '" + id +
-                        "' doesn't contain a timestamped version matching snapshot '" + baseVersion + "'" );
+                        "' doesn't contain a timestamped version matching snapshot '" + projectVersion + "'" );
             }
         }
         else
@@ -203,7 +203,7 @@ public class Maven2RepositoryPathTranslator
             // invalid
             throw new IllegalArgumentException(
                 "Not a valid artifact path in a Maven 2 repository, filename '" + id + "' doesn't contain version '" +
-                    baseVersion + "'" );
+                    projectVersion + "'" );
         }
 
         String classifier;
@@ -249,11 +249,16 @@ public class Maven2RepositoryPathTranslator
 
         ArtifactMetadata metadata = new ArtifactMetadata();
         metadata.setId( id );
-        metadata.setNamespace( groupId );
-        metadata.setProject( artifactId );
+        metadata.setNamespace( namespace );
+        metadata.setProject( projectId );
         metadata.setRepositoryId( repoId );
         metadata.setVersion( version );
-        // TODO: set classifier and extension on Maven facet
+
+        facet.setClassifier( classifier );
+        // TODO: migrate here from ArtifactExtensionMapping and make extensible
+//        facet.setType(  );
+        metadata.addFacet( facet );
+
         return metadata;
     }
 }
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java
new file mode 100644 (file)
index 0000000..f24ca0c
--- /dev/null
@@ -0,0 +1,112 @@
+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 org.apache.archiva.metadata.model.MetadataFacet;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class MavenArtifactFacet
+    implements MetadataFacet
+{
+    private String classifier;
+
+    private String type;
+
+    private String timestamp;
+
+    private int buildNumber;
+
+    public static final String FACET_ID = "org.apache.archiva.metadata.repository.storage.maven2.artifact";
+
+    public String getClassifier()
+    {
+        return classifier;
+    }
+
+    public void setClassifier( String classifier )
+    {
+        this.classifier = classifier;
+    }
+
+    public String getType()
+    {
+        return type;
+    }
+
+    public void setType( String type )
+    {
+        this.type = type;
+    }
+
+    public String getTimestamp()
+    {
+        return timestamp;
+    }
+
+    public void setTimestamp( String timestamp )
+    {
+        this.timestamp = timestamp;
+    }
+
+    public int getBuildNumber()
+    {
+        return buildNumber;
+    }
+
+    public void setBuildNumber( int buildNumber )
+    {
+        this.buildNumber = buildNumber;
+    }
+
+    public String getFacetId()
+    {
+        return FACET_ID;
+    }
+
+    public String getName()
+    {
+        // TODO: not needed, perhaps artifact/version metadata facet should be separate interface?
+        return null;
+    }
+
+    public Map<String, String> toProperties()
+    {
+        HashMap<String, String> properties = new HashMap<String, String>();
+        properties.put( FACET_ID + ":type", type );
+        properties.put( FACET_ID + ":classifier", classifier );
+        properties.put( FACET_ID + ":timestamp", timestamp );
+        properties.put( FACET_ID + ":buildNumber", Integer.toString( buildNumber ));
+        return properties;
+    }
+
+    public void fromProperties( Map<String, String> properties )
+    {
+        type = properties.get( FACET_ID + ":type" );
+        classifier = properties.get( FACET_ID + ":classifier" );
+        timestamp = properties.get( FACET_ID + ":timestamp" );
+        String buildNumber = properties.get( FACET_ID + ":buildNumber" );
+        if ( buildNumber != null )
+        {
+            this.buildNumber = Integer.valueOf( buildNumber );
+        }
+    }
+}
index 0145b94826eb8a9c939d784d4607297fdc15b648..93df5a1e117e22887dffa11a7db15941d757125d 100644 (file)
@@ -19,11 +19,11 @@ package org.apache.archiva.metadata.repository.storage.maven2;
  * under the License.
  */
 
+import org.apache.archiva.metadata.model.MetadataFacet;
+
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.archiva.metadata.model.MetadataFacet;
-
 public class MavenProjectFacet
     implements MetadataFacet
 {
@@ -35,7 +35,7 @@ public class MavenProjectFacet
 
     private String packaging;
 
-    public static final String FACET_ID = "org.apache.archiva.metadata.repository.storage.maven2";
+    public static final String FACET_ID = "org.apache.archiva.metadata.repository.storage.maven2.project";
 
     public String getGroupId()
     {
index e874b3f40d4bd3ff280b4c8ccb3b60486fe5742d..81a99b91012fc9cbeec91ecfda34a59eccfe8c77 100644 (file)
@@ -23,7 +23,7 @@ import org.apache.archiva.metadata.model.MetadataFacet;
 import org.apache.archiva.metadata.model.MetadataFacetFactory;
 
 /**
- * @plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.repository.storage.maven2"
+ * @plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.repository.storage.maven2.project"
  */
 public class MavenProjectFacetFactory
     implements MetadataFacetFactory
index 72d82ef7141c163d1843c4669cc85f16999aca75..6ee6495409e369960675251576da17b480127981 100644 (file)
@@ -19,14 +19,9 @@ package org.apache.archiva.metadata.repository.storage.maven2;
  * under the License.
  */
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.Dependency;
+import org.apache.archiva.metadata.model.FacetedMetadata;
 import org.apache.archiva.metadata.model.License;
 import org.apache.archiva.metadata.model.MailingList;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
@@ -40,6 +35,13 @@ import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
 public class Maven2RepositoryMetadataResolverTest
     extends PlexusInSpringTestCase
 {
@@ -80,8 +82,8 @@ public class Maven2RepositoryMetadataResolverTest
     public void testGetProjectVersionMetadata()
         throws Exception
     {
-        ProjectVersionMetadata metadata =
-            resolver.getProjectVersion( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" );
+        ProjectVersionMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "org.apache.archiva",
+                                                                      "archiva-common", "1.2.1" );
         MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
         assertEquals( "jar", facet.getPackaging() );
         assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
@@ -131,6 +133,44 @@ public class Maven2RepositoryMetadataResolverTest
         assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
     }
 
+    // TODO: test snapshot, rest of artifacts
+    public void testGetArtifactMetadata()
+        throws Exception
+    {
+        Collection<ArtifactMetadata> springArtifacts = resolver.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus",
+                                                                              "plexus-spring", "1.2" );
+        List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( springArtifacts );
+
+        assertEquals( 3, artifacts.size() );
+
+        ArtifactMetadata artifactMetadata = artifacts.get( 0 );
+        assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
+        MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+        assertEquals( 0, facet.getBuildNumber() );
+        assertNull( facet.getTimestamp() );
+        assertEquals( "sources", facet.getClassifier() );
+        // TODO
+//        assertEquals( "java-source", facet.getType() );
+
+        artifactMetadata = artifacts.get( 1 );
+        assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
+        facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+        assertEquals( 0, facet.getBuildNumber() );
+        assertNull( facet.getTimestamp() );
+        assertNull( facet.getClassifier() );
+        // TODO
+//        assertEquals( "jar", facet.getType() );
+
+        artifactMetadata = artifacts.get( 2 );
+        assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
+        facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+        assertEquals( 0, facet.getBuildNumber() );
+        assertNull( facet.getTimestamp() );
+        assertNull( facet.getClassifier() );
+        // TODO
+//        assertEquals( "pom", facet.getType() );
+    }
+
     private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
     {
         assertDependency( dependency, groupId, artifactId, version, "compile" );
@@ -151,8 +191,8 @@ public class Maven2RepositoryMetadataResolverTest
     public void testGetProjectVersionMetadataForTimestampedSnapshot()
         throws Exception
     {
-        ProjectVersionMetadata metadata =
-            resolver.getProjectVersion( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" );
+        ProjectVersionMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "org.apache", "apache",
+                                                                      "5-SNAPSHOT" );
         MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
         assertEquals( "pom", facet.getPackaging() );
         assertEquals( "http://www.apache.org/", metadata.getUrl() );
@@ -188,24 +228,24 @@ public class Maven2RepositoryMetadataResolverTest
     public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
         throws Exception
     {
-        ProjectVersionMetadata metadata =
-            resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" );
+        FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-metadata",
+                                                               "1.0-SNAPSHOT" );
         assertNull( metadata );
     }
 
     public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
         throws Exception
     {
-        ProjectVersionMetadata metadata =
-            resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "malformed-metadata", "1.0-SNAPSHOT" );
+        FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "malformed-metadata",
+                                                               "1.0-SNAPSHOT" );
         assertNull( metadata );
     }
 
     public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
         throws Exception
     {
-        ProjectVersionMetadata metadata =
-            resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "incomplete-metadata", "1.0-SNAPSHOT" );
+        FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "incomplete-metadata",
+                                                               "1.0-SNAPSHOT" );
         assertNull( metadata );
     }
 
@@ -221,10 +261,11 @@ public class Maven2RepositoryMetadataResolverTest
         }
         catch ( MetadataResolutionException e )
         {
-            assertFalse( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
-            RepositoryProblemFacet facet =
-                (RepositoryProblemFacet) metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID,
-                                                                              "com.example.test/invalid-pom/1.0" );
+            assertFalse( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+                                                               RepositoryProblemFacet.FACET_ID ).isEmpty() );
+            RepositoryProblemFacet facet = (RepositoryProblemFacet) metadataRepository.getMetadataFacet( TEST_REPO_ID,
+                                                                                                         RepositoryProblemFacet.FACET_ID,
+                                                                                                         "com.example.test/invalid-pom/1.0" );
             assertEquals( "invalid-pom", facet.getProblem() );
         }
     }
@@ -241,10 +282,11 @@ public class Maven2RepositoryMetadataResolverTest
         }
         catch ( MetadataResolutionException e )
         {
-            assertFalse( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
-            RepositoryProblemFacet facet =
-                (RepositoryProblemFacet) metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID,
-                                                                              "com.example.test/mislocated-pom/1.0" );
+            assertFalse( metadataRepository.getMetadataFacets( TEST_REPO_ID,
+                                                               RepositoryProblemFacet.FACET_ID ).isEmpty() );
+            RepositoryProblemFacet facet = (RepositoryProblemFacet) metadataRepository.getMetadataFacet( TEST_REPO_ID,
+                                                                                                         RepositoryProblemFacet.FACET_ID,
+                                                                                                         "com.example.test/mislocated-pom/1.0" );
             assertEquals( "mislocated-pom", facet.getProblem() );
         }
     }
@@ -254,14 +296,13 @@ public class Maven2RepositoryMetadataResolverTest
     {
         assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
 
-        ProjectVersionMetadata metadata =
-            resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
+        FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
         assertNull( metadata );
 
         assertFalse( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
-        RepositoryProblemFacet facet =
-            (RepositoryProblemFacet) metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID,
-                                                                          "com.example.test/missing-pom/1.0" );
+        RepositoryProblemFacet facet = (RepositoryProblemFacet) metadataRepository.getMetadataFacet( TEST_REPO_ID,
+                                                                                                     RepositoryProblemFacet.FACET_ID,
+                                                                                                     "com.example.test/missing-pom/1.0" );
         assertEquals( "missing-pom", facet.getProblem() );
 
     }
@@ -280,12 +321,12 @@ public class Maven2RepositoryMetadataResolverTest
         assertEquals( Arrays.asList( "apache", "codehaus" ), resolver.getNamespaces( TEST_REPO_ID, "org" ) );
         assertEquals( Arrays.asList( "archiva", "maven" ), resolver.getNamespaces( TEST_REPO_ID, "org.apache" ) );
         assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID, "org.apache.archiva" ) );
-        assertEquals( Arrays.asList( "plugins", "shared" ),
-                      resolver.getNamespaces( TEST_REPO_ID, "org.apache.maven" ) );
-        assertEquals( Collections.<String>emptyList(),
-                      resolver.getNamespaces( TEST_REPO_ID, "org.apache.maven.plugins" ) );
-        assertEquals( Collections.<String>emptyList(),
-                      resolver.getNamespaces( TEST_REPO_ID, "org.apache.maven.shared" ) );
+        assertEquals( Arrays.asList( "plugins", "shared" ), resolver.getNamespaces( TEST_REPO_ID,
+                                                                                    "org.apache.maven" ) );
+        assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID,
+                                                                               "org.apache.maven.plugins" ) );
+        assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID,
+                                                                               "org.apache.maven.shared" ) );
 
         assertEquals( Arrays.asList( "plexus" ), resolver.getNamespaces( TEST_REPO_ID, "org.codehaus" ) );
         assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID, "org.codehaus.plexus" ) );
@@ -303,45 +344,48 @@ public class Maven2RepositoryMetadataResolverTest
         assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
                       resolver.getProjects( TEST_REPO_ID, "org.apache.archiva" ) );
         assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "org.apache.maven" ) );
-        assertEquals( Collections.<String>emptyList(),
-                      resolver.getProjects( TEST_REPO_ID, "org.apache.maven.plugins" ) );
-        assertEquals( Arrays.asList( "maven-downloader" ),
-                      resolver.getProjects( TEST_REPO_ID, "org.apache.maven.shared" ) );
+        assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID,
+                                                                             "org.apache.maven.plugins" ) );
+        assertEquals( Arrays.asList( "maven-downloader" ), resolver.getProjects( TEST_REPO_ID,
+                                                                                 "org.apache.maven.shared" ) );
     }
 
     public void testGetProjectVersions()
     {
-        assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
-                      resolver.getProjectVersions( TEST_REPO_ID, "com.example.test", "incomplete-metadata" ) );
-        assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
-                      resolver.getProjectVersions( TEST_REPO_ID, "com.example.test", "malformed-metadata" ) );
-        assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
-                      resolver.getProjectVersions( TEST_REPO_ID, "com.example.test", "missing-metadata" ) );
-        assertEquals( Arrays.asList( "1.0" ),
-                      resolver.getProjectVersions( TEST_REPO_ID, "com.example.test", "invalid-pom" ) );
-
-        assertEquals( Arrays.asList( "4", "5-SNAPSHOT" ),
-                      resolver.getProjectVersions( TEST_REPO_ID, "org.apache", "apache" ) );
-
-        assertEquals( Arrays.asList( "1.2.1" ),
-                      resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva" ) );
-        assertEquals( Arrays.asList( "1.2.1" ),
-                      resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-base" ) );
-        assertEquals( Arrays.asList( "1.2.1" ),
-                      resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-common" ) );
-        assertEquals( Arrays.asList( "1.2.1" ),
-                      resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-modules" ) );
-        assertEquals( Arrays.asList( "3" ),
-                      resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-parent" ) );
-
-        assertEquals( Collections.<String>emptyList(),
-                      resolver.getProjectVersions( TEST_REPO_ID, "org.apache.maven.shared", "maven-downloader" ) );
+        assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "com.example.test",
+                                                                                    "incomplete-metadata" ) );
+        assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "com.example.test",
+                                                                                    "malformed-metadata" ) );
+        assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "com.example.test",
+                                                                                    "missing-metadata" ) );
+        assertEquals( Arrays.asList( "1.0" ), resolver.getProjectVersions( TEST_REPO_ID, "com.example.test",
+                                                                           "invalid-pom" ) );
+
+        assertEquals( Arrays.asList( "4", "5-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache",
+                                                                                       "apache" ) );
+
+        assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
+                                                                             "archiva" ) );
+        assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
+                                                                             "archiva-base" ) );
+        assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
+                                                                             "archiva-common" ) );
+        assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
+                                                                             "archiva-modules" ) );
+        assertEquals( Arrays.asList( "3" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
+                                                                         "archiva-parent" ) );
+
+        assertEquals( Collections.<String>emptyList(), resolver.getProjectVersions( TEST_REPO_ID,
+                                                                                    "org.apache.maven.shared",
+                                                                                    "maven-downloader" ) );
     }
 
     public void testGetArtifacts()
     {
-        List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
-            resolver.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2" ) );
+        List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.getArtifacts( TEST_REPO_ID,
+                                                                                                   "org.codehaus.plexus",
+                                                                                                   "plexus-spring",
+                                                                                                   "1.2" ) );
         assertEquals( 3, artifacts.size() );
         Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
         {
@@ -359,10 +403,12 @@ public class Maven2RepositoryMetadataResolverTest
 
     public void testGetArtifactsFiltered()
     {
-        ExcludesFilter<String> filter =
-            new ExcludesFilter<String>( Collections.singletonList( "plexus-spring-1.2.pom" ) );
-        List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
-            resolver.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", filter ) );
+        ExcludesFilter<String> filter = new ExcludesFilter<String>( Collections.singletonList(
+            "plexus-spring-1.2.pom" ) );
+        List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.getArtifacts( TEST_REPO_ID,
+                                                                                                   "org.codehaus.plexus",
+                                                                                                   "plexus-spring",
+                                                                                                   "1.2", filter ) );
         assertEquals( 2, artifacts.size() );
         Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
         {
@@ -378,8 +424,10 @@ public class Maven2RepositoryMetadataResolverTest
 
     public void testGetArtifactsTimestampedSnapshots()
     {
-        List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
-            resolver.getArtifacts( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" ) );
+        List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.getArtifacts( TEST_REPO_ID,
+                                                                                                   "com.example.test",
+                                                                                                   "missing-metadata",
+                                                                                                   "1.0-SNAPSHOT" ) );
         assertEquals( 1, artifacts.size() );
 
         ArtifactMetadata artifact = artifacts.get( 0 );
index 6565f7512530a5d0d1f49151474b5b578c25f0ed..18cbdca20808838145152da52ff1bc03cadc39ef 100644 (file)
@@ -423,6 +423,7 @@ public class FileMetadataRepository
                 String id = tok.nextToken();
 
                 ArtifactMetadata artifact = artifacts.get( id );
+                // TODO: facets (&test)
                 if ( artifact == null )
                 {
                     artifact = new ArtifactMetadata();
index c1f39808d7d086888e50471b76e800713f019c3e..5e64c86c5fc93658467d872a615fffd45fd5e966 100644 (file)
@@ -57,7 +57,6 @@
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-all</artifactId>
-      <version>1.8.3</version>
       <scope>test</scope>
     </dependency>
     <dependency>
diff --git a/archiva-modules/plugins/problem-reports/src/test/resources/META-INF/spring-context.xml b/archiva-modules/plugins/problem-reports/src/test/resources/META-INF/spring-context.xml
deleted file mode 100644 (file)
index 0aafa26..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  ~ 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.
-  -->
-
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
-  <bean id="metadataRepositoryFactory" class="org.apache.archiva.reports.consumers.MockitoFactory"
-        name="metadataRepository">
-    <constructor-arg value="org.apache.archiva.metadata.repository.MetadataRepository"/>
-  </bean>
-  <bean id="repositoryPathTranslatorFactory" class="org.apache.archiva.reports.consumers.MockitoFactory"
-        name="repositoryPathTranslator#maven2">
-    <constructor-arg value="org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator"/>
-  </bean>
-</beans>
\ No newline at end of file
diff --git a/archiva-modules/plugins/problem-reports/src/test/resources/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest-context.xml b/archiva-modules/plugins/problem-reports/src/test/resources/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest-context.xml
new file mode 100644 (file)
index 0000000..0aafa26
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+  <bean id="metadataRepositoryFactory" class="org.apache.archiva.reports.consumers.MockitoFactory"
+        name="metadataRepository">
+    <constructor-arg value="org.apache.archiva.metadata.repository.MetadataRepository"/>
+  </bean>
+  <bean id="repositoryPathTranslatorFactory" class="org.apache.archiva.reports.consumers.MockitoFactory"
+        name="repositoryPathTranslator#maven2">
+    <constructor-arg value="org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator"/>
+  </bean>
+</beans>
\ No newline at end of file
index 03c52a0d3a227d8ba6493b7becb8b913adc99691..1ab9386fce29ab5786c8be23c69f2ea3ecda0a27 100644 (file)
@@ -16,7 +16,9 @@
   ~ KIND, either express or implied.  See the License for the
   ~ specific language governing permissions and limitations
   ~ under the License.
-  --><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">
+  -->
+<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">
   <parent>
     <artifactId>archiva</artifactId>
     <groupId>org.apache.archiva</groupId>
     <module>metadata</module>
     <module>plugins</module>
   </modules>
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.mockito</groupId>
+        <artifactId>mockito-all</artifactId>
+        <version>1.8.3</version>
+        <scope>test</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
   <build>
     <pluginManagement>
       <plugins>
         </configuration>
       </plugin>
       -->
-<!-- TODO: OOME
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>findbugs-maven-plugin</artifactId>
-        <version>1.1.1</version>
-      </plugin>
--->
+      <!-- TODO: OOME
+            <plugin>
+              <groupId>org.codehaus.mojo</groupId>
+              <artifactId>findbugs-maven-plugin</artifactId>
+              <version>1.1.1</version>
+            </plugin>
+      -->
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>taglist-maven-plugin</artifactId>