archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r888164 [2/2] - in /archiva/branches/MRM-1025: ./ archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/ archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/ archiva-modules/archiva-...
Date Mon, 07 Dec 2009 22:32:20 GMT
Modified: archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java?rev=888164&r1=888163&r2=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java Mon Dec  7 22:32:10 2009
@@ -19,12 +19,19 @@
  * under the License.
  */
 
+import java.util.Arrays;
+
 import com.meterware.servletunit.ServletRunner;
 import com.meterware.servletunit.ServletUnitClient;
 import com.opensymphony.xwork2.Action;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.stats.DefaultRepositoryStatisticsManager;
+import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
+import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
 import org.codehaus.redback.integration.interceptor.SecureActionException;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.easymock.MockControl;
 
 /**
  * Test the repositories action returns the correct data.
@@ -48,6 +55,24 @@
     public void testGetRepositories()
         throws Exception
     {
+        MockControl control = MockControl.createControl( MetadataRepository.class );
+        MetadataRepository metadataRepository = (MetadataRepository) control.getMock();
+        control.expectAndReturn( metadataRepository.getMetadataFacets( "internal", RepositoryStatistics.FACET_ID ),
+                                 Arrays.asList( "20091125.123456.678" ) );
+        control.expectAndReturn(
+            metadataRepository.getMetadataFacet( "internal", RepositoryStatistics.FACET_ID, "20091125.123456.678" ),
+            new RepositoryStatistics() );
+        control.expectAndReturn( metadataRepository.getMetadataFacets( "snapshots", RepositoryStatistics.FACET_ID ),
+                                 Arrays.asList( "20091112.012345.012" ) );
+        control.expectAndReturn(
+            metadataRepository.getMetadataFacet( "snapshots", RepositoryStatistics.FACET_ID, "20091112.012345.012" ),
+            new RepositoryStatistics() );
+        control.replay();
+
+        DefaultRepositoryStatisticsManager statsManager =
+            (DefaultRepositoryStatisticsManager) lookup( RepositoryStatisticsManager.class );
+        statsManager.setMetadataRepository( metadataRepository );
+
         ServletRunner sr = new ServletRunner();
         ServletUnitClient sc = sr.newClient();
 
@@ -66,6 +91,8 @@
         assertEquals( 2, action.getManagedRepositories().size() );
         assertEquals( 2, action.getRemoteRepositories().size() );
         assertEquals( 2, action.getRepositoryStatistics().size() );
+
+        control.verify();
     }
 
     public void testSecureActionBundle()

Added: archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java?rev=888164&view=auto
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java (added)
+++ archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java Mon Dec  7 22:32:10 2009
@@ -0,0 +1,121 @@
+package org.apache.archiva.metadata.repository;
+
+/*
+ * 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.Collections;
+import java.util.List;
+
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.MetadataFacet;
+import org.apache.archiva.metadata.model.ProjectMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
+
+public class TestMetadataRepository
+    implements MetadataRepository
+{
+    public ProjectMetadata getProject( String repoId, String namespace, String projectId )
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
+                                                     String projectVersion )
+        throws MetadataResolverException
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
+                                                   String projectVersion )
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
+                                                                     String projectVersion )
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Collection<String> getRootNamespaces( String repoId )
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Collection<String> getNamespaces( String repoId, String namespace )
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Collection<String> getProjects( String repoId, String namespace )
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
+        throws MetadataResolverException
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void updateProject( String repoId, ProjectMetadata project )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void updateArtifact( String repoId, String namespace, String projectId, String projectVersion,
+                                ArtifactMetadata artifactMeta )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void updateProjectVersion( String repoId, String namespace, String projectId, ProjectVersionMetadata versionMetadata )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void updateProjectReference( String repoId, String namespace, String projectId, String projectVersion,
+                                        ProjectVersionReference reference )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void updateNamespace( String repoId, String namespace )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public List<String> getMetadataFacets( String repodId, String facetId )
+    {
+        return Collections.emptyList();
+    }
+
+    public MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name )
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void addMetadataFacet( String repositoryId, String facetId, String name, MetadataFacet metadataFacet )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+}

Modified: archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webdav/src/test/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webdav/src/test/resources/META-INF/plexus/components.xml?rev=888164&r1=888163&r2=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webdav/src/test/resources/META-INF/plexus/components.xml (original)
+++ archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webdav/src/test/resources/META-INF/plexus/components.xml Mon Dec  7 22:32:10 2009
@@ -29,5 +29,10 @@
         <resource>archiva-mime-types.txt</resource>
       </configuration>
     </component>
+
+    <component>
+      <role>org.apache.archiva.metadata.repository.MetadataRepository</role>
+      <implementation>org.apache.archiva.metadata.repository.TestMetadataRepository</implementation>
+    </component>
   </components>
 </component-set>
\ No newline at end of file

Modified: archiva/branches/MRM-1025/archiva-modules/metadata/content-model.txt
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/metadata/content-model.txt?rev=888164&r1=888163&r2=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/metadata/content-model.txt (original)
+++ archiva/branches/MRM-1025/archiva-modules/metadata/content-model.txt Mon Dec  7 22:32:10 2009
@@ -94,35 +94,60 @@
         |                   |-- maven:groupId=
         |                   |-- maven:plugins.compiler.artifactId=
         |                   `-- maven:plugins.compiler.name=
-        `-- references/
-            `-- org/
-                `-- apache/
-                    `-- archiva/
-                        |-- parent/
-                        |   `-- 1/
-                        |       `-- references/
-                        |           `-- org/
-                        |               `-- apache/
-                        |                   `-- archiva/
-                        |                       |-- platform/
-                        |                       |   `-- scanner/
-                        |                       |       `-- 1.0-SNAPSHOT/
-                        |                       |           `-- referenceType=parent
-                        |                       `-- web/
-                        |                           `-- webapp/
-                        |                               `-- 1.0-SNAPSHOT/
-                        |                                   `-- referenceType=parent
-                        `-- platform/
-                            `-- scanner/
-                                `-- 1.0-SNAPSHOT/
-                                    `-- references/
-                                        `-- org/
-                                            `-- apache/
-                                                `-- archiva/
-                                                    `-- web/
-                                                        `-- webapp/
-                                                            `-- 1.0-SNAPSHOT/
-                                                                `-- referenceType=dependency
+        |-- references/
+        |   `-- org/
+        |       `-- apache/
+        |           `-- archiva/
+        |               |-- parent/
+        |               |   `-- 1/
+        |               |       `-- references/
+        |               |           `-- org/
+        |               |               `-- apache/
+        |               |                   `-- archiva/
+        |               |                       |-- platform/
+        |               |                       |   `-- scanner/
+        |               |                       |       `-- 1.0-SNAPSHOT/
+        |               |                       |           `-- referenceType=parent
+        |               |                       `-- web/
+        |               |                           `-- webapp/
+        |               |                               `-- 1.0-SNAPSHOT/
+        |               |                                   `-- referenceType=parent
+        |               `-- platform/
+        |                   `-- scanner/
+        |                       `-- 1.0-SNAPSHOT/
+        |                           `-- references/
+        |                               `-- org/
+        |                                   `-- apache/
+        |                                       `-- archiva/
+        |                                           `-- web/
+        |                                               `-- webapp/
+        |                                                   `-- 1.0-SNAPSHOT/
+        |                                                       `-- referenceType=dependency
+        `-- stats/
+            `-- 2009/
+                `-- 12/
+                    |-- 02/
+                    |   `-- 23/
+                    |       `-- 47/
+                    |           `-- 00/
+                    |               |-- scanEndTime=
+                    |               |-- scanStartTime=
+                    |               |-- totalArtifactCount=
+                    |               |-- totalArtifactFileSize=
+                    |               |-- totalFileCount=
+                    |               |-- totalGroupCount=
+                    |               `-- totalProjectCount=
+                    `-- 03/
+                        `-- 09/
+                            `-- 00/
+                                `-- 00/
+                                    |-- scanEndTime=
+                                    |-- scanStartTime=
+                                    |-- totalArtifactCount=
+                                    |-- totalArtifactFileSize=
+                                    |-- totalFileCount=
+                                    |-- totalGroupCount=
+                                    `-- totalProjectCount=
 
 (To update - run "tree --dirstfirst -F" on the unpacked content-model.zip from the sandbox)
 
@@ -179,6 +204,9 @@
 *) some of the above needs to be reviewed before going into production. For example:
    - the maven specific aspects of dependencies should become a faceted part of the content
    - more of the metadata might be faceted in general, keeping the content model basic by default
+   - determine if any of the stats can be derived by functions of the content repository rather than storing and trying
+     to keep them up to date. Historical data might be retained by versioning and taking a snapshot at a given point in
+     time. The current approach of tying them to the scanning process is not optimal
    - the storing of metadata as 0-indexed lists would be better in as child nodes. This might require additional levels
      in the current repository (.../scanner/versions/1.0-SNAPSHOT/artifacts/scanner-1.0-20091120.012345-1.pom), or
      for listed information to be in a separate tree

Copied: archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacet.java (from r887042, archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionFacet.java)
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacet.java?p2=archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacet.java&p1=archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionFacet.java&r1=887042&r2=888164&rev=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionFacet.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacet.java Mon Dec  7 22:32:10 2009
@@ -21,7 +21,7 @@
 
 import java.util.Map;
 
-public interface ProjectVersionFacet
+public interface MetadataFacet
 {
     String getFacetId();
 

Propchange: archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacetFactory.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacetFactory.java?rev=888164&r1=888163&r2=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacetFactory.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacetFactory.java Mon Dec  7 22:32:10 2009
@@ -21,5 +21,5 @@
 
 public interface MetadataFacetFactory
 {
-    ProjectVersionFacet createProjectVersionFacet();
+    MetadataFacet createMetadataFacet();
 }

Modified: archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionMetadata.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionMetadata.java?rev=888164&r1=888163&r2=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionMetadata.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionMetadata.java Mon Dec  7 22:32:10 2009
@@ -45,7 +45,7 @@
 
     private List<License> licenses = new ArrayList<License>();
 
-    private Map<String, ProjectVersionFacet> facets = new HashMap<String, ProjectVersionFacet>();
+    private Map<String, MetadataFacet> facets = new HashMap<String, MetadataFacet>();
 
     private List<MailingList> mailingLists = new ArrayList<MailingList>();
 
@@ -151,22 +151,22 @@
         this.licenses.add( license );
     }
 
-    public void addFacet( ProjectVersionFacet projectVersionFacet )
+    public void addFacet( MetadataFacet metadataFacet )
     {
-        this.facets.put( projectVersionFacet.getFacetId(), projectVersionFacet );
+        this.facets.put( metadataFacet.getFacetId(), metadataFacet );
     }
 
-    public ProjectVersionFacet getFacet( String facetId )
+    public MetadataFacet getFacet( String facetId )
     {
         return this.facets.get( facetId );
     }
 
-    public Map<String, ProjectVersionFacet> getFacets()
+    public Map<String, MetadataFacet> getFacets()
     {
         return facets;
     }
 
-    public Collection<ProjectVersionFacet> getFacetList()
+    public Collection<MetadataFacet> getFacetList()
     {
         return this.facets.values();
     }

Modified: archiva/branches/MRM-1025/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java?rev=888164&r1=888163&r2=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java Mon Dec  7 22:32:10 2009
@@ -19,7 +19,10 @@
  * under the License.
  */
 
