]> source.dussan.org Git - archiva.git/commitdiff
remove dependency on repository-layer from repository-statistics module
authorBrett Porter <brett@apache.org>
Thu, 11 Mar 2010 10:39:33 +0000 (10:39 +0000)
committerBrett Porter <brett@apache.org>
Thu, 11 Mar 2010 10:39:33 +0000 (10:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@921791 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml
archiva-modules/plugins/repository-statistics/pom.xml
archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java
archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java

index ab685fb615b3f4fd089b5ffb8af2ecb83bd6675d..c62817b77ca27db0d593b4daaa7160f0c94df9c9 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-repository-scanner</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-repository-layer</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-scheduler-repository</artifactId>
index 247e1d884d74be43bfaac4d0fdcfb471899e4fef..58945a5f996ae46121b75eedbce7c65c95199cc8 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>metadata-repository-api</artifactId>
     </dependency>
+    <!-- TODO: look at making this optional -->
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>maven2-repository</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-spring</artifactId>
@@ -51,9 +56,5 @@
       <artifactId>jcl-over-slf4j</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.apache.archiva</groupId>
-      <artifactId>archiva-repository-layer</artifactId>
-    </dependency>
   </dependencies>
 </project>
index 9233b07b514939c22e55a45fb84502cd85e5a73e..7f2466470ba85c4a684cd438a7a431027cccea0c 100644 (file)
@@ -19,6 +19,12 @@ package org.apache.archiva.metadata.repository.stats;
  * under the License.
  */
 
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -28,15 +34,6 @@ import java.util.Date;
 import java.util.List;
 import java.util.TimeZone;
 
-import org.apache.archiva.metadata.model.ArtifactMetadata;
-import org.apache.archiva.metadata.repository.MetadataRepository;
-import org.apache.maven.archiva.repository.ManagedRepositoryContent;
-import org.apache.maven.archiva.repository.RepositoryContentFactory;
-import org.apache.maven.archiva.repository.RepositoryException;
-import org.apache.maven.archiva.repository.layout.LayoutException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  * @plexus.component role="org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager" role-hint="default"
  */
@@ -50,11 +47,6 @@ public class DefaultRepositoryStatisticsManager
      */
     private MetadataRepository metadataRepository;
 
-    /**
-     * @plexus.requirement
-     */
-    private RepositoryContentFactory repositoryContentFactory;
-
     private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
 
     public RepositoryStatistics getLastStatistics( String repositoryId )
@@ -74,12 +66,11 @@ public class DefaultRepositoryStatisticsManager
         }
     }
 
-    private void walkRepository( RepositoryStatistics stats, String repositoryId, String ns,
-                                 ManagedRepositoryContent repositoryContent )
+    private void walkRepository( RepositoryStatistics stats, String repositoryId, String ns )
     {
         for ( String namespace : metadataRepository.getNamespaces( repositoryId, ns ) )
         {
-            walkRepository( stats, repositoryId, ns + "." + namespace, repositoryContent );
+            walkRepository( stats, repositoryId, ns + "." + namespace );
         }
 
         Collection<String> projects = metadataRepository.getProjects( repositoryId, ns );
@@ -98,18 +89,12 @@ public class DefaultRepositoryStatisticsManager
                         stats.setTotalArtifactCount( stats.getTotalArtifactCount() + 1 );
                         stats.setTotalArtifactFileSize( stats.getTotalArtifactFileSize() + artifact.getSize() );
 
-                        // TODO: need a maven2 metadata repository API equivalent
-                        try
+                        MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet( MavenArtifactFacet.FACET_ID );
+                        if ( facet != null )
                         {
-                            String type = repositoryContent.toArtifactReference(
-                                ns.replace( '.', '/' ) + "/" + project + "/" + version + "/" +
-                                    artifact.getId() ).getType();
+                            String type = facet.getType();
                             stats.setTotalCountForType( type, stats.getTotalCountForType( type ) + 1 );
                         }
-                        catch ( LayoutException e )
-                        {
-                            // ignore
-                        }
                     }
                 }
             }
@@ -138,16 +123,7 @@ public class DefaultRepositoryStatisticsManager
         //       it on the fly
         for ( String ns : metadataRepository.getRootNamespaces( repositoryId ) )
         {
-            ManagedRepositoryContent content;
-            try
-            {
-                content = repositoryContentFactory.getManagedRepositoryContent( repositoryId );
-            }
-            catch ( RepositoryException e )
-            {
-                throw new RuntimeException( e );
-            }
-            walkRepository( repositoryStatistics, repositoryId, ns, content );
+            walkRepository( repositoryStatistics, repositoryId, ns );
         }
         log.info( "Repository walk for statistics executed in " + ( System.currentTimeMillis() - startWalk ) + "ms" );
 
@@ -199,9 +175,4 @@ public class DefaultRepositoryStatisticsManager
     {
         this.metadataRepository = metadataRepository;
     }
-
-    public void setRepositoryContentFactory( RepositoryContentFactory repositoryContentFactory )
-    {
-        this.repositoryContentFactory = repositoryContentFactory;
-    }
 }
index 292472f9463103a160bc40bc674556554561313a..a5ce803135acb65cfc81e9b544831195f74f37a8 100644 (file)
@@ -19,6 +19,11 @@ package org.apache.archiva.metadata.repository.stats;
  * under the License.
  */
 
+import junit.framework.TestCase;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.easymock.MockControl;
+
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -30,15 +35,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.TimeZone;
 
-import junit.framework.TestCase;
-import org.apache.archiva.metadata.model.ArtifactMetadata;
-import org.apache.archiva.metadata.repository.MetadataRepository;
-import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.archiva.repository.RepositoryContentFactory;
-import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
-import org.easymock.MockControl;
-import org.easymock.classextension.MockClassControl;
-
 public class RepositoryStatisticsManagerTest
     extends TestCase
 {
@@ -76,18 +72,6 @@ public class RepositoryStatisticsManagerTest
         metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
         metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
         repositoryStatisticsManager.setMetadataRepository( metadataRepository );
-
-        ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration();
-        repository.setId( TEST_REPO_ID );
-        repository.setLocation( "" );
-        ManagedDefaultRepositoryContent content = new ManagedDefaultRepositoryContent();
-        content.setRepository( repository );
-        MockControl control = MockClassControl.createControl( RepositoryContentFactory.class );
-        RepositoryContentFactory contentFactory = (RepositoryContentFactory) control.getMock();
-        contentFactory.getManagedRepositoryContent( TEST_REPO_ID );
-        control.setDefaultReturnValue( content );
-        control.replay();
-        repositoryStatisticsManager.setRepositoryContentFactory( contentFactory );
     }
 
     public void testGetLatestStats()