From 51acb7acd7e06a3a38c3c8bcc46a2c0942ae7b0f Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 11 Mar 2010 10:39:33 +0000 Subject: [PATCH] remove dependency on repository-layer from repository-statistics module git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@921791 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva-xmlrpc-services/pom.xml | 4 ++ .../plugins/repository-statistics/pom.xml | 9 ++-- .../DefaultRepositoryStatisticsManager.java | 53 +++++-------------- .../RepositoryStatisticsManagerTest.java | 26 ++------- 4 files changed, 26 insertions(+), 66 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml index ab685fb61..c62817b77 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml @@ -50,6 +50,10 @@ org.apache.archiva archiva-repository-scanner + + org.apache.archiva + archiva-repository-layer + org.apache.archiva archiva-scheduler-repository diff --git a/archiva-modules/plugins/repository-statistics/pom.xml b/archiva-modules/plugins/repository-statistics/pom.xml index 247e1d884..58945a5f9 100644 --- a/archiva-modules/plugins/repository-statistics/pom.xml +++ b/archiva-modules/plugins/repository-statistics/pom.xml @@ -32,6 +32,11 @@ org.apache.archiva metadata-repository-api + + + org.apache.archiva + maven2-repository + org.codehaus.plexus plexus-spring @@ -51,9 +56,5 @@ jcl-over-slf4j test - - org.apache.archiva - archiva-repository-layer - diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java index 9233b07b5..7f2466470 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java @@ -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 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; - } } diff --git a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java index 292472f94..a5ce80313 100644 --- a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java +++ b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java @@ -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() -- 2.39.5