+import java.util.List;
+
 import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.MetadataFacet;
 import org.apache.archiva.metadata.model.ProjectMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionReference;
@@ -45,4 +48,10 @@
                                  ProjectVersionReference reference );
 
     void updateNamespace( String repoId, String namespace );
+
+    List<String> getMetadataFacets( String repodId, String facetId );
+
+    MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name );
+
+    void addMetadataFacet( String repositoryId, String facetId, String name, MetadataFacet metadataFacet );
 }

Modified: archiva/branches/MRM-1025/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java?rev=888164&r1=888163&r2=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java Mon Dec  7 22:32:10 2009
@@ -22,10 +22,10 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.archiva.metadata.model.ProjectVersionFacet;
+import org.apache.archiva.metadata.model.MetadataFacet;
 
 public class MavenProjectFacet
-    implements ProjectVersionFacet
+    implements MetadataFacet
 {
     private String groupId;
 

Modified: archiva/branches/MRM-1025/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java?rev=888164&r1=888163&r2=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java Mon Dec  7 22:32:10 2009
@@ -19,8 +19,8 @@
  * under the License.
  */
 
+import org.apache.archiva.metadata.model.MetadataFacet;
 import org.apache.archiva.metadata.model.MetadataFacetFactory;
-import org.apache.archiva.metadata.model.ProjectVersionFacet;
 
 /**
  * @plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.repository.storage.maven2"
@@ -28,7 +28,7 @@
 public class MavenProjectFacetFactory
     implements MetadataFacetFactory
 {
-    public ProjectVersionFacet createProjectVersionFacet()
+    public MetadataFacet createMetadataFacet()
     {
         return new MavenProjectFacet();
     }

Modified: archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java?rev=888164&r1=888163&r2=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java Mon Dec  7 22:32:10 2009
@@ -27,6 +27,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -40,10 +41,10 @@
 import org.apache.archiva.metadata.model.IssueManagement;
 import org.apache.archiva.metadata.model.License;
 import org.apache.archiva.metadata.model.MailingList;
+import org.apache.archiva.metadata.model.MetadataFacet;
 import org.apache.archiva.metadata.model.MetadataFacetFactory;
 import org.apache.archiva.metadata.model.Organization;
 import org.apache.archiva.metadata.model.ProjectMetadata;
-import org.apache.archiva.metadata.model.ProjectVersionFacet;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionReference;
 import org.apache.archiva.metadata.model.Scm;
@@ -78,6 +79,8 @@
 
     private static final String NAMESPACE_METADATA_KEY = "namespace-metadata";
 
+    private static final String METADATA_KEY = "metadata";
+
     public void updateProject( String repoId, ProjectMetadata project )
     {
         updateProject( repoId, project.getNamespace(), project.getId() );
@@ -95,7 +98,6 @@
             properties.setProperty( "namespace", namespace );
             properties.setProperty( "id", id );
             writeProperties( properties, new File( namespaceDirectory, id ), PROJECT_METADATA_KEY );
-
         }
         catch ( IOException e )
         {
@@ -112,7 +114,7 @@
         File directory =
             new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + versionMetadata.getId() );
 
-        Properties properties = readProperties( directory, PROJECT_VERSION_METADATA_KEY );
+        Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
         // remove properties that are not references or artifacts
         for ( String name : properties.stringPropertyNames() )
         {
@@ -180,7 +182,7 @@
         facetIds.addAll( Arrays.asList( properties.getProperty( "facetIds", "" ).split( "," ) ) );
         properties.setProperty( "facetIds", join( facetIds ) );
 
-        for ( ProjectVersionFacet facet : versionMetadata.getFacetList() )
+        for ( MetadataFacet facet : versionMetadata.getFacetList() )
         {
             properties.putAll( facet.toProperties() );
         }
@@ -201,7 +203,7 @@
     {
         File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion );
 
-        Properties properties = readProperties( directory, PROJECT_VERSION_METADATA_KEY );
+        Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
         int i = Integer.valueOf( properties.getProperty( "ref:lastReferenceNum", "-1" ) ) + 1;
         setProperty( properties, "ref:lastReferenceNum", Integer.toString( i ) );
         setProperty( properties, "ref:reference." + i + ".namespace", reference.getNamespace() );
@@ -237,6 +239,68 @@
         }
     }
 
+    public List<String> getMetadataFacets( String repoId, String facetId )
+    {
+        File directory = getMetadataDirectory( repoId, facetId );
+        String[] list = directory.list();
+        return list != null ? Arrays.asList( list ) : Collections.<String>emptyList();
+    }
+
+    public MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name )
+    {
+        Properties properties;
+        try
+        {
+            properties =
+                readProperties( new File( getMetadataDirectory( repositoryId, facetId ), name ), METADATA_KEY );
+        }
+        catch ( FileNotFoundException e )
+        {
+            return null;
+        }
+        catch ( IOException e )
+        {
+            // TODO
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            return null;
+        }
+        MetadataFacet metadataFacet = null;
+        MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get( facetId );
+        if ( metadataFacetFactory != null )
+        {
+            metadataFacet = metadataFacetFactory.createMetadataFacet();
+            Map<String, String> map = new HashMap<String, String>();
+            for ( String key : properties.stringPropertyNames() )
+            {
+                map.put( key, properties.getProperty( key ) );
+            }
+            metadataFacet.fromProperties( map );
+        }
+        return metadataFacet;
+    }
+
+    public void addMetadataFacet( String repositoryId, String facetId, String name, MetadataFacet metadataFacet )
+    {
+        Properties properties = new Properties();
+        properties.putAll( metadataFacet.toProperties() );
+
+        try
+        {
+            writeProperties( properties, new File( getMetadataDirectory( repositoryId, facetId ), name ),
+                             METADATA_KEY );
+        }
+        catch ( IOException e )
+        {
+            // TODO!
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+    }
+
+    private File getMetadataDirectory( String repositoryId, String facetId )
+    {
+        return new File( this.directory, repositoryId + "/.meta/" + facetId );
+    }
+
     private String join( Collection<String> ids )
     {
         if ( !ids.isEmpty() )
@@ -265,7 +329,7 @@
     {
         File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion );
 
-        Properties properties = readProperties( directory, PROJECT_VERSION_METADATA_KEY );
+        Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
 
         properties.setProperty( "artifact:updated:" + artifact.getId(),
                                 Long.toString( artifact.getFileLastModified().getTime() ) );
@@ -287,24 +351,34 @@
         }
     }
 
-    private Properties readProperties( File directory, String propertiesKey )
+    private Properties readOrCreateProperties( File directory, String propertiesKey )
     {
-        Properties properties = new Properties();
-        FileInputStream in = null;
         try
         {
-            in = new FileInputStream( new File( directory, propertiesKey + ".properties" ) );
-            properties.load( in );
+            return readProperties( directory, propertiesKey );
         }
         catch ( FileNotFoundException e )
         {
-            // skip - use blank properties
+            // ignore and return new properties
         }
         catch ( IOException e )
         {
             // TODO
             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
         }
+        return new Properties();
+    }
+
+    private Properties readProperties( File directory, String propertiesKey )
+        throws IOException
+    {
+        Properties properties = new Properties();
+        FileInputStream in = null;
+        try
+        {
+            in = new FileInputStream( new File( directory, propertiesKey + ".properties" ) );
+            properties.load( in );
+        }
         finally
         {
             IOUtils.closeQuietly( in );
@@ -316,7 +390,7 @@
     {
         File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId );
 
-        Properties properties = readProperties( directory, PROJECT_VERSION_METADATA_KEY );
+        Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
 
         ProjectMetadata project = new ProjectMetadata();
         project.setNamespace( properties.getProperty( "namespace" ) );
@@ -329,7 +403,7 @@
     {
         File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion );
 
-        Properties properties = readProperties( directory, PROJECT_VERSION_METADATA_KEY );
+        Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
         String id = properties.getProperty( "id" );
         ProjectVersionMetadata versionMetadata = null;
         if ( id != null )
@@ -461,7 +535,7 @@
                 }
                 else
                 {
-                    ProjectVersionFacet facet = factory.createProjectVersionFacet();
+                    MetadataFacet facet = factory.createMetadataFacet();
                     Map<String, String> map = new HashMap<String, String>();
                     for ( String key : properties.stringPropertyNames() )
                     {
@@ -475,7 +549,7 @@
                 }
             }
 
-            for ( ProjectVersionFacet facet : versionMetadata.getFacetList() )
+            for ( MetadataFacet facet : versionMetadata.getFacetList() )
             {
                 properties.putAll( facet.toProperties() );
             }
@@ -488,7 +562,7 @@
     {
         File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion );
 
-        Properties properties = readProperties( directory, PROJECT_VERSION_METADATA_KEY );
+        Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
 
         List<String> versions = new ArrayList<String>();
         for ( Map.Entry entry : properties.entrySet() )
@@ -507,7 +581,7 @@
     {
         File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion );
 
-        Properties properties = readProperties( directory, PROJECT_VERSION_METADATA_KEY );
+        Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
         int numberOfRefs = Integer.valueOf( properties.getProperty( "ref:lastReferenceNum", "-1" ) ) + 1;
 
         List<ProjectVersionReference> references = new ArrayList<ProjectVersionReference>();

Modified: archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java?rev=888164&r1=888163&r2=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java Mon Dec  7 22:32:10 2009
@@ -1,18 +1,5 @@
 package org.apache.archiva.metadata.repository.file;
 
-import java.io.File;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-
-import org.apache.archiva.metadata.model.MailingList;
-import org.apache.archiva.metadata.model.MetadataFacetFactory;
-import org.apache.archiva.metadata.model.ProjectVersionFacet;
-import org.apache.archiva.metadata.model.ProjectVersionMetadata;
-import org.apache.archiva.metadata.repository.MetadataRepository;
-import org.apache.commons.io.FileUtils;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -32,6 +19,19 @@
  * under the License.
  */
 
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.archiva.metadata.model.MailingList;
+import org.apache.archiva.metadata.model.MetadataFacet;
+import org.apache.archiva.metadata.model.MetadataFacetFactory;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.commons.io.FileUtils;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+
 public class FileMetadataRepositoryTest
     extends PlexusInSpringTestCase
 {
@@ -45,15 +45,32 @@
 
     private static final String TEST_PROJECT_VERSION = "1.0";
 
+    private static final String TEST_FACET_ID = "test-facet-id";
+
+    private static final String TEST_NAME = "test-name";
+
+    private static final String TEST_VALUE = "test-value";
+
+    private static final String UNKNOWN = "unknown";
+
     public void setUp()
         throws Exception
     {
         super.setUp();
 
-        repository = (FileMetadataRepository) lookup( MetadataRepository.class );
+        repository = new FileMetadataRepository();
         File directory = getTestFile( "target/test-repository" );
         FileUtils.deleteDirectory( directory );
         repository.setDirectory( directory );
+
+        repository.setMetadataFacetFactories(
+            Collections.<String, MetadataFacetFactory>singletonMap( TEST_FACET_ID, new MetadataFacetFactory()
+            {
+                public MetadataFacet createMetadataFacet()
+                {
+                    return new TestMetadataFacet( "test-metadata" );
+                }
+            } ) );
     }
 
     public void testRootNamespaceWithNoMetadataRepository()
@@ -75,38 +92,78 @@
 
     public void testUpdateProjectVersionMetadataWithExistingFacets()
     {
-        repository.setMetadataFacetFactories(
-            Collections.<String, MetadataFacetFactory>singletonMap( "test", new MetadataFacetFactory()
-            {
-                public ProjectVersionFacet createProjectVersionFacet()
-                {
-                    return new TestProjectVersionFacet( "bar" );
-                }
-            } ) );
-
         ProjectVersionMetadata metadata = new ProjectVersionMetadata();
         metadata.setId( TEST_PROJECT_VERSION );
-        ProjectVersionFacet facet = new TestProjectVersionFacet( "baz" );
+        MetadataFacet facet = new TestMetadataFacet( "baz" );
         metadata.addFacet( facet );
         repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
 
         metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
-        assertEquals( Collections.singleton( "test" ), metadata.getFacetIds() );
+        assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
 
         metadata = new ProjectVersionMetadata();
         metadata.setId( TEST_PROJECT_VERSION );
         repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
 
         metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
-        assertEquals( Collections.singleton( "test" ), metadata.getFacetIds() );
-        TestProjectVersionFacet testFacet = (TestProjectVersionFacet) metadata.getFacet( "test" );
+        assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
+        TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID );
         assertEquals( "baz", testFacet.getValue() );
     }
 
-    private static class TestProjectVersionFacet
-        implements ProjectVersionFacet
+    public void testGetMetadataFacet()
+    {
+        repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME, new TestMetadataFacet( TEST_VALUE ) );
+
+        assertEquals( new TestMetadataFacet( TEST_VALUE ),
+                      repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
+    }
+
+    public void testGetMetadataFacetWhenEmpty()
+    {
+        assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
+    }
+
+    public void testGetMetadataFacetWhenUnknownName()
     {
-        private TestProjectVersionFacet( String value )
+        repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME, new TestMetadataFacet( TEST_VALUE ) );
+
+        assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, UNKNOWN ) );
+    }
+
+    public void testGetMetadataFacetWhenDefaultValue()
+    {
+        repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME, new TestMetadataFacet( null ) );
+
+        assertEquals( new TestMetadataFacet( "test-metadata" ),
+                      repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) );
+    }
+
+    public void testGetMetadataFacetWhenUnknownFacetId()
+    {
+        repository.addMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME, new TestMetadataFacet( TEST_VALUE ) );
+
+        assertNull( repository.getMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ) );
+    }
+
+    public void testGetMetadataFacets()
+    {
+        repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME, new TestMetadataFacet( TEST_VALUE ) );
+
+        assertEquals( Collections.singletonList( TEST_NAME ),
+                      repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ) );
+    }
+
+    public void testGetMetadataFacetsWhenEmpty()
+    {
+        List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID );
+        assertTrue( facets.isEmpty() );
+    }
+
+    private static class TestMetadataFacet
+        implements MetadataFacet
+    {
+        private TestMetadataFacet( String value )
         {
             this.value = value;
         }
@@ -115,22 +172,67 @@
 
         public String getFacetId()
         {
-            return "test";
+            return TEST_FACET_ID;
         }
 
         public Map<String, String> toProperties()
         {
-            return Collections.singletonMap( "test:foo", value );
+            if ( value != null )
+            {
+                return Collections.singletonMap( TEST_FACET_ID + ":foo", value );
+            }
+            else
+            {
+                return Collections.emptyMap();
+            }
         }
 
         public void fromProperties( Map<String, String> properties )
         {
-            value = properties.get( "test:foo" );
+            String value = properties.get( TEST_FACET_ID + ":foo" );
+            if ( value != null )
+            {
+                this.value = value;
+            }
         }
 
         public String getValue()
         {
             return value;
         }
+
+        @Override
+        public String toString()
+        {
+            return "TestMetadataFacet{" + "value='" + value + '\'' + '}';
+        }
+
+        @Override
+        public boolean equals( Object o )
+        {
+            if ( this == o )
+            {
+                return true;
+            }
+            if ( o == null || getClass() != o.getClass() )
+            {
+                return false;
+            }
+
+            TestMetadataFacet that = (TestMetadataFacet) o;
+
+            if ( value != null ? !value.equals( that.value ) : that.value != null )
+            {
+                return false;
+            }
+
+            return true;
+        }
+
+        @Override
+        public int hashCode()
+        {
+            return value != null ? value.hashCode() : 0;
+        }
     }
 }

