From 0960c24cfbf3c11faa4871b1029308e78d8caa7c Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Wed, 16 Dec 2009 02:25:42 +0000 Subject: [PATCH] [MRM-1301] add back summary statistics for various counts git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@891102 13f79535-47bb-0310-9956-ffa450edef68 --- .../ArchivaMetadataCreationConsumer.java | 15 +- .../repository/TestMetadataRepository.java | 2 - ...ArchivaRepositoryScanningTaskExecutor.java | 11 +- ...ivaRepositoryScanningTaskExecutorTest.java | 16 +- .../TestRepositoryStatisticsManager.java | 10 +- ...NewVersionsOfArtifactRssFeedProcessor.java | 3 - .../rss/processor/RssFeedProcessor.java | 4 +- .../archiva/web/action/BrowseAction.java | 3 - .../web/action/ShowArtifactAction.java | 41 +---- .../maven/archiva/web/rss/RssFeedServlet.java | 6 - .../memory/TestMetadataRepository.java | 3 - .../archiva/web/action/BrowseActionTest.java | 6 - .../repository/TestMetadataRepository.java | 2 - .../repository/DefaultMetadataResolver.java | 2 - .../metadata/repository/MetadataResolver.java | 9 +- .../repository/MetadataResolverException.java | 29 --- .../maven2/DefaultDependencyTreeBuilder.java | 24 +-- .../Maven2RepositoryMetadataResolver.java | 2 - .../repository/TestMetadataResolver.java | 2 - .../Maven2RepositoryMetadataResolverTest.java | 9 - .../DefaultRepositoryStatisticsManager.java | 59 +++++-- .../stats/RepositoryStatistics.java | 73 ++++++++ .../stats/RepositoryStatisticsManager.java | 2 +- .../RepositoryStatisticsManagerTest.java | 167 ++++++++++++++++-- 24 files changed, 311 insertions(+), 189 deletions(-) delete mode 100644 archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolverException.java diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java index 3275405d4..1d2ba0064 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java @@ -31,7 +31,6 @@ import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.archiva.metadata.repository.MetadataResolverException; import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver; import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -163,17 +162,9 @@ public class ArchivaMetadataCreationConsumer String projectVersion = VersionUtil.getBaseVersion( artifact.getVersion() ); // TODO: maybe not too efficient since it may have already been read and stored for this artifact - ProjectVersionMetadata versionMetadata; - try - { - versionMetadata = - storageResolver.getProjectVersion( repository.getId(), artifact.getGroupId(), artifact.getArtifactId(), - projectVersion ); - } - catch ( MetadataResolverException e ) - { - throw new ConsumerException( e.getMessage(), e ); - } + ProjectVersionMetadata versionMetadata = + storageResolver.getProjectVersion( repository.getId(), artifact.getGroupId(), artifact.getArtifactId(), + projectVersion ); if ( versionMetadata == null ) { diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index c42488105..021a6a030 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -40,7 +40,6 @@ public class TestMetadataRepository 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. } @@ -73,7 +72,6 @@ public class TestMetadataRepository } public Collection getProjectVersions( String repoId, String namespace, String projectId ) - throws MetadataResolverException { return null; //To change body of implemented methods use File | Settings | File Templates. } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java index 7f0c65515..3cfa5786c 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java @@ -142,14 +142,11 @@ public class ArchivaRepositoryScanningTaskExecutor log.info( "Finished first scan: " + stats.toDump( arepo ) ); - RepositoryStatistics repositoryStatistics = new RepositoryStatistics(); - repositoryStatistics.setScanStartTime( stats.getWhenGathered() ); - repositoryStatistics.setScanEndTime( - new Date( stats.getWhenGathered().getTime() + stats.getDuration() ) ); - repositoryStatistics.setTotalFileCount( stats.getTotalFileCount() ); - repositoryStatistics.setNewFileCount( stats.getTotalFileCount() - previousFileCount ); // further statistics will be populated by the following method - repositoryStatisticsManager.addStatisticsAfterScan( repoId, repositoryStatistics ); + Date endTime = new Date( stats.getWhenGathered().getTime() + stats.getDuration() ); + repositoryStatisticsManager.addStatisticsAfterScan( repoId, stats.getWhenGathered(), endTime, + stats.getTotalFileCount(), + stats.getTotalFileCount() - previousFileCount ); // log.info( "Scanning for removed repository content" ); diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutorTest.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutorTest.java index 419b9418e..1df470dc9 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutorTest.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutorTest.java @@ -282,17 +282,8 @@ public class ArchivaRepositoryScanningTaskExecutorTest repoTask.setScanAll( true ); Date date = Calendar.getInstance().getTime(); - RepositoryStatistics stats = new RepositoryStatistics(); - stats.setScanStartTime( new Date( date.getTime() - 1234567 ) ); - stats.setScanEndTime( date ); - stats.setNewFileCount( 8 ); - stats.setTotalArtifactCount( 8 ); - stats.setTotalFileCount( 8 ); - stats.setTotalGroupCount( 3 ); - stats.setTotalProjectCount( 5 ); - stats.setTotalArtifactFileSize( 999999 ); - - repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats ); + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, new Date( date.getTime() - 1234567 ), date, 8, + 8 ); taskExecutor.executeTask( repoTask ); @@ -315,6 +306,7 @@ public class ArchivaRepositoryScanningTaskExecutorTest stats.setTotalProjectCount( 5 ); stats.setTotalArtifactFileSize( 38545 ); - repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats ); + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, new Date( date.getTime() - 1234567 ), date, + 31, 31 ); } } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java index 2129bc45f..155f927d5 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java @@ -41,9 +41,17 @@ public class TestRepositoryStatisticsManager : null; } - public void addStatisticsAfterScan( String repositoryId, RepositoryStatistics repositoryStatistics ) + public void addStatisticsAfterScan( String repositoryId, Date startTime, Date endTime, long totalFiles, + long newFiles ) { List stats = getStatsList( repositoryId ); + + RepositoryStatistics repositoryStatistics = new RepositoryStatistics(); + repositoryStatistics.setScanStartTime( startTime ); + repositoryStatistics.setScanEndTime( endTime ); + repositoryStatistics.setNewFileCount( newFiles ); + repositoryStatistics.setTotalFileCount( totalFiles ); + stats.add( repositoryStatistics ); } diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java index a1a80ed54..53cf9f4cf 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java @@ -27,7 +27,6 @@ import java.util.Map; import com.sun.syndication.feed.synd.SyndFeed; import org.apache.archiva.metadata.model.ArtifactMetadata; -import org.apache.archiva.metadata.repository.MetadataResolverException; import org.apache.archiva.rss.RssFeedEntry; import org.apache.archiva.rss.RssFeedGenerator; @@ -54,7 +53,6 @@ public class NewVersionsOfArtifactRssFeedProcessor * Process all versions of the artifact which had a rss feed request. */ public SyndFeed process( Map reqParams ) - throws MetadataResolverException { String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_ID ); String artifactId = reqParams.get( RssFeedProcessor.KEY_ARTIFACT_ID ); @@ -68,7 +66,6 @@ public class NewVersionsOfArtifactRssFeedProcessor } private SyndFeed processNewVersionsOfArtifact( String groupId, String artifactId ) - throws MetadataResolverException { List artifacts = new ArrayList(); for ( String repoId : metadataRepository.getRepositories() ) diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java index 7d4723e31..face4bd57 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java @@ -22,7 +22,6 @@ package org.apache.archiva.rss.processor; import java.util.Map; import com.sun.syndication.feed.synd.SyndFeed; -import org.apache.archiva.metadata.repository.MetadataResolverException; /** * Retrieve and process the data that will be fed into the RssFeedGenerator. @@ -35,6 +34,5 @@ public interface RssFeedProcessor public static final String KEY_ARTIFACT_ID = "artifactId"; - SyndFeed process( Map reqParams ) - throws MetadataResolverException; + SyndFeed process( Map reqParams ); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java index 738bc9747..86877a06c 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java @@ -28,7 +28,6 @@ import java.util.Set; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.repository.MetadataResolver; -import org.apache.archiva.metadata.repository.MetadataResolverException; import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; @@ -153,7 +152,6 @@ public class BrowseAction } public String browseArtifact() - throws MetadataResolverException { if ( StringUtils.isEmpty( groupId ) ) { @@ -190,7 +188,6 @@ public class BrowseAction } private void populateSharedModel( Collection selectedRepos, Collection projectVersions ) - throws MetadataResolverException { sharedModel = new ProjectVersionMetadata(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java index c41326b12..94f33f1dc 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java @@ -28,7 +28,6 @@ import org.apache.archiva.metadata.model.MailingList; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.repository.MetadataResolver; -import org.apache.archiva.metadata.repository.MetadataResolverException; import org.apache.commons.lang.StringUtils; /** @@ -96,15 +95,7 @@ public class ShowArtifactAction // we don't want the implementation being that intelligent - so another resolver to do the // "just-in-time" nature of picking up the metadata (if appropriate for the repository type) is used - try - { - versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version ); - } - catch ( MetadataResolverException e ) - { - addActionError( "Error occurred resolving metadata for project: " + e.getMessage() ); - return ERROR; - } + versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version ); if ( versionMetadata != null ) { repositoryId = repoId; @@ -136,15 +127,7 @@ public class ShowArtifactAction { if ( versionMetadata == null ) { - try - { - versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version ); - } - catch ( MetadataResolverException e ) - { - addActionError( "Error occurred resolving metadata for project: " + e.getMessage() ); - return ERROR; - } + versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version ); } } @@ -170,15 +153,7 @@ public class ShowArtifactAction { if ( versionMetadata == null ) { - try - { - versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version ); - } - catch ( MetadataResolverException e ) - { - addActionError( "Error occurred resolving metadata for project: " + e.getMessage() ); - return ERROR; - } + versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version ); } } @@ -214,15 +189,7 @@ public class ShowArtifactAction { if ( versionMetadata == null ) { - try - { - versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version ); - } - catch ( MetadataResolverException e ) - { - addActionError( "Error occurred resolving metadata for project: " + e.getMessage() ); - return ERROR; - } + versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version ); } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java index 8135fbce3..093abb7d6 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java @@ -33,7 +33,6 @@ import javax.servlet.http.HttpServletResponse; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.SyndFeedOutput; -import org.apache.archiva.metadata.repository.MetadataResolverException; import org.apache.archiva.rss.processor.RssFeedProcessor; import org.apache.commons.codec.Decoder; import org.apache.commons.codec.DecoderException; @@ -218,11 +217,6 @@ public class RssFeedServlet res.sendError( HttpServletResponse.SC_UNAUTHORIZED, USER_NOT_AUTHORIZED ); } - catch ( MetadataResolverException e ) - { - log.debug( COULD_NOT_GENERATE_FEED_ERROR, e ); - res.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, COULD_NOT_GENERATE_FEED_ERROR ); - } } /** diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java index 45d9106e6..b883a4338 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java @@ -31,7 +31,6 @@ import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.archiva.metadata.repository.MetadataResolverException; public class TestMetadataRepository implements MetadataRepository @@ -80,7 +79,6 @@ public class TestMetadataRepository public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) - throws MetadataResolverException { throw new UnsupportedOperationException(); } @@ -113,7 +111,6 @@ public class TestMetadataRepository } public Collection getProjectVersions( String repoId, String namespace, String projectId ) - throws MetadataResolverException { return versions; } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java index d4d8e3257..a2cdb6fd0 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java @@ -25,7 +25,6 @@ import java.util.List; import com.opensymphony.xwork2.Action; import org.apache.archiva.metadata.model.ProjectVersionMetadata; -import org.apache.archiva.metadata.repository.MetadataResolverException; import org.apache.archiva.metadata.repository.memory.TestMetadataResolver; public class BrowseActionTest @@ -90,7 +89,6 @@ public class BrowseActionTest } public void testBrowseArtifactNoObservableRepos() - throws MetadataResolverException { setObservableRepos( Collections.emptyList() ); String selectedGroupId = "org.apache"; @@ -205,7 +203,6 @@ public class BrowseActionTest } public void testBrowseArtifactNoGroupId() - throws MetadataResolverException { String selectedArtifactId = "apache"; @@ -223,7 +220,6 @@ public class BrowseActionTest } public void testBrowseArtifactNoArtifactId() - throws MetadataResolverException { String selectedGroupId = "org.apache"; @@ -241,7 +237,6 @@ public class BrowseActionTest } public void testBrowseArtifact() - throws MetadataResolverException { String selectedGroupId = "org.apache"; String selectedArtifactId = "apache"; @@ -274,7 +269,6 @@ public class BrowseActionTest } public void testBrowseArtifactWithSnapshots() - throws MetadataResolverException { String selectedGroupId = "org.apache"; String selectedArtifactId = "apache"; diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index c42488105..021a6a030 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -40,7 +40,6 @@ public class TestMetadataRepository 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. } @@ -73,7 +72,6 @@ public class TestMetadataRepository } public Collection getProjectVersions( String repoId, String namespace, String projectId ) - throws MetadataResolverException { return null; //To change body of implemented methods use File | Settings | File Templates. } diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java index aa762a2ab..bef603466 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java @@ -58,7 +58,6 @@ public class DefaultMetadataResolver public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) - throws MetadataResolverException { ProjectVersionMetadata metadata = metadataRepository.getProjectVersion( repoId, namespace, projectId, projectVersion ); @@ -166,7 +165,6 @@ public class DefaultMetadataResolver } public Collection getProjectVersions( String repoId, String namespace, String projectId ) - throws MetadataResolverException { Collection projectVersions = metadataRepository.getProjectVersions( repoId, namespace, projectId ); Collection storageProjectVersions = storageResolver.getProjectVersions( repoId, namespace, projectId, diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java index d677a70f1..c6ca461af 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java @@ -30,8 +30,8 @@ public interface MetadataResolver { ProjectMetadata getProject( String repoId, String namespace, String projectId ); - ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) - throws MetadataResolverException; + ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, + String projectVersion ); Collection getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion ); @@ -55,9 +55,8 @@ public interface MetadataResolver Collection getProjects( String repoId, String namespace ); - Collection getProjectVersions( String repoId, String namespace, String projectId ) - throws MetadataResolverException; + Collection getProjectVersions( String repoId, String namespace, String projectId ); Collection getArtifacts( String repoId, String namespace, String projectId, - String projectVersion ); + String projectVersion ); } diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolverException.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolverException.java deleted file mode 100644 index c62a2577f..000000000 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolverException.java +++ /dev/null @@ -1,29 +0,0 @@ -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. - */ - -public class MetadataResolverException - extends Exception -{ - public MetadataResolverException( String message, Exception cause ) - { - super( message, cause ); - } -} diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/DefaultDependencyTreeBuilder.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/DefaultDependencyTreeBuilder.java index 706349fe4..ab6cc04b5 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/DefaultDependencyTreeBuilder.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/DefaultDependencyTreeBuilder.java @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Set; import org.apache.archiva.metadata.repository.MetadataResolver; -import org.apache.archiva.metadata.repository.MetadataResolverException; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.metadata.repository.storage.maven2.RepositoryModelResolver; import org.apache.commons.lang.StringUtils; @@ -421,25 +420,18 @@ public class DefaultDependencyTreeBuilder List remoteRepositories ) throws ArtifactMetadataRetrievalException { - try + Set versions = new HashSet(); + for ( String repoId : repositoryIds ) { - Set versions = new HashSet(); - for ( String repoId : repositoryIds ) + Collection projectVersions = + metadataResolver.getProjectVersions( repoId, artifact.getGroupId(), artifact.getArtifactId() ); + for ( String version : projectVersions ) { - Collection projectVersions = - metadataResolver.getProjectVersions( repoId, artifact.getGroupId(), artifact.getArtifactId() ); - for ( String version : projectVersions ) - { - versions.add( new DefaultArtifactVersion( version ) ); - } + versions.add( new DefaultArtifactVersion( version ) ); } - - return new ArrayList( versions ); - } - catch ( MetadataResolverException e ) - { - throw new ArtifactMetadataRetrievalException( e.getMessage(), e, artifact ); } + + return new ArrayList( versions ); } } } diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java index 2a90d7b7c..05290b5ae 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java @@ -36,7 +36,6 @@ import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.archiva.metadata.repository.MetadataResolverException; import org.apache.archiva.metadata.repository.filter.AllFilter; import org.apache.archiva.metadata.repository.filter.Filter; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; @@ -101,7 +100,6 @@ public class Maven2RepositoryMetadataResolver public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) - throws MetadataResolverException { ManagedRepositoryConfiguration repositoryConfiguration = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId ); diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataResolver.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataResolver.java index 43aefdd8b..bb26ecba6 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataResolver.java @@ -36,7 +36,6 @@ public class TestMetadataResolver 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. } @@ -69,7 +68,6 @@ public class TestMetadataResolver } public Collection getProjectVersions( String repoId, String namespace, String projectId ) - throws MetadataResolverException { return null; //To change body of implemented methods use File | Settings | File Templates. } diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java index 531b59fd5..d9aca1fc4 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java @@ -31,7 +31,6 @@ import org.apache.archiva.metadata.model.License; import org.apache.archiva.metadata.model.MailingList; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.archiva.metadata.repository.MetadataResolverException; import org.apache.archiva.metadata.repository.filter.ExcludesFilter; import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver; import org.apache.archiva.reports.RepositoryProblemFacet; @@ -78,7 +77,6 @@ public class Maven2RepositoryMetadataResolverTest } public void testGetProjectVersionMetadata() - throws MetadataResolverException { ProjectVersionMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" ); @@ -149,7 +147,6 @@ public class Maven2RepositoryMetadataResolverTest } public void testGetProjectVersionMetadataForTimestampedSnapshot() - throws MetadataResolverException { ProjectVersionMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" ); @@ -186,7 +183,6 @@ public class Maven2RepositoryMetadataResolverTest } public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata() - throws MetadataResolverException { ProjectVersionMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" ); @@ -194,7 +190,6 @@ public class Maven2RepositoryMetadataResolverTest } public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata() - throws MetadataResolverException { ProjectVersionMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "malformed-metadata", "1.0-SNAPSHOT" ); @@ -202,7 +197,6 @@ public class Maven2RepositoryMetadataResolverTest } public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata() - throws MetadataResolverException { ProjectVersionMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "incomplete-metadata", "1.0-SNAPSHOT" ); @@ -210,7 +204,6 @@ public class Maven2RepositoryMetadataResolverTest } public void testGetProjectVersionMetadataForInvalidPom() - throws MetadataResolverException { assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() ); @@ -226,7 +219,6 @@ public class Maven2RepositoryMetadataResolverTest } public void testGetProjectVersionMetadataForMislocatedPom() - throws MetadataResolverException { assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() ); @@ -242,7 +234,6 @@ public class Maven2RepositoryMetadataResolverTest } public void testGetProjectVersionMetadataForMissingPom() - throws MetadataResolverException { assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() ); 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 5d877951a..506f593d9 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 @@ -21,10 +21,12 @@ package org.apache.archiva.metadata.repository.stats; import java.text.ParseException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; +import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,23 +61,60 @@ public class DefaultRepositoryStatisticsManager } } - public void addStatisticsAfterScan( String repositoryId, RepositoryStatistics repositoryStatistics ) + private void walkRepository( RepositoryStatistics stats, String repositoryId, String ns ) { + for ( String namespace : metadataRepository.getNamespaces( repositoryId, ns ) ) + { + walkRepository( stats, repositoryId, ns + "." + namespace ); + } + + Collection projects = metadataRepository.getProjects( repositoryId, ns ); + if ( !projects.isEmpty() ) + { + stats.setTotalGroupCount( stats.getTotalGroupCount() + 1 ); + stats.setTotalProjectCount( stats.getTotalProjectCount() + projects.size() ); + + for ( String project : projects ) + { + for ( String version : metadataRepository.getProjectVersions( repositoryId, ns, project ) ) + { + for ( ArtifactMetadata artifact : metadataRepository.getArtifacts( repositoryId, ns, project, + version ) ) + { + stats.setTotalArtifactCount( stats.getTotalArtifactCount() + 1 ); + stats.setTotalArtifactFileSize( stats.getTotalArtifactFileSize() + artifact.getSize() ); + + // TODO: add by type + } + } + } + } + } + + + public void addStatisticsAfterScan( String repositoryId, Date startTime, Date endTime, long totalFiles, long newFiles ) + { + RepositoryStatistics repositoryStatistics = new RepositoryStatistics(); + repositoryStatistics.setScanStartTime( startTime ); + repositoryStatistics.setScanEndTime( endTime ); + repositoryStatistics.setTotalFileCount( totalFiles ); + repositoryStatistics.setNewFileCount( newFiles ); + // In the future, instead of being tied to a scan we might want to record information in the fly based on // events that are occurring. Even without these totals we could query much of the information on demand based // on information from the metadata content repository. In the mean time, we lock information in at scan time. // Note that if new types are later discoverable due to a code change or new plugin, historical stats will not // be updated and the repository will need to be rescanned. - // TODO, populate these and also a count per artifact type - // 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( ); + long startWalk = System.currentTimeMillis(); + // TODO: we can probably get a more efficient implementation directly from the metadata repository, but for now + // we just walk it. Alternatively, we could build an index, or store the aggregate information and update + // it on the fly + for ( String ns : metadataRepository.getRootNamespaces( repositoryId ) ) + { + walkRepository( repositoryStatistics, repositoryId, ns ); + } + log.info( "Repository walk for statistics executed in " + ( System.currentTimeMillis() - startWalk ) + "ms" ); metadataRepository.addMetadataFacet( repositoryId, repositoryStatistics ); } diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java index 272d524dd..6b8020054 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatistics.java @@ -170,4 +170,77 @@ public class RepositoryStatistics totalProjectCount = Long.valueOf( properties.get( "totalProjectCount" ) ); newFileCount = Long.valueOf( properties.get( "newFileCount" ) ); } + + @Override + public String toString() + { + return "RepositoryStatistics{" + "scanEndTime=" + scanEndTime + ", scanStartTime=" + scanStartTime + + ", totalArtifactCount=" + totalArtifactCount + ", totalArtifactFileSize=" + totalArtifactFileSize + + ", totalFileCount=" + totalFileCount + ", totalGroupCount=" + totalGroupCount + ", totalProjectCount=" + + totalProjectCount + ", newFileCount=" + newFileCount + '}'; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + RepositoryStatistics that = (RepositoryStatistics) o; + + if ( newFileCount != that.newFileCount ) + { + return false; + } + if ( totalArtifactCount != that.totalArtifactCount ) + { + return false; + } + if ( totalArtifactFileSize != that.totalArtifactFileSize ) + { + return false; + } + if ( totalFileCount != that.totalFileCount ) + { + return false; + } + if ( totalGroupCount != that.totalGroupCount ) + { + return false; + } + if ( totalProjectCount != that.totalProjectCount ) + { + return false; + } + if ( !scanEndTime.equals( that.scanEndTime ) ) + { + return false; + } + if ( !scanStartTime.equals( that.scanStartTime ) ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = scanEndTime.hashCode(); + result = 31 * result + scanStartTime.hashCode(); + result = 31 * result + (int) ( totalArtifactCount ^ ( totalArtifactCount >>> 32 ) ); + result = 31 * result + (int) ( totalArtifactFileSize ^ ( totalArtifactFileSize >>> 32 ) ); + result = 31 * result + (int) ( totalFileCount ^ ( totalFileCount >>> 32 ) ); + result = 31 * result + (int) ( totalGroupCount ^ ( totalGroupCount >>> 32 ) ); + result = 31 * result + (int) ( totalProjectCount ^ ( totalProjectCount >>> 32 ) ); + result = 31 * result + (int) ( newFileCount ^ ( newFileCount >>> 32 ) ); + return result; + } } diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java index f5388a4b5..6abc44348 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java @@ -26,7 +26,7 @@ public interface RepositoryStatisticsManager { RepositoryStatistics getLastStatistics( String repositoryId ); - void addStatisticsAfterScan( String repositoryId, RepositoryStatistics repositoryStatistics ); + void addStatisticsAfterScan( String repositoryId, Date startTime, Date endTime, long totalFiles, long newFiles ); void deleteStatistics( String repositoryId ); 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 f806291c8..289a33820 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 @@ -29,6 +29,7 @@ import java.util.List; import java.util.Map; import junit.framework.TestCase; +import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; import org.easymock.MockControl; @@ -120,6 +121,8 @@ public class RepositoryStatisticsManagerTest RepositoryStatistics stats = createTestStats( startTime, current ); + walkRepository( 1 ); + metadataRepository.addMetadataFacet( TEST_REPO_ID, stats ); metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), @@ -130,15 +133,15 @@ public class RepositoryStatisticsManagerTest metadataRepositoryControl.replay(); - repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats ); + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, startTime, current, 56345, 45 ); stats = repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ); assertNotNull( stats ); - assertEquals( 1400032000L, stats.getTotalArtifactFileSize() ); + assertEquals( 246900, stats.getTotalArtifactFileSize() ); assertEquals( 45, stats.getNewFileCount() ); - assertEquals( 10412, stats.getTotalArtifactCount() ); - assertEquals( 2036, stats.getTotalProjectCount() ); - assertEquals( 531, stats.getTotalGroupCount() ); + assertEquals( 20, stats.getTotalArtifactCount() ); + assertEquals( 5, stats.getTotalProjectCount() ); + assertEquals( 4, stats.getTotalGroupCount() ); assertEquals( 56345, stats.getTotalFileCount() ); assertEquals( current.getTime() - 12345, stats.getScanStartTime().getTime() ); assertEquals( current, stats.getScanEndTime() ); @@ -148,6 +151,8 @@ public class RepositoryStatisticsManagerTest public void testDeleteStats() { + walkRepository( 2 ); + Date current = new Date(); Date startTime1 = new Date( current.getTime() - 12345 ); @@ -173,8 +178,10 @@ public class RepositoryStatisticsManagerTest metadataRepositoryControl.replay(); - repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats1 ); - repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats2 ); + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, startTime1, stats1.getScanEndTime(), 56345, + 45 ); + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, startTime2, stats2.getScanEndTime(), 56345, + 45 ); assertNotNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) ); @@ -205,6 +212,8 @@ public class RepositoryStatisticsManagerTest public void testGetStatsRangeInside() { + walkRepository( 3 ); + Date current = new Date(); addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) ); @@ -225,7 +234,8 @@ public class RepositoryStatisticsManagerTest for ( RepositoryStatistics stats : statsCreated.values() ) { - repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats ); + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats.getScanStartTime(), + stats.getScanEndTime(), 56345, 45 ); } List list = @@ -240,6 +250,8 @@ public class RepositoryStatisticsManagerTest public void testGetStatsRangeUpperOutside() { + walkRepository( 3 ); + Date current = new Date(); addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) ); @@ -263,7 +275,8 @@ public class RepositoryStatisticsManagerTest for ( RepositoryStatistics stats : statsCreated.values() ) { - repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats ); + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats.getScanStartTime(), + stats.getScanEndTime(), 56345, 45 ); } List list = @@ -279,6 +292,8 @@ public class RepositoryStatisticsManagerTest public void testGetStatsRangeLowerOutside() { + walkRepository( 3 ); + Date current = new Date(); addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) ); @@ -302,7 +317,8 @@ public class RepositoryStatisticsManagerTest for ( RepositoryStatistics stats : statsCreated.values() ) { - repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats ); + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats.getScanStartTime(), + stats.getScanEndTime(), 56345, 45 ); } List list = @@ -318,6 +334,8 @@ public class RepositoryStatisticsManagerTest public void testGetStatsRangeLowerAndUpperOutside() { + walkRepository( 3 ); + Date current = new Date(); addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) ); @@ -345,7 +363,8 @@ public class RepositoryStatisticsManagerTest for ( RepositoryStatistics stats : statsCreated.values() ) { - repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats ); + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats.getScanStartTime(), + stats.getScanEndTime(), 56345, 45 ); } List list = @@ -362,6 +381,8 @@ public class RepositoryStatisticsManagerTest public void testGetStatsRangeNotInside() { + walkRepository( 3 ); + Date current = new Date(); addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) ); @@ -376,7 +397,8 @@ public class RepositoryStatisticsManagerTest for ( RepositoryStatistics stats : statsCreated.values() ) { - repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats ); + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats.getScanStartTime(), + stats.getScanEndTime(), 56345, 45 ); } List list = @@ -395,17 +417,130 @@ public class RepositoryStatisticsManagerTest statsCreated.put( stats.getName(), stats ); } + private ArtifactMetadata createArtifact( String namespace, String projectId, String projectVersion, String type ) + { + ArtifactMetadata metadata = new ArtifactMetadata(); + metadata.setRepositoryId( TEST_REPO_ID ); + metadata.setId( projectId + "-" + projectVersion + "." + type ); + metadata.setProject( projectId ); + metadata.setSize( 12345L ); + metadata.setVersion( projectVersion ); + metadata.setNamespace( namespace ); + return metadata; + } + private RepositoryStatistics createTestStats( Date startTime, Date endTime ) { RepositoryStatistics stats = new RepositoryStatistics(); stats.setScanStartTime( startTime ); stats.setScanEndTime( endTime ); - stats.setTotalArtifactFileSize( 1400032000L ); + stats.setTotalArtifactFileSize( 20 * 12345L ); stats.setNewFileCount( 45 ); - stats.setTotalArtifactCount( 10412 ); - stats.setTotalProjectCount( 2036 ); - stats.setTotalGroupCount( 531 ); + stats.setTotalArtifactCount( 20 ); + stats.setTotalProjectCount( 5 ); + stats.setTotalGroupCount( 4 ); stats.setTotalFileCount( 56345 ); return stats; } + + private void walkRepository( int count ) + { + for ( int i = 0; i < count; i++ ) + { + metadataRepositoryControl.expectAndReturn( metadataRepository.getRootNamespaces( TEST_REPO_ID ), + Arrays.asList( "com", "org" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "com" ), + Arrays.asList() ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "com" ), + Arrays.asList( "example" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "com.example" ), + Arrays.asList() ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "com.example" ), + Arrays.asList( "example-project" ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getProjectVersions( TEST_REPO_ID, "com.example", "example-project" ), + Arrays.asList( "1.0", "1.1" ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", "example-project", "1.0" ), + Arrays.asList( createArtifact( "com.example", "example-project", "1.0", "jar" ), + createArtifact( "com.example", "example-project", "1.0", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", "example-project", "1.1" ), + Arrays.asList( createArtifact( "com.example", "example-project", "1.1", "jar" ), + createArtifact( "com.example", "example-project", "1.1", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org" ), + Arrays.asList( "apache", "codehaus" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache" ), + Arrays.asList( "archiva", "maven" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org.apache" ), + Arrays.asList() ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache.archiva" ), Arrays.asList() ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getProjects( TEST_REPO_ID, "org.apache.archiva" ), + Arrays.asList( "metadata-repository-api", "metadata-model" ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api" ), + Arrays.asList( "1.3-SNAPSHOT", "1.3" ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", + "1.3-SNAPSHOT" ), + Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "jar" ), + createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", + "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3" ), + Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ), + createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "metadata-model" ), + Arrays.asList( "1.3-SNAPSHOT", "1.3" ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT" ), + Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "jar" ), + createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", + "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3" ), + Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ), + createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache.maven" ), Arrays.asList() ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getProjects( TEST_REPO_ID, "org.apache.maven" ), Arrays.asList( "maven-model" ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.maven", "maven-model" ), + Arrays.asList( "2.2.1" ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.maven", "maven-model", "2.2.1" ), + Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "2.2.1", "jar" ), + createArtifact( "org.apache.archiva", "metadata-repository-api", "2.2.1", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus" ), + Arrays.asList( "plexus" ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org" ), + Arrays.asList() ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus" ), + Arrays.asList() ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus.plexus" ), Arrays.asList() ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus.plexus" ), + Arrays.asList( "plexus-spring" ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getProjectVersions( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring" ), + Arrays.asList( "1.0", "1.1", "1.2" ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.0" ), + Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "jar" ), + createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.1" ), + Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "jar" ), + createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "pom" ) ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2" ), + Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "jar" ), + createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "pom" ) ) ); + } + } } -- 2.39.5