Modified: archiva/branches/MRM-1025/archiva-modules/plugins/pom.xml
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/pom.xml?rev=888164&r1=888163&r2=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/pom.xml (original)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/pom.xml Mon Dec  7 22:32:10 2009
@@ -29,5 +29,6 @@
   <modules>
     <module>metadata-repository-file</module>
     <module>maven2-repository</module>
+    <module>repository-statistics</module>
   </modules>
 </project>
\ No newline at end of file

Propchange: archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Dec  7 22:32:10 2009
@@ -0,0 +1,2 @@
+target
+*.iml

Added: archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/pom.xml
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/pom.xml?rev=888164&view=auto
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/pom.xml (added)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/pom.xml Mon Dec  7 22:32:10 2009
@@ -0,0 +1,51 @@
+<?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.
+-->
+<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>
+  <parent>
+    <artifactId>plugins</artifactId>
+    <groupId>org.apache.archiva</groupId>
+    <version>1.3-SNAPSHOT</version>
+  </parent>
+  <artifactId>repository-statistics</artifactId>
+  <name>Repository Statistics</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>metadata-repository-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-spring</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jcl-over-slf4j</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

Added: archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java?rev=888164&view=auto
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java (added)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java Mon Dec  7 22:32:10 2009
@@ -0,0 +1,80 @@
+package org.apache.archiva.metadata.repository.stats;
+
+/*
+ * 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.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.archiva.metadata.repository.MetadataRepository;
+
+/**
+ * @plexus.component role="org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager" role-hint="default"
+ */
+public class DefaultRepositoryStatisticsManager
+    implements RepositoryStatisticsManager
+{
+    /**
+     * @plexus.requirement
+     */
+    private MetadataRepository metadataRepository;
+
+    static final DateFormat SCAN_TIMESTAMP = new SimpleDateFormat( "yyyyMMdd.HHmmss.SSS" );
+
+    public RepositoryStatistics getLastStatistics( String repositoryId )
+    {
+        // TODO: consider a more efficient implementation that directly gets the last one from the content repository
+        List<String> scans = metadataRepository.getMetadataFacets( repositoryId, RepositoryStatistics.FACET_ID );
+        Collections.sort( scans );
+        if ( !scans.isEmpty() )
+        {
+            String name = scans.get( scans.size() - 1 );
+            return (RepositoryStatistics) metadataRepository.getMetadataFacet( repositoryId,
+                                                                               RepositoryStatistics.FACET_ID, name );
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    public void addStatisticsAfterScan( String repositoryId, RepositoryStatistics repositoryStatistics )
+    {
+        // TODO
+        // populate total artifact count from content repository
+//        repositoryStatistics.setTotalArtifactCount(  );
+        // populate total size from content repository
+//        repositoryStatistics.setTotalArtifactFileSize(  );
+        // populate total group count from content repository
+//        repositoryStatistics.setTotalGroupCount(  );
+        // populate total project count from content repository
+//        repositoryStatistics.setTotalProjectCount(  );
+
+        metadataRepository.addMetadataFacet( repositoryId, RepositoryStatistics.FACET_ID,
+                                             SCAN_TIMESTAMP.format( repositoryStatistics.getScanStartTime() ),
+                                             repositoryStatistics );
+    }
+
+    public void setMetadataRepository( MetadataRepository metadataRepository )
+    {
+        this.metadataRepository = metadataRepository;
+    }
+}

Added: archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java?rev=888164&view=auto
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java (added)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java Mon Dec  7 22:32:10 2009
@@ -0,0 +1,164 @@
+package org.apache.archiva.metadata.repository.stats;
+
+/*
+ * 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.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.archiva.metadata.model.MetadataFacet;
+
+public class RepositoryStatistics
+    implements MetadataFacet
+{
+    private Date scanEndTime;
+
+    private Date scanStartTime;
+
+    private long totalArtifactCount;
+
+    private long totalArtifactFileSize;
+
+    private long totalFileCount;
+
+    private long totalGroupCount;
+
+    private long totalProjectCount;
+
+    private long newFileCount;
+
+    public static String FACET_ID = "org.apache.archiva.metadata.repository.stats";
+
+    public Date getScanEndTime()
+    {
+        return scanEndTime;
+    }
+
+    public void setScanEndTime( Date scanEndTime )
+    {
+        this.scanEndTime = scanEndTime;
+    }
+
+    public Date getScanStartTime()
+    {
+        return scanStartTime;
+    }
+
+    public void setScanStartTime( Date scanStartTime )
+    {
+        this.scanStartTime = scanStartTime;
+    }
+
+    public long getTotalArtifactCount()
+    {
+        return totalArtifactCount;
+    }
+
+    public void setTotalArtifactCount( long totalArtifactCount )
+    {
+        this.totalArtifactCount = totalArtifactCount;
+    }
+
+    public long getTotalArtifactFileSize()
+    {
+        return totalArtifactFileSize;
+    }
+
+    public void setTotalArtifactFileSize( long totalArtifactFileSize )
+    {
+        this.totalArtifactFileSize = totalArtifactFileSize;
+    }
+
+    public long getTotalFileCount()
+    {
+        return totalFileCount;
+    }
+
+    public void setTotalFileCount( long totalFileCount )
+    {
+        this.totalFileCount = totalFileCount;
+    }
+
+    public long getTotalGroupCount()
+    {
+        return totalGroupCount;
+    }
+
+    public void setTotalGroupCount( long totalGroupCount )
+    {
+        this.totalGroupCount = totalGroupCount;
+    }
+
+    public long getTotalProjectCount()
+    {
+        return totalProjectCount;
+    }
+
+    public void setTotalProjectCount( long totalProjectCount )
+    {
+        this.totalProjectCount = totalProjectCount;
+    }
+
+    public void setNewFileCount( long newFileCount )
+    {
+        this.newFileCount = newFileCount;
+    }
+
+    public long getNewFileCount()
+    {
+        return newFileCount;
+    }
+
+    public long getDuration()
+    {
+        return scanEndTime.getTime() - scanStartTime.getTime();
+    }
+
+    public String getFacetId()
+    {
+        return FACET_ID;
+    }
+
+    public Map<String, String> toProperties()
+    {
+        Map<String, String> properties = new HashMap<String, String>();
+        properties.put( "scanEndTime", String.valueOf( scanEndTime.getTime() ) );
+        properties.put( "scanStartTime", String.valueOf( scanStartTime.getTime() ) );
+        properties.put( "totalArtifactCount", String.valueOf( totalArtifactCount ) );
+        properties.put( "totalArtifactFileSize", String.valueOf( totalArtifactFileSize ) );
+        properties.put( "totalFileCount", String.valueOf( totalFileCount ) );
+        properties.put( "totalGroupCount", String.valueOf( totalGroupCount ) );
+        properties.put( "totalProjectCount", String.valueOf( totalProjectCount ) );
+        properties.put( "newFileCount", String.valueOf( newFileCount ) );
+        return properties;
+    }
+
+    public void fromProperties( Map<String, String> properties )
+    {
+        scanEndTime = new Date( Long.valueOf( properties.get( "scanEndTime" ) ) );
+        scanStartTime = new Date( Long.valueOf( properties.get( "scanStartTime" ) ) );
+        totalArtifactCount = Long.valueOf( properties.get( "totalArtifactCount" ) );
+        totalArtifactFileSize = Long.valueOf( properties.get( "totalArtifactFileSize" ) );
+        totalFileCount = Long.valueOf( properties.get( "totalFileCount" ) );
+        totalGroupCount = Long.valueOf( properties.get( "totalGroupCount" ) );
+        totalProjectCount = Long.valueOf( properties.get( "totalProjectCount" ) );
+        newFileCount = Long.valueOf( properties.get( "newFileCount" ) );
+    }
+}

Added: archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsFactory.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsFactory.java?rev=888164&view=auto
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsFactory.java (added)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsFactory.java Mon Dec  7 22:32:10 2009
@@ -0,0 +1,35 @@
+package org.apache.archiva.metadata.repository.stats;
+
+/*
+ * 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 org.apache.archiva.metadata.model.MetadataFacetFactory;
+
+/**
+ * @plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.repository.stats"
+ */
+public class RepositoryStatisticsFactory
+    implements MetadataFacetFactory
+{
+    public MetadataFacet createMetadataFacet()
+    {
+        return new RepositoryStatistics();
+    }
+}
\ No newline at end of file

Added: archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java?rev=888164&view=auto
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java (added)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java Mon Dec  7 22:32:10 2009
@@ -0,0 +1,27 @@
+package org.apache.archiva.metadata.repository.stats;
+
+/*
+ * 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 RepositoryStatisticsManager
+{
+    RepositoryStatistics getLastStatistics( String repositoryId );
+
+    void addStatisticsAfterScan( String repositoryId, RepositoryStatistics repositoryStatistics );
+}

Added: archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java?rev=888164&view=auto
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java (added)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java Mon Dec  7 22:32:10 2009
@@ -0,0 +1,152 @@
+package org.apache.archiva.metadata.repository.stats;
+
+/*
+ * 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.text.ParseException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+
+import junit.framework.TestCase;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.easymock.MockControl;
+
+public class RepositoryStatisticsManagerTest
+    extends TestCase
+{
+    private DefaultRepositoryStatisticsManager repositoryStatisticsManager;
+
+    private static final String TEST_REPO_ID = "test-repo";
+
+    private MockControl metadataRepositoryControl;
+
+    private MetadataRepository metadataRepository;
+
+    private static final String FIRST_TEST_SCAN = "20091201.123456.789";
+
+    private static final String SECOND_TEST_SCAN = "20091202.012345.678";
+
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        repositoryStatisticsManager = new DefaultRepositoryStatisticsManager();
+
+        metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
+        metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
+        repositoryStatisticsManager.setMetadataRepository( metadataRepository );
+    }
+
+    public void testGetLatestStats()
+        throws ParseException
+    {
+        Date endTime =
+            new Date( DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.parse( SECOND_TEST_SCAN ).getTime() + 60000 );
+
+        RepositoryStatistics stats = new RepositoryStatistics();
+        stats.setScanStartTime( DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.parse( SECOND_TEST_SCAN ) );
+        stats.setScanEndTime( endTime );
+        stats.setTotalArtifactFileSize( 1314527915L );
+        stats.setNewFileCount( 123 );
+        stats.setTotalArtifactCount( 10386 );
+        stats.setTotalProjectCount( 2031 );
+        stats.setTotalGroupCount( 529 );
+        stats.setTotalFileCount( 56229 );
+
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ),
+            Arrays.asList( FIRST_TEST_SCAN, SECOND_TEST_SCAN ) );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, SECOND_TEST_SCAN ),
+            stats );
+        metadataRepositoryControl.replay();
+
+        stats = repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID );
+        assertNotNull( stats );
+        assertEquals( 1314527915L, stats.getTotalArtifactFileSize() );
+        assertEquals( 123, stats.getNewFileCount() );
+        assertEquals( 10386, stats.getTotalArtifactCount() );
+        assertEquals( 2031, stats.getTotalProjectCount() );
+        assertEquals( 529, stats.getTotalGroupCount() );
+        assertEquals( 56229, stats.getTotalFileCount() );
+        assertEquals( SECOND_TEST_SCAN,
+                      DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( stats.getScanStartTime() ) );
+        assertEquals( endTime, stats.getScanEndTime() );
+
+        metadataRepositoryControl.verify();
+    }
+
+    public void testGetLatestStatsWhenEmpty()
+    {
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ),
+            Collections.emptyList() );
+        metadataRepositoryControl.replay();
+
+        RepositoryStatistics stats = repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID );
+        assertNull( stats );
+
+        metadataRepositoryControl.verify();
+    }
+
+    public void testAddNewStats()
+    {
+        Date current = new Date();
+        Date startTime = new Date( current.getTime() - 12345 );
+
+        RepositoryStatistics stats = new RepositoryStatistics();
+        stats.setScanStartTime( startTime );
+        stats.setScanEndTime( current );
+        stats.setTotalArtifactFileSize( 1400032000L );
+        stats.setNewFileCount( 45 );
+        stats.setTotalArtifactCount( 10412 );
+        stats.setTotalProjectCount( 2036 );
+        stats.setTotalGroupCount( 531 );
+        stats.setTotalFileCount( 56345 );
+
+        String startTimeAsString = DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( startTime );
+        metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString, stats );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ),
+            Arrays.asList( startTimeAsString ) );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString ),
+            stats );
+
+        metadataRepositoryControl.replay();
+
+        repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats );
+
+        stats = repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID );
+        assertNotNull( stats );
+        assertEquals( 1400032000L, stats.getTotalArtifactFileSize() );
+        assertEquals( 45, stats.getNewFileCount() );
+        assertEquals( 10412, stats.getTotalArtifactCount() );
+        assertEquals( 2036, stats.getTotalProjectCount() );
+        assertEquals( 531, stats.getTotalGroupCount() );
+        assertEquals( 56345, stats.getTotalFileCount() );
+        assertEquals( current.getTime() - 12345, stats.getScanStartTime().getTime() );
+        assertEquals( current, stats.getScanEndTime() );
+
+        metadataRepositoryControl.verify();
+    }
+}

Modified: archiva/branches/MRM-1025/pom.xml
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/pom.xml?rev=888164&r1=888163&r2=888164&view=diff
==============================================================================
--- archiva/branches/MRM-1025/pom.xml (original)
+++ archiva/branches/MRM-1025/pom.xml Mon Dec  7 22:32:10 2009
@@ -100,6 +100,7 @@
         <executions>
           <execution>
             <id>generate</id>
+            <phase>generate-resources</phase>
             <goals>
               <goal>generate-metadata</goal>
             </goals>
@@ -305,6 +306,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.archiva</groupId>
+        <artifactId>repository-statistics</artifactId>
+        <version>1.3-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.archiva</groupId>
         <artifactId>maven2-repository</artifactId>
         <version>1.3-SNAPSHOT</version>
       </dependency>



Mime
View raw message