diff options
author | Brett Porter <brett@apache.org> | 2010-12-22 01:53:10 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2010-12-22 01:53:10 +0000 |
commit | badcc9e925b9351d2e1d2b198d082245960ee40a (patch) | |
tree | 5ef3f8a7ad494d5560b25fe1ad8ce9bb0dcfd410 | |
parent | 1ff88d24fe6665e01b57eff1e9db76216e942354 (diff) | |
download | archiva-badcc9e925b9351d2e1d2b198d082245960ee40a.tar.gz archiva-badcc9e925b9351d2e1d2b198d082245960ee40a.zip |
[MRM-1327] add exception handling to the metadata repository implementation
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1051732 13f79535-47bb-0310-9956-ffa450edef68
38 files changed, 1455 insertions, 849 deletions
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 61e496f6a..9f06b89aa 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 @@ -23,6 +23,7 @@ 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.MetadataRepositoryException; import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver; import org.apache.maven.archiva.common.utils.VersionUtil; @@ -169,15 +170,24 @@ public class ArchivaMetadataCreationConsumer createVersionMetadata = true; } - // TODO: transaction - // read the metadata and update it if it is newer or doesn't exist - artifact.setWhenGathered( whenGathered ); - metadataRepository.updateArtifact( repoId, project.getNamespace(), project.getId(), projectVersion, artifact ); - if ( createVersionMetadata ) + try + { + // TODO: transaction + // read the metadata and update it if it is newer or doesn't exist + artifact.setWhenGathered( whenGathered ); + metadataRepository.updateArtifact( repoId, project.getNamespace(), project.getId(), projectVersion, + artifact ); + if ( createVersionMetadata ) + { + metadataRepository.updateProjectVersion( repoId, project.getNamespace(), project.getId(), + versionMetadata ); + } + metadataRepository.updateProject( repoId, project ); + } + catch ( MetadataRepositoryException e ) { - metadataRepository.updateProjectVersion( repoId, project.getNamespace(), project.getId(), versionMetadata ); + log.warn( "Error occurred persisting metadata for artifact: " + path + "; message: " + e.getMessage(), e ); } - metadataRepository.updateProject( repoId, project ); } public void processFile( String path, boolean executeOnEntireRepo ) 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 3cfa5786c..c4a8b8ec5 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 @@ -19,8 +19,7 @@ package org.apache.archiva.scheduler.repository; * under the License. */ -import java.util.Date; - +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.stats.RepositoryStatistics; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.archiva.repository.scanner.RepositoryContentConsumers; @@ -38,6 +37,8 @@ import org.codehaus.plexus.taskqueue.execution.TaskExecutor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Date; + /** * ArchivaRepositoryScanningTaskExecutor * @@ -80,7 +81,7 @@ public class ArchivaRepositoryScanningTaskExecutor log.info( "Initialized " + this.getClass().getName() ); } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) public void executeTask( Task task ) throws TaskExecutionException { @@ -103,8 +104,8 @@ public class ArchivaRepositoryScanningTaskExecutor throw new TaskExecutionException( "Unable to execute RepositoryTask with blank repository Id." ); } - ManagedRepositoryConfiguration arepo = - archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId ); + ManagedRepositoryConfiguration arepo = archivaConfiguration.getConfiguration().findManagedRepositoryById( + repoId ); // execute consumers on resource file if set if ( repoTask.getResourceFile() != null ) @@ -117,50 +118,66 @@ public class ArchivaRepositoryScanningTaskExecutor log.info( "Executing task from queue with job name: " + repoTask ); // otherwise, execute consumers on whole repository - try + if ( arepo == null ) { - if ( arepo == null ) - { - throw new TaskExecutionException( - "Unable to execute RepositoryTask with invalid repository id: " + repoId ); - } + throw new TaskExecutionException( + "Unable to execute RepositoryTask with invalid repository id: " + repoId ); + } - long sinceWhen = RepositoryScanner.FRESH_SCAN; - long previousFileCount = 0; + long sinceWhen = RepositoryScanner.FRESH_SCAN; + long previousFileCount = 0; - if ( !repoTask.isScanAll() ) + if ( !repoTask.isScanAll() ) + { + RepositoryStatistics previousStats; + try + { + previousStats = repositoryStatisticsManager.getLastStatistics( repoId ); + } + catch ( MetadataRepositoryException e ) + { + throw new TaskExecutionException( "Unable to get previous statistics: " + e.getMessage(), e ); + } + if ( previousStats != null ) { - RepositoryStatistics previousStats = repositoryStatisticsManager.getLastStatistics( repoId ); - if ( previousStats != null ) - { - sinceWhen = previousStats.getScanStartTime().getTime(); - previousFileCount = previousStats.getTotalFileCount(); - } + sinceWhen = previousStats.getScanStartTime().getTime(); + previousFileCount = previousStats.getTotalFileCount(); } + } - RepositoryScanStatistics stats = repoScanner.scan( arepo, sinceWhen ); + RepositoryScanStatistics stats; + try + { + stats = repoScanner.scan( arepo, sinceWhen ); + } + catch ( RepositoryScannerException e ) + { + throw new TaskExecutionException( "Repository error when executing repository job.", e ); + } - log.info( "Finished first scan: " + stats.toDump( arepo ) ); + log.info( "Finished first scan: " + stats.toDump( arepo ) ); - // further statistics will be populated by the following method - Date endTime = new Date( stats.getWhenGathered().getTime() + stats.getDuration() ); + // further statistics will be populated by the following method + Date endTime = new Date( stats.getWhenGathered().getTime() + stats.getDuration() ); + try + { repositoryStatisticsManager.addStatisticsAfterScan( repoId, stats.getWhenGathered(), endTime, stats.getTotalFileCount(), stats.getTotalFileCount() - previousFileCount ); + } + catch ( MetadataRepositoryException e ) + { + throw new TaskExecutionException( "Unable to store updated statistics: " + e.getMessage(), e ); + } // log.info( "Scanning for removed repository content" ); // metadataRepository.findAllProjects(); - // FIXME: do something + // FIXME: do something - log.info( "Finished repository task: " + repoTask ); + log.info( "Finished repository task: " + repoTask ); - this.task = null; - } - catch ( RepositoryScannerException e ) - { - throw new TaskExecutionException( "Repository error when executing repository job.", e ); - } + this.task = null; } } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java index 603e6debc..ce02452a6 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java @@ -19,12 +19,7 @@ package org.apache.archiva.scheduler.repository; * under the License. */ -import java.text.ParseException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.archiva.scheduler.ArchivaTaskScheduler; import org.apache.maven.archiva.common.ArchivaException; @@ -46,6 +41,12 @@ import org.quartz.SchedulerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + /** * Default implementation of a scheduling component for archiva. * @@ -110,28 +111,36 @@ public class RepositoryArchivaTaskScheduler public void start() throws StartingException { - try - { - List<ManagedRepositoryConfiguration> repositories = archivaConfiguration.getConfiguration() - .getManagedRepositories(); + List<ManagedRepositoryConfiguration> repositories = + archivaConfiguration.getConfiguration().getManagedRepositories(); - for ( ManagedRepositoryConfiguration repoConfig : repositories ) + for ( ManagedRepositoryConfiguration repoConfig : repositories ) + { + if ( repoConfig.isScanned() ) { - if ( repoConfig.isScanned() ) + try { scheduleRepositoryJobs( repoConfig ); + } + catch ( SchedulerException e ) + { + throw new StartingException( "Unable to start scheduler: " + e.getMessage(), e ); + } - if( !isPreviouslyScanned( repoConfig ) ) + try + { + if ( !isPreviouslyScanned( repoConfig ) ) { queueInitialRepoScan( repoConfig ); } } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to determine if a repository is already scanned, skipping initial scan: " + + e.getMessage(), e ); + } } } - catch ( SchedulerException e ) - { - throw new StartingException( "Unable to start scheduler: " + e.getMessage(), e ); - } } public void stop() @@ -152,10 +161,10 @@ public class RepositoryArchivaTaskScheduler } } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) public boolean isProcessingRepositoryTask( String repositoryId ) { - synchronized( repositoryScanningQueue ) + synchronized ( repositoryScanningQueue ) { List<RepositoryTask> queue = null; @@ -179,10 +188,10 @@ public class RepositoryArchivaTaskScheduler } } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) private boolean isProcessingRepositoryTask( RepositoryTask task ) { - synchronized( repositoryScanningQueue ) + synchronized ( repositoryScanningQueue ) { List<RepositoryTask> queue = null; @@ -240,7 +249,8 @@ public class RepositoryArchivaTaskScheduler } jobs.clear(); - List<ManagedRepositoryConfiguration> repositories = archivaConfiguration.getConfiguration().getManagedRepositories(); + List<ManagedRepositoryConfiguration> repositories = + archivaConfiguration.getConfiguration().getManagedRepositories(); for ( ManagedRepositoryConfiguration repoConfig : repositories ) { @@ -259,8 +269,9 @@ public class RepositoryArchivaTaskScheduler } } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) private boolean isPreviouslyScanned( ManagedRepositoryConfiguration repoConfig ) + throws MetadataRepositoryException { return repositoryStatisticsManager.getLastStatistics( repoConfig.getId() ) != null; } @@ -310,13 +321,13 @@ public class RepositoryArchivaTaskScheduler if ( !cronValidator.validate( cronString ) ) { log.warn( "Cron expression [" + cronString + "] for repository [" + repoConfig.getId() + - "] is invalid. Defaulting to hourly." ); + "] is invalid. Defaulting to hourly." ); cronString = CRON_HOURLY; } // setup the unprocessed artifact job - JobDetail repositoryJob = - new JobDetail( REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP, RepositoryTaskJob.class ); + JobDetail repositoryJob = new JobDetail( REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP, + RepositoryTaskJob.class ); JobDataMap dataMap = new JobDataMap(); dataMap.put( TASK_QUEUE, repositoryScanningQueue ); @@ -325,17 +336,16 @@ public class RepositoryArchivaTaskScheduler try { - CronTrigger trigger = - new CronTrigger( REPOSITORY_JOB_TRIGGER + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP, cronString ); + CronTrigger trigger = new CronTrigger( REPOSITORY_JOB_TRIGGER + ":" + repoConfig.getId(), + REPOSITORY_SCAN_GROUP, cronString ); jobs.add( REPOSITORY_JOB + ":" + repoConfig.getId() ); scheduler.scheduleJob( repositoryJob, trigger ); } catch ( ParseException e ) { - log.error( - "ParseException in repository scanning cron expression, disabling repository scanning for '" + - repoConfig.getId() + "': " + e.getMessage() ); + log.error( "ParseException in repository scanning cron expression, disabling repository scanning for '" + + repoConfig.getId() + "': " + e.getMessage() ); } } 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 1df470dc9..06b32a85f 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 @@ -19,12 +19,7 @@ package org.apache.archiva.scheduler.repository; * under the License. */ -import java.io.File; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.List; - +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.stats.RepositoryStatistics; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -35,6 +30,12 @@ import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.codehaus.plexus.taskqueue.execution.TaskExecutor; import org.codehaus.plexus.util.FileUtils; +import java.io.File; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.List; + /** * ArchivaRepositoryScanningTaskExecutorTest * @@ -294,6 +295,7 @@ public class ArchivaRepositoryScanningTaskExecutorTest } private void createAndSaveTestStats() + throws MetadataRepositoryException { Date date = Calendar.getInstance().getTime(); RepositoryStatistics stats = new RepositoryStatistics(); diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java index c7d81921c..027ce4ee3 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java @@ -19,32 +19,34 @@ package org.apache.archiva.rss.processor; * under the License. */ -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.TimeZone; - import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.rss.RssFeedEntry; import org.apache.archiva.rss.RssFeedGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; + /** * Retrieve and process all artifacts of a repository from the database and generate a rss feed. - * The artifacts will be grouped by the date when the artifacts were gathered. + * The artifacts will be grouped by the date when the artifacts were gathered. * Each group will appear as one entry in the feed. - * + * * @plexus.component role="org.apache.archiva.rss.processor.RssFeedProcessor" role-hint="new-artifacts" */ public class NewArtifactsRssFeedProcessor extends AbstractArtifactsRssFeedProcessor { private int numberOfDaysBeforeNow = 30; - + private static final String title = "New Artifacts in Repository "; private static final String desc = "These are the new artifacts found in the repository "; @@ -63,6 +65,7 @@ public class NewArtifactsRssFeedProcessor * new versions of artifact. */ public SyndFeed process( Map<String, String> reqParams ) + throws FeedException { log.debug( "Process new artifacts into rss feeds." ); @@ -76,13 +79,22 @@ public class NewArtifactsRssFeedProcessor } private SyndFeed processNewArtifactsInRepo( String repoId ) + throws FeedException { Calendar greaterThanThisDate = Calendar.getInstance( GMT_TIME_ZONE ); greaterThanThisDate.add( Calendar.DATE, -( getNumberOfDaysBeforeNow() ) ); greaterThanThisDate.clear( Calendar.MILLISECOND ); - List<ArtifactMetadata> artifacts = - metadataRepository.getArtifactsByDateRange( repoId, greaterThanThisDate.getTime(), null ); + List<ArtifactMetadata> artifacts = null; + try + { + artifacts = metadataRepository.getArtifactsByDateRange( repoId, greaterThanThisDate.getTime(), null ); + } + catch ( MetadataRepositoryException e ) + { + throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), + e ); + } long tmp = 0; RssFeedEntry entry = null; @@ -104,7 +116,8 @@ public class NewArtifactsRssFeedProcessor } String repoId1 = artifact.getRepositoryId(); - entry = new RssFeedEntry( this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date( whenGathered ) ); + entry = new RssFeedEntry( this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date( + whenGathered ) ); entry.setPublishedDate( artifact.getWhenGathered() ); description = this.getDescription() + "\'" + repoId1 + "\'" + ": \n" + id + " | "; } @@ -123,8 +136,9 @@ public class NewArtifactsRssFeedProcessor idx++; } - return generator.generateFeed( getTitle() + "\'" + repoId + "\'", "New artifacts found in repository " + - "\'" + repoId + "\'" + " during repository scan.", entries ); + return generator.generateFeed( getTitle() + "\'" + repoId + "\'", + "New artifacts found in repository " + "\'" + repoId + "\'" + + " during repository scan.", entries ); } public String getTitle() 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 53cf9f4cf..f90b22a2a 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 @@ -19,17 +19,22 @@ package org.apache.archiva.rss.processor; * under the License. */ +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; +import org.apache.archiva.metadata.repository.MetadataResolutionException; +import org.apache.archiva.rss.RssFeedEntry; +import org.apache.archiva.rss.RssFeedGenerator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Map; -import com.sun.syndication.feed.synd.SyndFeed; -import org.apache.archiva.metadata.model.ArtifactMetadata; -import org.apache.archiva.rss.RssFeedEntry; -import org.apache.archiva.rss.RssFeedGenerator; - /** * Retrieve and process new versions of an artifact from the database and * generate a rss feed. The versions will be grouped by the date when the artifact @@ -40,6 +45,8 @@ import org.apache.archiva.rss.RssFeedGenerator; public class NewVersionsOfArtifactRssFeedProcessor extends AbstractArtifactsRssFeedProcessor { + private Logger log = LoggerFactory.getLogger( NewVersionsOfArtifactRssFeedProcessor.class ); + private static final String title = "New Versions of Artifact "; private static final String desc = "These are the new versions of artifact "; @@ -53,6 +60,7 @@ public class NewVersionsOfArtifactRssFeedProcessor * Process all versions of the artifact which had a rss feed request. */ public SyndFeed process( Map<String, String> reqParams ) + throws FeedException { String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_ID ); String artifactId = reqParams.get( RssFeedProcessor.KEY_ARTIFACT_ID ); @@ -66,16 +74,30 @@ public class NewVersionsOfArtifactRssFeedProcessor } private SyndFeed processNewVersionsOfArtifact( String groupId, String artifactId ) + throws FeedException { List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(); - for ( String repoId : metadataRepository.getRepositories() ) + try { - Collection<String> versions = metadataRepository.getProjectVersions( repoId, groupId, artifactId ); - for ( String version : versions ) + for ( String repoId : metadataRepository.getRepositories() ) { - artifacts.addAll( metadataRepository.getArtifacts( repoId, groupId, artifactId, version ) ); + Collection<String> versions = metadataRepository.getProjectVersions( repoId, groupId, artifactId ); + for ( String version : versions ) + { + artifacts.addAll( metadataRepository.getArtifacts( repoId, groupId, artifactId, version ) ); + } } } + catch ( MetadataRepositoryException e ) + { + throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), + e ); + } + catch ( MetadataResolutionException e ) + { + throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), + e ); + } long tmp = 0; RssFeedEntry entry = null; 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 face4bd57..d8d7cb878 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 @@ -19,9 +19,10 @@ package org.apache.archiva.rss.processor; * under the License. */ -import java.util.Map; - import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; + +import java.util.Map; /** * Retrieve and process the data that will be fed into the RssFeedGenerator. @@ -34,5 +35,6 @@ public interface RssFeedProcessor public static final String KEY_ARTIFACT_ID = "artifactId"; - SyndFeed process( Map<String, String> reqParams ); + SyndFeed process( Map<String, String> reqParams ) + throws FeedException; } diff --git a/archiva-modules/archiva-web/archiva-webapp/pom.xml b/archiva-modules/archiva-web/archiva-webapp/pom.xml index 6536bd71a..65b30b1b9 100644 --- a/archiva-modules/archiva-web/archiva-webapp/pom.xml +++ b/archiva-modules/archiva-web/archiva-webapp/pom.xml @@ -288,6 +288,11 @@ <!-- FIXME: temporary coupling to plugin, should be runtime --> <artifactId>maven2-repository</artifactId> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> <resources> 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 ceb9ca8b2..1d5c7d456 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 @@ -19,13 +19,6 @@ package org.apache.maven.archiva.web.action; * under the License. */ -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.metadata.repository.MetadataResolver; @@ -33,6 +26,13 @@ import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + /** * Browse the repository. * @@ -62,6 +62,7 @@ public class BrowseAction private Collection<String> projectVersions; public String browse() + throws MetadataResolutionException { List<String> selectedRepos = getObservableRepos(); if ( CollectionUtils.isEmpty( selectedRepos ) ) @@ -91,6 +92,7 @@ public class BrowseAction } private String collapseNamespaces( Collection<String> repoIds, String n ) + throws MetadataResolutionException { Set<String> subNamespaces = new LinkedHashSet<String>(); for ( String repoId : repoIds ) @@ -124,6 +126,7 @@ public class BrowseAction } public String browseGroup() + throws MetadataResolutionException { if ( StringUtils.isEmpty( groupId ) ) { @@ -171,6 +174,7 @@ public class BrowseAction } public String browseArtifact() + throws MetadataResolutionException { if ( StringUtils.isEmpty( groupId ) ) { @@ -249,8 +253,8 @@ public class BrowseAction } else { - MavenProjectFacet versionMetadataMavenFacet = - (MavenProjectFacet) versionMetadata.getFacet( MavenProjectFacet.FACET_ID ); + MavenProjectFacet versionMetadataMavenFacet = (MavenProjectFacet) versionMetadata.getFacet( + MavenProjectFacet.FACET_ID ); if ( versionMetadataMavenFacet != null ) { if ( mavenFacet.getPackaging() != null && !StringUtils.equalsIgnoreCase( mavenFacet.getPackaging(), @@ -260,14 +264,14 @@ public class BrowseAction } } - if ( sharedModel.getName() != null && - !StringUtils.equalsIgnoreCase( sharedModel.getName(), versionMetadata.getName() ) ) + if ( sharedModel.getName() != null && !StringUtils.equalsIgnoreCase( sharedModel.getName(), + versionMetadata.getName() ) ) { sharedModel.setName( "" ); } - if ( sharedModel.getDescription() != null && - !StringUtils.equalsIgnoreCase( sharedModel.getDescription(), versionMetadata.getDescription() ) ) + if ( sharedModel.getDescription() != null && !StringUtils.equalsIgnoreCase( + sharedModel.getDescription(), versionMetadata.getDescription() ) ) { sharedModel.setDescription( null ); } @@ -293,8 +297,8 @@ public class BrowseAction sharedModel.setOrganization( null ); } - if ( sharedModel.getUrl() != null && - !StringUtils.equalsIgnoreCase( sharedModel.getUrl(), versionMetadata.getUrl() ) ) + if ( sharedModel.getUrl() != null && !StringUtils.equalsIgnoreCase( sharedModel.getUrl(), + versionMetadata.getUrl() ) ) { sharedModel.setUrl( null ); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java index 83ff863b3..d389e283d 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java @@ -27,6 +27,8 @@ import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; +import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.common.utils.VersionComparator; import org.apache.maven.archiva.common.utils.VersionUtil; @@ -199,8 +201,8 @@ public class DeleteArtifactAction TimeZone timezone = TimeZone.getTimeZone( "UTC" ); DateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" ); fmt.setTimeZone( timezone ); - ManagedRepositoryConfiguration repoConfig = - configuration.getConfiguration().findManagedRepositoryById( repositoryId ); + ManagedRepositoryConfiguration repoConfig = configuration.getConfiguration().findManagedRepositoryById( + repositoryId ); VersionedReference ref = new VersionedReference(); ref.setArtifactId( artifactId ); @@ -228,8 +230,8 @@ public class DeleteArtifactAction updateMetadata( metadata, metadataFile, lastUpdatedTimestamp ); - Collection<ArtifactMetadata> artifacts = - metadataRepository.getArtifacts( repositoryId, groupId, artifactId, version ); + Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts( repositoryId, groupId, artifactId, + version ); for ( ArtifactMetadata artifact : artifacts ) { @@ -237,8 +239,7 @@ public class DeleteArtifactAction if ( artifact.getVersion().equals( version ) ) { metadataRepository.deleteArtifact( artifact.getRepositoryId(), artifact.getNamespace(), - artifact.getProject(), artifact.getVersion(), - artifact.getId() ); + artifact.getProject(), artifact.getVersion(), artifact.getId() ); // TODO: move into the metadata repository proper - need to differentiate attachment of // repository metadata to an artifact @@ -275,6 +276,16 @@ public class DeleteArtifactAction addActionError( "Repository exception: " + e.getMessage() ); return ERROR; } + catch ( MetadataResolutionException e ) + { + addActionError( "Repository exception: " + e.getMessage() ); + return ERROR; + } + catch ( MetadataRepositoryException e ) + { + addActionError( "Repository exception: " + e.getMessage() ); + return ERROR; + } } private File getMetadata( String targetPath ) 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 85f90930d..93dae804c 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 @@ -20,7 +20,6 @@ package org.apache.maven.archiva.web.action; */ import com.opensymphony.xwork2.Validateable; - import org.apache.archiva.metadata.generic.GenericMetadataFacet; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.Dependency; @@ -28,6 +27,7 @@ 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.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; @@ -49,12 +49,12 @@ import java.util.List; import java.util.Map; /** - * Browse the repository. - * + * Browse the repository. + * * TODO change name to ShowVersionedAction to conform to terminology. - * + * * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="showArtifactAction" - * instantiation-strategy="per-lookup" + * instantiation-strategy="per-lookup" */ @SuppressWarnings( "serial" ) public class ShowArtifactAction @@ -171,9 +171,19 @@ public class ShowArtifactAction { repositoryId = repoId; - List<ArtifactMetadata> artifacts = - new ArrayList<ArtifactMetadata>( metadataResolver.getArtifacts( repoId, groupId, artifactId, - version ) ); + List<ArtifactMetadata> artifacts; + try + { + artifacts = new ArrayList<ArtifactMetadata>( metadataResolver.getArtifacts( repoId, groupId, + artifactId, + version ) ); + } + catch ( MetadataResolutionException e ) + { + addIncompleteModelWarning(); + + artifacts = Collections.emptyList(); + } Collections.sort( artifacts, new Comparator<ArtifactMetadata>() { public int compare( ArtifactMetadata o1, ArtifactMetadata o2 ) @@ -181,9 +191,8 @@ public class ShowArtifactAction // sort by version (reverse), then ID // TODO: move version sorting into repository handling (maven2 specific), and perhaps add a // way to get latest instead - int result = - new DefaultArtifactVersion( o2.getVersion() ).compareTo( new DefaultArtifactVersion( - o1.getVersion() ) ); + int result = new DefaultArtifactVersion( o2.getVersion() ).compareTo( + new DefaultArtifactVersion( o1.getVersion() ) ); return result != 0 ? result : o1.getId().compareTo( o2.getId() ); } } ); @@ -207,7 +216,8 @@ public class ShowArtifactAction private void addIncompleteModelWarning() { - addActionMessage( "The model may be incomplete due to a previous error in resolving information. Refer to the repository problem reports for more information." ); + addActionMessage( + "The model may be incomplete due to a previous error in resolving information. Refer to the repository problem reports for more information." ); } /** @@ -248,6 +258,7 @@ public class ShowArtifactAction * Show the dependees (other artifacts that depend on this project) tab. */ public String dependees() + throws MetadataResolutionException { List<ProjectVersionReference> references = new ArrayList<ProjectVersionReference>(); // TODO: what if we get duplicates across repositories? @@ -321,8 +332,8 @@ public class ShowArtifactAction genericMetadata = projectMetadata.getFacet( GenericMetadataFacet.FACET_ID ).toProperties(); } - if ( propertyName == null || "".equals( propertyName.trim() ) || propertyValue == null || - "".equals( propertyValue.trim() ) ) + if ( propertyName == null || "".equals( propertyName.trim() ) || propertyValue == null || "".equals( + propertyValue.trim() ) ) { model = projectMetadata; addActionError( errorMsg != null ? errorMsg : "Property Name and Property Value are required." ); @@ -331,7 +342,16 @@ public class ShowArtifactAction genericMetadata.put( propertyName, propertyValue ); - updateProjectMetadata( projectMetadata ); + try + { + updateProjectMetadata( projectMetadata ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to persist modified project metadata after adding entry: " + e.getMessage(), e ); + addActionError( "Unable to add metadata item to underlying content storage - consult application logs." ); + return ERROR; + } projectMetadata = getProjectVersionMetadata(); @@ -352,7 +372,7 @@ public class ShowArtifactAction if ( projectMetadata == null ) { - addActionError( errorMsg != null ? errorMsg : "Artifact not found" ); + addActionError( "Artifact not found" ); return ERROR; } @@ -364,7 +384,18 @@ public class ShowArtifactAction { genericMetadata.remove( deleteItem ); - updateProjectMetadata( projectMetadata ); + try + { + updateProjectMetadata( projectMetadata ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to persist modified project metadata after removing entry: " + e.getMessage(), + e ); + addActionError( + "Unable to remove metadata item to underlying content storage - consult application logs." ); + return ERROR; + } projectMetadata = getProjectVersionMetadata(); @@ -379,7 +410,7 @@ public class ShowArtifactAction } else { - addActionError( errorMsg != null ? errorMsg : "No generic metadata facet for this artifact." ); + addActionError( "No generic metadata facet for this artifact." ); return ERROR; } @@ -387,6 +418,7 @@ public class ShowArtifactAction } private void updateProjectMetadata( ProjectVersionMetadata projectMetadata ) + throws MetadataRepositoryException { GenericMetadataFacet genericMetadataFacet = new GenericMetadataFacet(); genericMetadataFacet.fromProperties( genericMetadata ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java index 2cfc4b199..92fcc959e 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java @@ -22,6 +22,7 @@ package org.apache.maven.archiva.web.action.admin.repositories; import com.opensymphony.xwork2.Preparable; import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; @@ -35,7 +36,7 @@ import java.util.Map; /** * DeleteManagedRepositoryAction - * + * * @version $Id$ * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="deleteManagedRepositoryAction" instantiation-strategy="per-lookup" */ @@ -64,7 +65,8 @@ public class DeleteManagedRepositoryAction if ( StringUtils.isNotBlank( repoid ) ) { this.repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid ); - this.stagingRepository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid +"-stage"); + this.stagingRepository = archivaConfiguration.getConfiguration().findManagedRepositoryById( + repoid + "-stage" ); } } @@ -104,23 +106,23 @@ public class DeleteManagedRepositoryAction try { Configuration configuration = archivaConfiguration.getConfiguration(); - cleanupRepositoryData( existingRepository ); - removeRepository( repoid, configuration ); - triggerAuditEvent( repoid, null, AuditEvent.DELETE_MANAGED_REPO ); - if(attachedStagingRepo !=null) + if ( attachedStagingRepo != null ) { cleanupRepositoryData( attachedStagingRepo ); - removeRepository( repoid +"-stage", configuration ); - triggerAuditEvent(repoid +"-stage", null, AuditEvent.DELETE_MANAGED_REPO ); + removeRepository( repoid + "-stage", configuration ); + triggerAuditEvent( repoid + "-stage", null, AuditEvent.DELETE_MANAGED_REPO ); } + cleanupRepositoryData( existingRepository ); + removeRepository( repoid, configuration ); + triggerAuditEvent( repoid, null, AuditEvent.DELETE_MANAGED_REPO ); result = saveConfiguration( configuration ); if ( result.equals( SUCCESS ) ) { if ( deleteContents ) { - if(attachedStagingRepo !=null) + if ( attachedStagingRepo != null ) { removeContents( attachedStagingRepo ); } @@ -130,12 +132,20 @@ public class DeleteManagedRepositoryAction } catch ( IOException e ) { - addActionError( "Unable to delete repository: " + e.getMessage() ); + addActionError( + "Unable to delete repository, content may already be partially removed: " + e.getMessage() ); result = ERROR; } catch ( RoleManagerException e ) { - addActionError( "Unable to delete repository: " + e.getMessage() ); + addActionError( + "Unable to delete repository, content may already be partially removed: " + e.getMessage() ); + result = ERROR; + } + catch ( MetadataRepositoryException e ) + { + addActionError( + "Unable to delete repository, content may already be partially removed: " + e.getMessage() ); result = ERROR; } @@ -143,7 +153,7 @@ public class DeleteManagedRepositoryAction } private void cleanupRepositoryData( ManagedRepositoryConfiguration cleanupRepository ) - throws RoleManagerException + throws RoleManagerException, MetadataRepositoryException { removeRepositoryRoles( cleanupRepository ); cleanupDatabase( cleanupRepository.getId() ); @@ -160,20 +170,22 @@ public class DeleteManagedRepositoryAction } Map<String, List<String>> repoToGroupMap = archivaConfiguration.getConfiguration().getRepositoryToGroupMap(); - if( repoToGroupMap != null ) + if ( repoToGroupMap != null ) { - if( repoToGroupMap.containsKey( cleanupRepository.getId() ) ) + if ( repoToGroupMap.containsKey( cleanupRepository.getId() ) ) { List<String> repoGroups = repoToGroupMap.get( cleanupRepository.getId() ); - for( String repoGroup : repoGroups ) + for ( String repoGroup : repoGroups ) { - archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository( cleanupRepository.getId() ); + archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository( + cleanupRepository.getId() ); } } } } private void cleanupDatabase( String repoId ) + throws MetadataRepositoryException { metadataRepository.deleteRepository( repoId ); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java index a0a4f7cf6..b29d5dec0 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java @@ -22,6 +22,7 @@ package org.apache.maven.archiva.web.action.admin.repositories; import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.Validateable; import org.apache.archiva.audit.AuditEvent; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; @@ -144,7 +145,7 @@ public class EditManagedRepositoryAction //delete staging repo when we dont need it if ( !stageNeeded ) { - stagingRepository = getStageRepoConfig(configuration); + stagingRepository = getStageRepoConfig( configuration ); removeRepository( stagingRepository.getId(), configuration ); removeContents( stagingRepository ); removeRepositoryRoles( stagingRepository ); @@ -166,6 +167,11 @@ public class EditManagedRepositoryAction addActionError( "Role Manager Exception: " + e.getMessage() ); result = ERROR; } + catch ( MetadataRepositoryException e ) + { + addActionError( "Metadata Exception: " + e.getMessage() ); + result = ERROR; + } return result; } @@ -177,7 +183,7 @@ public class EditManagedRepositoryAction if ( repoConf.getId().equals( repository.getId() + "-stage" ) ) { stagingRepository = repoConf; - removeRepository( repoConf .getId() , configuration); + removeRepository( repoConf.getId(), configuration ); updateStagingRepository( stagingRepository ); return stagingRepository; } @@ -220,6 +226,7 @@ public class EditManagedRepositoryAction } private void resetStatistics() + throws MetadataRepositoryException { repositoryStatisticsManager.deleteStatistics( repository.getId() ); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java index 3d0a739d6..caf61f06e 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java @@ -19,14 +19,8 @@ package org.apache.maven.archiva.web.action.admin.repositories; * under the License. */ -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.servlet.http.HttpServletRequest; - import com.opensymphony.xwork2.Preparable; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.stats.RepositoryStatistics; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -43,6 +37,13 @@ import org.codehaus.redback.integration.interceptor.SecureAction; import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; + /** * Shows the Repositories Tab for the administrator. * @@ -108,7 +109,17 @@ public class RepositoriesAction repositoryStatistics = new HashMap<String, RepositoryStatistics>(); for ( ManagedRepositoryConfiguration repo : managedRepositories ) { - RepositoryStatistics stats = repositoryStatisticsManager.getLastStatistics( repo.getId() ); + RepositoryStatistics stats = null; + try + { + stats = repositoryStatisticsManager.getLastStatistics( repo.getId() ); + } + catch ( MetadataRepositoryException e ) + { + addActionError( + "Error retrieving statistics for repository " + repo.getId() + " - consult application logs" ); + log.warn( "Error retrieving repository statistics: " + e.getMessage(), e ); + } if ( stats != null ) { repositoryStatistics.put( repo.getId(), stats ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java index 4ee425f63..abd346192 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java @@ -19,22 +19,9 @@ package org.apache.maven.archiva.web.action.reports; * under the License. */ -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - import com.opensymphony.xwork2.Preparable; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.stats.RepositoryStatistics; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.archiva.reports.RepositoryProblemFacet; @@ -51,6 +38,20 @@ import org.codehaus.redback.integration.interceptor.SecureActionException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + /** * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="generateReport" instantiation-strategy="per-lookup" */ @@ -114,7 +115,7 @@ public class GenerateReportAction */ private MetadataRepository metadataRepository; - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) public void prepare() { repositoryIds = new ArrayList<String>(); @@ -186,9 +187,16 @@ public class GenerateReportAction // multiple repos for ( String repo : selectedRepositories ) { - List<RepositoryStatistics> stats = - repositoryStatisticsManager.getStatisticsInRange( repo, startDateInDF, endDateInDF ); - if ( stats.isEmpty() ) + List<RepositoryStatistics> stats = null; + try + { + stats = repositoryStatisticsManager.getStatisticsInRange( repo, startDateInDF, endDateInDF ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to retrieve stats, assuming is empty: " + e.getMessage(), e ); + } + if ( stats == null || stats.isEmpty() ) { log.info( "No statistics available for repository '" + repo + "'." ); // TODO set repo's stats to 0 @@ -212,10 +220,17 @@ public class GenerateReportAction return INPUT; } - List<RepositoryStatistics> stats = - repositoryStatisticsManager.getStatisticsInRange( repositoryId, startDateInDF, endDateInDF ); - - if ( stats.isEmpty() ) + List<RepositoryStatistics> stats = null; + try + { + stats = repositoryStatisticsManager.getStatisticsInRange( repositoryId, startDateInDF, + endDateInDF ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to retrieve stats, assuming is empty: " + e.getMessage(), e ); + } + if ( stats == null || stats.isEmpty() ) { addActionError( "No statistics available for repository. Repository might not have been scanned." ); return ERROR; @@ -304,9 +319,16 @@ public class GenerateReportAction // multiple repos for ( String repo : selectedRepositories ) { - List<RepositoryStatistics> stats = - repositoryStatisticsManager.getStatisticsInRange( repo, startDateInDF, endDateInDF ); - if ( stats.isEmpty() ) + List<RepositoryStatistics> stats = null; + try + { + stats = repositoryStatisticsManager.getStatisticsInRange( repo, startDateInDF, endDateInDF ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to retrieve stats, assuming is empty: " + e.getMessage(), e ); + } + if ( stats == null || stats.isEmpty() ) { log.info( "No statistics available for repository '" + repo + "'." ); // TODO set repo's stats to 0 @@ -344,9 +366,17 @@ public class GenerateReportAction return INPUT; } - List<RepositoryStatistics> stats = - repositoryStatisticsManager.getStatisticsInRange( repositoryId, startDateInDF, endDateInDF ); - if ( stats.isEmpty() ) + List<RepositoryStatistics> stats = null; + try + { + stats = repositoryStatisticsManager.getStatisticsInRange( repositoryId, startDateInDF, + endDateInDF ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to retrieve stats, assuming is empty: " + e.getMessage(), e ); + } + if ( stats == null || stats.isEmpty() ) { addActionError( "No statistics available for repository. Repository might not have been scanned." ); return ERROR; @@ -503,10 +533,8 @@ public class GenerateReportAction // TODO: improve performance by navigating into a group subtree. Currently group is property, not part of name of item for ( String name : metadataRepository.getMetadataFacets( repoId, RepositoryProblemFacet.FACET_ID ) ) { - RepositoryProblemFacet metadataFacet = - (RepositoryProblemFacet) metadataRepository.getMetadataFacet( repoId, - RepositoryProblemFacet.FACET_ID, - name ); + RepositoryProblemFacet metadataFacet = (RepositoryProblemFacet) metadataRepository.getMetadataFacet( + repoId, RepositoryProblemFacet.FACET_ID, name ); if ( StringUtils.isEmpty( groupId ) || groupId.equals( metadataFacet.getNamespace() ) ) { 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 c80cb3e3e..bee91623c 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 @@ -19,14 +19,14 @@ package org.apache.maven.archiva.web.action; * under the License. */ -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - import com.opensymphony.xwork2.Action; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.repository.memory.TestMetadataResolver; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + public class BrowseActionTest extends AbstractActionTestCase { @@ -34,9 +34,8 @@ public class BrowseActionTest private BrowseAction action; - private static final List<String> GROUPS = - Arrays.asList( "org.apache.archiva", "commons-lang", "org.apache.maven", "com.sun", "com.oracle", - "repeat.repeat" ); + private static final List<String> GROUPS = Arrays.asList( "org.apache.archiva", "commons-lang", "org.apache.maven", + "com.sun", "com.oracle", "repeat.repeat" ); private static final String OTHER_TEST_REPO = "other-repo"; @@ -46,6 +45,7 @@ public class BrowseActionTest } public void testBrowse() + throws Exception { metadataResolver.setNamespaces( TEST_REPO, GROUPS ); @@ -63,6 +63,7 @@ public class BrowseActionTest } public void testBrowseNoObservableRepos() + throws Exception { setObservableRepos( Collections.<String>emptyList() ); @@ -73,6 +74,7 @@ public class BrowseActionTest } public void testBrowseGroupNoObservableRepos() + throws Exception { setObservableRepos( Collections.<String>emptyList() ); String selectedGroupId = "org"; @@ -91,6 +93,7 @@ public class BrowseActionTest } public void testBrowseArtifactNoObservableRepos() + throws Exception { setObservableRepos( Collections.<String>emptyList() ); String selectedGroupId = "org.apache"; @@ -111,6 +114,7 @@ public class BrowseActionTest } public void testBrowseGroupNoGroupId() + throws Exception { String result = action.browseGroup(); assertErrorResult( result ); @@ -118,6 +122,7 @@ public class BrowseActionTest } public void testBrowseGroupNoArtifacts() + throws Exception { String selectedGroupId = "org"; List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache.maven" ); @@ -138,6 +143,7 @@ public class BrowseActionTest } public void testBrowseGroupWithArtifacts() + throws Exception { String artifacts = "apache"; String selectedGroupId = "org.apache"; @@ -160,6 +166,7 @@ public class BrowseActionTest } public void testBrowseWithCollapsedGroupsAndArtifacts() + throws Exception { List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache" ); @@ -181,6 +188,7 @@ public class BrowseActionTest } public void testBrowseWithCollapsedGroupsAndArtifactsAcrossRepositories() + throws Exception { setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) ); @@ -204,6 +212,7 @@ public class BrowseActionTest } public void testBrowseGroupWithCollapsedGroupsAndArtifacts() + throws Exception { String artifacts = "apache"; String selectedGroupId = "org.apache"; @@ -228,6 +237,7 @@ public class BrowseActionTest } public void testBrowseArtifactNoGroupId() + throws Exception { String selectedArtifactId = "apache"; @@ -245,6 +255,7 @@ public class BrowseActionTest } public void testBrowseArtifactNoArtifactId() + throws Exception { String selectedGroupId = "org.apache"; @@ -262,19 +273,21 @@ public class BrowseActionTest } public void testBrowseArtifact() + throws Exception + { String selectedGroupId = "org.apache"; String selectedArtifactId = "apache"; List<String> versions = Arrays.asList( "1", "2", "3", "4" ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, - createProjectModel( selectedGroupId, selectedArtifactId, "1" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, - createProjectModel( selectedGroupId, selectedArtifactId, "2" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, - createProjectModel( selectedGroupId, selectedArtifactId, "3" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, - createProjectModel( selectedGroupId, selectedArtifactId, "4" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( + selectedGroupId, selectedArtifactId, "1" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( + selectedGroupId, selectedArtifactId, "2" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( + selectedGroupId, selectedArtifactId, "3" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( + selectedGroupId, selectedArtifactId, "4" ) ); action.setGroupId( selectedGroupId ); action.setArtifactId( selectedArtifactId ); @@ -294,23 +307,25 @@ public class BrowseActionTest } public void testBrowseArtifactWithSnapshots() + throws Exception + { String selectedGroupId = "org.apache"; String selectedArtifactId = "apache"; List<String> versions = Arrays.asList( "1", "2", "3", "4-SNAPSHOT", "4", "5-SNAPSHOT" ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, - createProjectModel( selectedGroupId, selectedArtifactId, "1" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, - createProjectModel( selectedGroupId, selectedArtifactId, "2" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, - createProjectModel( selectedGroupId, selectedArtifactId, "3" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, - createProjectModel( selectedGroupId, selectedArtifactId, "4-SNAPSHOT" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, - createProjectModel( selectedGroupId, selectedArtifactId, "4" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, - createProjectModel( selectedGroupId, selectedArtifactId, "5-SNAPSHOT" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( + selectedGroupId, selectedArtifactId, "1" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( + selectedGroupId, selectedArtifactId, "2" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( + selectedGroupId, selectedArtifactId, "3" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( + selectedGroupId, selectedArtifactId, "4-SNAPSHOT" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( + selectedGroupId, selectedArtifactId, "4" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( + selectedGroupId, selectedArtifactId, "5-SNAPSHOT" ) ); action.setGroupId( selectedGroupId ); action.setArtifactId( selectedArtifactId ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java index b9edaa3d0..7685d1430 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java @@ -20,33 +20,30 @@ package org.apache.maven.archiva.web.action; */ import com.opensymphony.xwork2.Action; - -import org.apache.archiva.metadata.generic.GenericMetadataFacet; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.Dependency; 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.MetadataRepository; -import org.apache.archiva.metadata.repository.file.FileMetadataRepository; import org.apache.archiva.metadata.repository.memory.TestMetadataResolver; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; -import org.apache.maven.archiva.configuration.DefaultArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent; -import org.easymock.MockControl; -import org.easymock.classextension.MockClassControl; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class ShowArtifactActionTest extends AbstractActionTestCase { @@ -77,8 +74,8 @@ public class ShowArtifactActionTest public void testGetArtifactUniqueRelease() { - metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, - createProjectModel( TEST_VERSION ) ); + metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( + TEST_VERSION ) ); setActionParameters(); @@ -100,8 +97,8 @@ public class ShowArtifactActionTest public void testGetArtifactUniqueSnapshot() { - metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, - createProjectModel( TEST_SNAPSHOT_VERSION ) ); + metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( + TEST_SNAPSHOT_VERSION ) ); metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION, TEST_SNAPSHOT_ARTIFACTS ); @@ -130,8 +127,8 @@ public class ShowArtifactActionTest public void testGetArtifactUniqueSnapshotTimestamped() { - metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, - createProjectModel( TEST_SNAPSHOT_VERSION ) ); + metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( + TEST_SNAPSHOT_VERSION ) ); metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION, TEST_SNAPSHOT_ARTIFACTS ); @@ -171,8 +168,8 @@ public class ShowArtifactActionTest public void testGetArtifactNotInObservableRepos() { - metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, - createProjectModel( TEST_VERSION ) ); + metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( + TEST_VERSION ) ); setActionParameters(); @@ -186,8 +183,8 @@ public class ShowArtifactActionTest public void testGetArtifactOnlySeenInSecondObservableRepo() { setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) ); - metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, - createProjectModel( TEST_VERSION ) ); + metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( + TEST_VERSION ) ); setActionParameters(); @@ -210,10 +207,10 @@ public class ShowArtifactActionTest public void testGetArtifactSeenInBothObservableRepo() { setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) ); - metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, - createProjectModel( TEST_VERSION ) ); - metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, - createProjectModel( TEST_VERSION ) ); + metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( + TEST_VERSION ) ); + metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( + TEST_VERSION ) ); setActionParameters(); @@ -236,10 +233,10 @@ public class ShowArtifactActionTest public void testGetArtifactCanOnlyObserveInOneOfTwoRepos() { setObservableRepos( Arrays.asList( TEST_REPO ) ); - metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, - createProjectModel( TEST_VERSION ) ); - metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, - createProjectModel( TEST_VERSION ) ); + metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( + TEST_VERSION ) ); + metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( + TEST_VERSION ) ); setActionParameters(); @@ -347,13 +344,14 @@ public class ShowArtifactActionTest } public void testGetDependees() + throws Exception { ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION ); metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata ); ProjectVersionReference dependee1 = createReference( "artifactId1" ); ProjectVersionReference dependee2 = createReference( "artifactId2" ); - metadataResolver.setProjectReferences( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, - Arrays.asList( dependee1, dependee2 ) ); + metadataResolver.setProjectReferences( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, Arrays.asList( + dependee1, dependee2 ) ); setActionParameters(); @@ -378,7 +376,7 @@ public class ShowArtifactActionTest public void testGetProjectMetadata() { ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION ); - + metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata ); setActionParameters(); @@ -388,11 +386,12 @@ public class ShowArtifactActionTest assertActionSuccess( action, result ); assertActionParameters( action ); - + Map<String, String> genericMetadata = action.getGenericMetadata(); assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) ); - assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ), TEST_GENERIC_METADATA_PROPERTY_VALUE ); - + assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ), + TEST_GENERIC_METADATA_PROPERTY_VALUE ); + assertEquals( TEST_REPO, action.getRepositoryId() ); assertNotNull( action.getModel() ); assertNull( action.getDependees() ); @@ -400,7 +399,7 @@ public class ShowArtifactActionTest assertNull( action.getMailingLists() ); assertTrue( action.getArtifacts().isEmpty() ); } - + public void testAddAndDeleteMetadataProperty() { ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION ); @@ -412,6 +411,9 @@ public class ShowArtifactActionTest action.setPropertyValue( "bar" ); action.setRepositoryId( TEST_REPO ); + MetadataRepository repo = mock( MetadataRepository.class ); + action.setMetadataRepository( repo ); + String result = action.addMetadataProperty(); assertActionSuccess( action, result ); @@ -419,7 +421,8 @@ public class ShowArtifactActionTest Map<String, String> genericMetadata = action.getGenericMetadata(); assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) ); - assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ), TEST_GENERIC_METADATA_PROPERTY_VALUE ); + assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ), + TEST_GENERIC_METADATA_PROPERTY_VALUE ); assertNotNull( genericMetadata.get( "foo" ) ); assertEquals( "bar", genericMetadata.get( "foo" ) ); @@ -444,7 +447,8 @@ public class ShowArtifactActionTest genericMetadata = action.getGenericMetadata(); assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) ); - assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ), TEST_GENERIC_METADATA_PROPERTY_VALUE ); + assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ), + TEST_GENERIC_METADATA_PROPERTY_VALUE ); assertNull( genericMetadata.get( "foo" ) ); @@ -474,7 +478,7 @@ public class ShowArtifactActionTest assertEquals( TEST_TYPE, actual.getType() ); assertEquals( "12.06 K", actual.getSize() ); assertEquals( artifact.getNamespace() + "/" + artifact.getProject() + "/" + TEST_SNAPSHOT_VERSION + "/" + - artifact.getId(), actual.getPath() ); + artifact.getId(), actual.getPath() ); } } @@ -576,8 +580,8 @@ public class ShowArtifactActionTest ml1.setSubscribeAddress( prefix + "-subscribe@" ); ml1.setUnsubscribeAddress( prefix + "-unsubscribe@" ); ml1.setMainArchiveUrl( prefix + "-archive-url" ); - ml1.setOtherArchives( - Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ) ); + ml1.setOtherArchives( Arrays.asList( "other-" + prefix + "-archive-url-1", + "other-" + prefix + "-archive-url-2" ) ); return ml1; } @@ -628,32 +632,22 @@ public class ShowArtifactActionTest super.setUp(); action = (ShowArtifactAction) lookup( Action.class, ACTION_HINT ); metadataResolver = (TestMetadataResolver) action.getMetadataResolver(); - MockControl control = MockClassControl.createControl( RepositoryContentFactory.class ); - RepositoryContentFactory factory = (RepositoryContentFactory) control.getMock(); + + RepositoryContentFactory factory = mock( RepositoryContentFactory.class ); action.setRepositoryFactory( factory ); ManagedRepositoryConfiguration config = new ManagedRepositoryConfiguration(); config.setId( TEST_REPO ); config.setLocation( getTestFile( "target/test-repo" ).getAbsolutePath() ); - + ManagedRepositoryContent content = new ManagedDefaultRepositoryContent(); content.setRepository( config ); - factory.getManagedRepositoryContent( TEST_REPO ); - - FileMetadataRepository metadataRepo = ( FileMetadataRepository ) lookup( MetadataRepository.class ); - MockControl archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class ); - ArchivaConfiguration archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock(); - + when( factory.getManagedRepositoryContent( TEST_REPO ) ).thenReturn( content ); + + ArchivaConfiguration archivaConfig = mock( ArchivaConfiguration.class ); + Configuration configuration = new Configuration(); configuration.addManagedRepository( config ); - metadataRepo.setConfiguration( archivaConfig ); - archivaConfig.getConfiguration(); - - action.setMetadataRepository( metadataRepo ); - - archivaConfigControl.setDefaultReturnValue( configuration ); - control.setDefaultReturnValue( content ); - control.replay(); - archivaConfigControl.replay(); + when( archivaConfig.getConfiguration() ).thenReturn( configuration ); } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java index a0ad561ee..9a68f3c55 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java @@ -23,6 +23,7 @@ import com.opensymphony.xwork2.Action; import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.audit.AuditListener; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; @@ -42,7 +43,6 @@ import org.codehaus.redback.integration.interceptor.SecureActionException; import org.easymock.MockControl; import java.io.File; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -123,7 +123,7 @@ public class DeleteManagedRepositoryActionTest archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration ); - Configuration stageRepoConfiguration = new Configuration(); + Configuration stageRepoConfiguration = new Configuration(); stageRepoConfiguration.addManagedRepository( createSatingRepository() ); archivaConfigurationControl.setReturnValue( stageRepoConfiguration ); @@ -174,6 +174,7 @@ public class DeleteManagedRepositoryActionTest } private MockControl mockMetadataRepository() + throws MetadataRepositoryException { MockControl metadataRepositoryControl = MockControl.createControl( MetadataRepository.class ); MetadataRepository metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock(); @@ -273,8 +274,8 @@ public class DeleteManagedRepositoryActionTest } - - private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, int expectCountGetConfig ) + private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, + int expectCountGetConfig ) throws RegistryException, IndeterminateConfigurationException { location.mkdirs(); @@ -288,7 +289,6 @@ public class DeleteManagedRepositoryActionTest stageRepoConfiguration.addManagedRepository( createSatingRepository() ); archivaConfigurationControl.setReturnValue( stageRepoConfiguration ); - archivaConfiguration.save( configuration ); archivaConfigurationControl.replay(); @@ -348,7 +348,7 @@ public class DeleteManagedRepositoryActionTest private ManagedRepositoryConfiguration createSatingRepository() { ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration(); - r.setId( REPO_ID +"-stage" ); + r.setId( REPO_ID + "-stage" ); r.setName( "repo name" ); r.setLocation( location.getAbsolutePath() ); r.setLayout( "default" ); @@ -362,7 +362,7 @@ public class DeleteManagedRepositoryActionTest return r; } - private RemoteRepositoryConfiguration createRemoteRepository(String id, String url) + private RemoteRepositoryConfiguration createRemoteRepository( String id, String url ) { RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration(); r.setId( id ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java index 01c8a11e5..bf309a170 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java @@ -19,13 +19,6 @@ package org.apache.maven.archiva.web.action.reports; * under the License. */ -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.List; - import com.opensymphony.xwork2.Action; import org.apache.archiva.metadata.model.MetadataFacet; import org.apache.archiva.metadata.repository.MetadataRepository; @@ -36,6 +29,13 @@ import org.apache.commons.io.IOUtils; import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.List; + /** * Test the GenerationReportAction. Note that we are testing for <i>current</i> behaviour, however there are several * instances below where other behaviour may actually be more appropriate (eg the error handling, download stats should @@ -167,10 +167,12 @@ public class GenerateReportActionTest } public void testGenerateStatisticsSingleRepo() + throws Exception { - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( INTERNAL, null, null ), - Collections.singletonList( createDefaultStats() ) ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( INTERNAL, + null, + null ), + Collections.singletonList( createDefaultStats() ) ); repositoryStatisticsManagerControl.replay(); prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) ); @@ -181,9 +183,13 @@ public class GenerateReportActionTest } public void testGenerateStatisticsSingleRepoNoStats() + throws Exception + { - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( INTERNAL, null, null ), Collections.<Object>emptyList() ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( INTERNAL, + null, + null ), + Collections.<Object>emptyList() ); repositoryStatisticsManagerControl.replay(); prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) ); @@ -195,10 +201,13 @@ public class GenerateReportActionTest } public void testGenerateStatisticsOvershotPages() + throws Exception + { - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( INTERNAL, null, null ), - Collections.singletonList( createDefaultStats() ) ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( INTERNAL, + null, + null ), + Collections.singletonList( createDefaultStats() ) ); repositoryStatisticsManagerControl.replay(); action.setPage( 2 ); prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) ); @@ -210,12 +219,17 @@ public class GenerateReportActionTest } public void testGenerateStatisticsMultipleRepoNoResults() + throws Exception + { - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, null, null ), - Collections.<Object>emptyList() ); - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( INTERNAL, null, null ), Collections.<Object>emptyList() ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, + null, + null ), + Collections.<Object>emptyList() ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( INTERNAL, + null, + null ), + Collections.<Object>emptyList() ); repositoryStatisticsManagerControl.replay(); prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() ); @@ -229,13 +243,17 @@ public class GenerateReportActionTest } public void testGenerateStatisticsMultipleRepo() + throws Exception + { - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, null, null ), - Collections.singletonList( createDefaultStats() ) ); - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( INTERNAL, null, null ), - Collections.singletonList( createDefaultStats() ) ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, + null, + null ), + Collections.singletonList( createDefaultStats() ) ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( INTERNAL, + null, + null ), + Collections.singletonList( createDefaultStats() ) ); repositoryStatisticsManagerControl.replay(); prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() ); @@ -246,12 +264,13 @@ public class GenerateReportActionTest } public void testDownloadStatisticsSingleRepo() - throws IOException + throws Exception { Date date = new Date(); - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, null, null ), - Collections.singletonList( createStats( date ) ) ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, + null, + null ), + Collections.singletonList( createStats( date ) ) ); repositoryStatisticsManagerControl.replay(); prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) ); @@ -268,14 +287,16 @@ public class GenerateReportActionTest } public void testDownloadStatisticsMultipleRepos() - throws IOException + throws Exception { - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, null, null ), - Collections.singletonList( createDefaultStats() ) ); - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( INTERNAL, null, null ), - Collections.singletonList( createDefaultStats() ) ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, + null, + null ), + Collections.singletonList( createDefaultStats() ) ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( INTERNAL, + null, + null ), + Collections.singletonList( createDefaultStats() ) ); repositoryStatisticsManagerControl.replay(); prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() ); @@ -343,9 +364,13 @@ public class GenerateReportActionTest } public void testDownloadStatisticsSingleRepoNoStats() + throws Exception + { - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( INTERNAL, null, null ), Collections.<Object>emptyList() ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( INTERNAL, + null, + null ), + Collections.<Object>emptyList() ); repositoryStatisticsManagerControl.replay(); prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) ); @@ -367,12 +392,17 @@ public class GenerateReportActionTest } public void testDownloadStatisticsMultipleRepoNoResults() + throws Exception + { - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, null, null ), - Collections.<Object>emptyList() ); - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( INTERNAL, null, null ), Collections.<Object>emptyList() ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, + null, + null ), + Collections.<Object>emptyList() ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( INTERNAL, + null, + null ), + Collections.<Object>emptyList() ); repositoryStatisticsManagerControl.replay(); prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() ); @@ -385,14 +415,16 @@ public class GenerateReportActionTest } public void testDownloadStatisticsMultipleRepoInStrutsFormat() - throws IOException + throws Exception { - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, null, null ), - Collections.singletonList( createDefaultStats() ) ); - repositoryStatisticsManagerControl.expectAndReturn( - repositoryStatisticsManager.getStatisticsInRange( INTERNAL, null, null ), - Collections.singletonList( createDefaultStats() ) ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, + null, + null ), + Collections.singletonList( createDefaultStats() ) ); + repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( INTERNAL, + null, + null ), + Collections.singletonList( createDefaultStats() ) ); repositoryStatisticsManagerControl.replay(); prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() ); @@ -412,15 +444,17 @@ public class GenerateReportActionTest RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL ); RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", INTERNAL ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ), - Arrays.asList( problem1.getName(), problem2.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ), - problem1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem2.getName() ), - problem2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( INTERNAL, + RepositoryProblemFacet.FACET_ID ), + Arrays.asList( problem1.getName(), problem2.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( INTERNAL, + RepositoryProblemFacet.FACET_ID, + problem1.getName() ), + problem1 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( INTERNAL, + RepositoryProblemFacet.FACET_ID, + problem2.getName() ), + problem2 ); metadataRepositoryControl.replay(); action.setRepositoryId( INTERNAL ); @@ -459,18 +493,20 @@ public class GenerateReportActionTest { RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL ); RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", SNAPSHOTS ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ), - Arrays.asList( problem1.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( SNAPSHOTS, RepositoryProblemFacet.FACET_ID ), - Arrays.asList( problem2.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ), - problem1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( SNAPSHOTS, RepositoryProblemFacet.FACET_ID, problem2.getName() ), - problem2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( INTERNAL, + RepositoryProblemFacet.FACET_ID ), + Arrays.asList( problem1.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( SNAPSHOTS, + RepositoryProblemFacet.FACET_ID ), + Arrays.asList( problem2.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( INTERNAL, + RepositoryProblemFacet.FACET_ID, + problem1.getName() ), + problem1 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( SNAPSHOTS, + RepositoryProblemFacet.FACET_ID, + problem2.getName() ), + problem2 ); metadataRepositoryControl.replay(); action.setRepositoryId( GenerateReportAction.ALL_REPOSITORIES ); @@ -480,8 +516,8 @@ public class GenerateReportActionTest String result = action.execute(); assertSuccessResult( result ); - assertEquals( Arrays.asList( INTERNAL, SNAPSHOTS ), - new ArrayList<String>( action.getRepositoriesMap().keySet() ) ); + assertEquals( Arrays.asList( INTERNAL, SNAPSHOTS ), new ArrayList<String>( + action.getRepositoriesMap().keySet() ) ); assertEquals( Arrays.asList( problem1 ), action.getRepositoriesMap().get( INTERNAL ) ); assertEquals( Arrays.asList( problem2 ), action.getRepositoriesMap().get( SNAPSHOTS ) ); @@ -493,15 +529,17 @@ public class GenerateReportActionTest { RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL ); RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", INTERNAL ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ), - Arrays.asList( problem1.getName(), problem2.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ), - problem1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem2.getName() ), - problem2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( INTERNAL, + RepositoryProblemFacet.FACET_ID ), + Arrays.asList( problem1.getName(), problem2.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( INTERNAL, + RepositoryProblemFacet.FACET_ID, + problem1.getName() ), + problem1 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( INTERNAL, + RepositoryProblemFacet.FACET_ID, + problem2.getName() ), + problem2 ); metadataRepositoryControl.replay(); action.setGroupId( GROUP_ID ); @@ -523,18 +561,20 @@ public class GenerateReportActionTest { RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL ); RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", SNAPSHOTS ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ), - Arrays.asList( problem1.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( SNAPSHOTS, RepositoryProblemFacet.FACET_ID ), - Arrays.asList( problem2.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ), - problem1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( SNAPSHOTS, RepositoryProblemFacet.FACET_ID, problem2.getName() ), - problem2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( INTERNAL, + RepositoryProblemFacet.FACET_ID ), + Arrays.asList( problem1.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( SNAPSHOTS, + RepositoryProblemFacet.FACET_ID ), + Arrays.asList( problem2.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( INTERNAL, + RepositoryProblemFacet.FACET_ID, + problem1.getName() ), + problem1 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( SNAPSHOTS, + RepositoryProblemFacet.FACET_ID, + problem2.getName() ), + problem2 ); metadataRepositoryControl.replay(); action.setGroupId( GROUP_ID ); @@ -545,8 +585,8 @@ public class GenerateReportActionTest String result = action.execute(); assertSuccessResult( result ); - assertEquals( Arrays.asList( INTERNAL, SNAPSHOTS ), - new ArrayList<String>( action.getRepositoriesMap().keySet() ) ); + assertEquals( Arrays.asList( INTERNAL, SNAPSHOTS ), new ArrayList<String>( + action.getRepositoriesMap().keySet() ) ); assertEquals( Arrays.asList( problem1 ), action.getRepositoriesMap().get( INTERNAL ) ); assertEquals( Arrays.asList( problem2 ), action.getRepositoriesMap().get( SNAPSHOTS ) ); @@ -556,9 +596,9 @@ public class GenerateReportActionTest public void testHealthReportSingleRepoByIncorrectGroupId() throws Exception { - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ), - Collections.<MetadataFacet>emptyList() ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( INTERNAL, + RepositoryProblemFacet.FACET_ID ), + Collections.<MetadataFacet>emptyList() ); metadataRepositoryControl.replay(); action.setGroupId( "not.it" ); @@ -579,8 +619,8 @@ public class GenerateReportActionTest { assertEquals( "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars\n" + - "snapshots,0,0,0,0,0,0,0,0,0\n" + "internal,0,0,0,0,0,0,0,0,0\n", - IOUtils.toString( action.getInputStream() ) ); + "snapshots,0,0,0,0,0,0,0,0,0\n" + "internal,0,0,0,0,0,0,0,0,0\n", IOUtils.toString( + action.getInputStream() ) ); } private RepositoryProblemFacet createProblem( String groupId, String artifactId, String repoId ) 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 a0d7d7f90..9fd802db9 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 @@ -19,9 +19,6 @@ package org.apache.archiva.metadata.repository; * under the License. */ -import java.util.ArrayList; -import java.util.Collection; - import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.Dependency; import org.apache.archiva.metadata.model.ProjectMetadata; @@ -32,6 +29,9 @@ import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.Collection; + /** * @plexus.component role="org.apache.archiva.metadata.repository.MetadataResolver" */ @@ -55,6 +55,7 @@ public class DefaultMetadataResolver private static final Logger log = LoggerFactory.getLogger( DefaultMetadataResolver.class ); public ProjectMetadata getProject( String repoId, String namespace, String projectId ) + throws MetadataResolutionException { // TODO: intercept return metadataRepository.getProject( repoId, namespace, projectId ); @@ -64,8 +65,8 @@ public class DefaultMetadataResolver String projectVersion ) throws MetadataResolutionException { - ProjectVersionMetadata metadata = - metadataRepository.getProjectVersion( repoId, namespace, projectId, projectVersion ); + ProjectVersionMetadata metadata = metadataRepository.getProjectVersion( repoId, namespace, projectId, + projectVersion ); // TODO: do we want to detect changes as well by comparing timestamps? isProjectVersionNewerThan(updated) // in such cases we might also remove/update stale metadata, including adjusting plugin-based facets // This would also be better than checking for completeness - we can then refresh only when fixed (though @@ -91,12 +92,26 @@ public class DefaultMetadataResolver ref.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY ); for ( Dependency dependency : metadata.getDependencies() ) { - metadataRepository.updateProjectReference( repoId, dependency.getGroupId(), - dependency.getArtifactId(), dependency.getVersion(), - ref ); + try + { + metadataRepository.updateProjectReference( repoId, dependency.getGroupId(), + dependency.getArtifactId(), + dependency.getVersion(), ref ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to persist resolved information: " + e.getMessage(), e ); + } } } - metadataRepository.updateProjectVersion( repoId, namespace, projectId, metadata ); + try + { + metadataRepository.updateProjectVersion( repoId, namespace, projectId, metadata ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to persist resolved information: " + e.getMessage(), e ); + } } } return metadata; @@ -104,6 +119,7 @@ public class DefaultMetadataResolver public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataResolutionException { // TODO: intercept return metadataRepository.getArtifactVersions( repoId, namespace, projectId, projectVersion ); @@ -111,6 +127,7 @@ public class DefaultMetadataResolver public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataResolutionException { // TODO: is this assumption correct? could a storage mech. actually know all references in a non-Maven scenario? // not passed to the storage mechanism as resolving references would require iterating all artifacts @@ -118,10 +135,11 @@ public class DefaultMetadataResolver } public Collection<String> getRootNamespaces( String repoId ) + throws MetadataResolutionException { Collection<String> namespaces = metadataRepository.getRootNamespaces( repoId ); - Collection<String> storageNamespaces = - storageResolver.getRootNamespaces( repoId, new ExcludesFilter<String>( namespaces ) ); + Collection<String> storageNamespaces = storageResolver.getRootNamespaces( repoId, new ExcludesFilter<String>( + namespaces ) ); if ( storageNamespaces != null && !storageNamespaces.isEmpty() ) { if ( log.isDebugEnabled() ) @@ -130,7 +148,14 @@ public class DefaultMetadataResolver } for ( String n : storageNamespaces ) { - metadataRepository.updateNamespace( repoId, n ); + try + { + metadataRepository.updateNamespace( repoId, n ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to persist resolved information: " + e.getMessage(), e ); + } } namespaces = new ArrayList<String>( namespaces ); namespaces.addAll( storageNamespaces ); @@ -139,12 +164,14 @@ public class DefaultMetadataResolver } public Collection<String> getNamespaces( String repoId, String namespace ) + throws MetadataResolutionException { Collection<String> namespaces = metadataRepository.getNamespaces( repoId, namespace ); Collection<String> exclusions = new ArrayList<String>( namespaces ); exclusions.addAll( metadataRepository.getProjects( repoId, namespace ) ); - Collection<String> storageNamespaces = - storageResolver.getNamespaces( repoId, namespace, new ExcludesFilter<String>( exclusions ) ); + Collection<String> storageNamespaces = storageResolver.getNamespaces( repoId, namespace, + new ExcludesFilter<String>( + exclusions ) ); if ( storageNamespaces != null && !storageNamespaces.isEmpty() ) { if ( log.isDebugEnabled() ) @@ -153,7 +180,14 @@ public class DefaultMetadataResolver } for ( String n : storageNamespaces ) { - metadataRepository.updateNamespace( repoId, namespace + "." + n ); + try + { + metadataRepository.updateNamespace( repoId, namespace + "." + n ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to persist resolved information: " + e.getMessage(), e ); + } } namespaces = new ArrayList<String>( namespaces ); namespaces.addAll( storageNamespaces ); @@ -162,12 +196,13 @@ public class DefaultMetadataResolver } public Collection<String> getProjects( String repoId, String namespace ) + throws MetadataResolutionException { Collection<String> projects = metadataRepository.getProjects( repoId, namespace ); Collection<String> exclusions = new ArrayList<String>( projects ); exclusions.addAll( metadataRepository.getNamespaces( repoId, namespace ) ); - Collection<String> storageProjects = - storageResolver.getProjects( repoId, namespace, new ExcludesFilter<String>( exclusions ) ); + Collection<String> storageProjects = storageResolver.getProjects( repoId, namespace, new ExcludesFilter<String>( + exclusions ) ); if ( storageProjects != null && !storageProjects.isEmpty() ) { if ( log.isDebugEnabled() ) @@ -179,7 +214,14 @@ public class DefaultMetadataResolver ProjectMetadata projectMetadata = storageResolver.getProject( repoId, namespace, projectId ); if ( projectMetadata != null ) { - metadataRepository.updateProject( repoId, projectMetadata ); + try + { + metadataRepository.updateProject( repoId, projectMetadata ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to persist resolved information: " + e.getMessage(), e ); + } } } projects = new ArrayList<String>( projects ); @@ -189,6 +231,7 @@ public class DefaultMetadataResolver } public Collection<String> getProjectVersions( String repoId, String namespace, String projectId ) + throws MetadataResolutionException { Collection<String> projectVersions = metadataRepository.getProjectVersions( repoId, namespace, projectId ); Collection<String> storageProjectVersions = storageResolver.getProjectVersions( repoId, namespace, projectId, @@ -204,8 +247,9 @@ public class DefaultMetadataResolver { try { - ProjectVersionMetadata versionMetadata = - storageResolver.getProjectVersion( repoId, namespace, projectId, projectVersion ); + ProjectVersionMetadata versionMetadata = storageResolver.getProjectVersion( repoId, namespace, + projectId, + projectVersion ); if ( versionMetadata != null ) { metadataRepository.updateProjectVersion( repoId, namespace, projectId, versionMetadata ); @@ -214,7 +258,11 @@ public class DefaultMetadataResolver catch ( MetadataResolutionException e ) { log.warn( "Not update project in metadata repository due to an error resolving it from storage: " + - e.getMessage() ); + e.getMessage() ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to persist resolved information: " + e.getMessage(), e ); } } projectVersions = new ArrayList<String>( projectVersions ); @@ -225,12 +273,15 @@ public class DefaultMetadataResolver public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataResolutionException { - Collection<ArtifactMetadata> artifacts = - metadataRepository.getArtifacts( repoId, namespace, projectId, projectVersion ); - Collection<ArtifactMetadata> storageArtifacts = - storageResolver.getArtifacts( repoId, namespace, projectId, projectVersion, - new ExcludesFilter<String>( createArtifactIdList( artifacts ) ) ); + Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts( repoId, namespace, projectId, + projectVersion ); + Collection<ArtifactMetadata> storageArtifacts = storageResolver.getArtifacts( repoId, namespace, projectId, + projectVersion, + new ExcludesFilter<String>( + createArtifactIdList( + artifacts ) ) ); if ( storageArtifacts != null && !storageArtifacts.isEmpty() ) { if ( log.isDebugEnabled() ) @@ -239,7 +290,14 @@ public class DefaultMetadataResolver } for ( ArtifactMetadata artifact : storageArtifacts ) { - metadataRepository.updateArtifact( repoId, namespace, projectId, projectVersion, artifact ); + try + { + metadataRepository.updateArtifact( repoId, namespace, projectId, projectVersion, artifact ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to persist resolved information: " + e.getMessage(), e ); + } } artifacts = new ArrayList<ArtifactMetadata>( artifacts ); artifacts.addAll( storageArtifacts ); diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index cc7c513fc..130dc7300 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -35,46 +35,63 @@ public interface MetadataRepository /** * Update metadata for a particular project in the metadata repository, or create it if it does not already exist. * - * @param repositoryId the repository the project is in - * @param project the project metadata to create or update + * @param repositoryId the repository the project is in + * @param project the project metadata to create or update */ - void updateProject( String repositoryId, ProjectMetadata project ); + void updateProject( String repositoryId, ProjectMetadata project ) + throws MetadataRepositoryException; void updateArtifact( String repositoryId, String namespace, String projectId, String projectVersion, - ArtifactMetadata artifactMeta ); + ArtifactMetadata artifactMeta ) + throws MetadataRepositoryException; void updateProjectVersion( String repositoryId, String namespace, String projectId, - ProjectVersionMetadata versionMetadata ); + ProjectVersionMetadata versionMetadata ) + throws MetadataRepositoryException; void updateProjectReference( String repositoryId, String namespace, String projectId, String projectVersion, - ProjectVersionReference reference ); + ProjectVersionReference reference ) + throws MetadataRepositoryException; - void updateNamespace( String repositoryId, String namespace ); + void updateNamespace( String repositoryId, String namespace ) + throws MetadataRepositoryException; - List<String> getMetadataFacets( String repositoryId, String facetId ); + List<String> getMetadataFacets( String repositoryId, String facetId ) + throws MetadataRepositoryException; - MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name ); + MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name ) + throws MetadataRepositoryException; - void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet ); + void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet ) + throws MetadataRepositoryException; - void removeMetadataFacets( String repositoryId, String facetId ); + void removeMetadataFacets( String repositoryId, String facetId ) + throws MetadataRepositoryException; - void removeMetadataFacet( String repositoryId, String facetId, String name ); + void removeMetadataFacet( String repositoryId, String facetId, String name ) + throws MetadataRepositoryException; - List<ArtifactMetadata> getArtifactsByDateRange( String repositoryId, Date startTime, Date endTime ); + List<ArtifactMetadata> getArtifactsByDateRange( String repositoryId, Date startTime, Date endTime ) + throws MetadataRepositoryException; // TODO: remove from API, just use configuration - Collection<String> getRepositories(); + Collection<String> getRepositories() + throws MetadataRepositoryException; - List<ArtifactMetadata> getArtifactsByChecksum( String repositoryId, String checksum ); + List<ArtifactMetadata> getArtifactsByChecksum( String repositoryId, String checksum ) + throws MetadataRepositoryException; - void deleteArtifact( String repositoryId, String namespace, String project, String version, String id ); + void deleteArtifact( String repositoryId, String namespace, String project, String version, String id ) + throws MetadataRepositoryException; /** * Delete a repository's metadata. This includes all associated metadata facets. + * * @param repositoryId the repository to delete */ - void deleteRepository( String repositoryId ); + void deleteRepository( String repositoryId ) + throws MetadataRepositoryException; - List<ArtifactMetadata> getArtifacts(String repositoryId); + List<ArtifactMetadata> getArtifacts( String repositoryId ) + throws MetadataRepositoryException; } diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepositoryException.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepositoryException.java new file mode 100644 index 000000000..92dbf59ec --- /dev/null +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepositoryException.java @@ -0,0 +1,34 @@ +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 MetadataRepositoryException + extends Exception +{ + public MetadataRepositoryException( String message ) + { + super( message ); + } + + public MetadataRepositoryException( String s, Throwable throwable ) + { + super( s, throwable ); + } +} diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolutionException.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolutionException.java index 57525e954..b787787ea 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolutionException.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolutionException.java @@ -26,4 +26,9 @@ public class MetadataResolutionException { super( message ); } + + public MetadataResolutionException( String message, Throwable throwable ) + { + super( message, throwable ); + } } 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 c00f97cf9..6de4ad562 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 @@ -19,22 +19,23 @@ package org.apache.archiva.metadata.repository; * under the License. */ -import java.util.Collection; - 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.model.ProjectVersionReference; +import java.util.Collection; + public interface MetadataResolver { - ProjectMetadata getProject( String repoId, String namespace, String projectId ); + ProjectMetadata getProject( String repoId, String namespace, String projectId ) + throws MetadataResolutionException; - ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, - String projectVersion ) + ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) throws MetadataResolutionException; - Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion ); + Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataResolutionException; /** * Retrieve project references from the metadata repository. Note that this is not built into the content model for @@ -48,16 +49,22 @@ public interface MetadataResolver * @return a list of project references */ Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId, - String projectVersion ); + String projectVersion ) + throws MetadataResolutionException; - Collection<String> getRootNamespaces( String repoId ); + Collection<String> getRootNamespaces( String repoId ) + throws MetadataResolutionException; - Collection<String> getNamespaces( String repoId, String namespace ); + Collection<String> getNamespaces( String repoId, String namespace ) + throws MetadataResolutionException; - Collection<String> getProjects( String repoId, String namespace ); + Collection<String> getProjects( String repoId, String namespace ) + throws MetadataResolutionException; - Collection<String> getProjectVersions( String repoId, String namespace, String projectId ); + Collection<String> getProjectVersions( String repoId, String namespace, String projectId ) + throws MetadataResolutionException; Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId, - String projectVersion ); + String projectVersion ) + throws MetadataResolutionException; } diff --git a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java index e96c00d01..643df1817 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java +++ b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java @@ -106,12 +106,14 @@ public abstract class AbstractMetadataRepositoryTest } public void testRootNamespaceWithNoMetadataRepository() + throws Exception { Collection<String> namespaces = repository.getRootNamespaces( TEST_REPO_ID ); assertEquals( Collections.<String>emptyList(), namespaces ); } public void testGetNamespaceOnly() + throws Exception { assertEquals( Collections.emptyList(), repository.getRootNamespaces( TEST_REPO_ID ) ); @@ -121,6 +123,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetProjectOnly() + throws Exception { assertNull( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) ); assertEquals( Collections.emptyList(), repository.getRootNamespaces( TEST_REPO_ID ) ); @@ -140,7 +143,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetProjectVersionOnly() - throws MetadataResolutionException + throws Exception { assertNull( repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ); assertNull( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) ); @@ -162,7 +165,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactOnly() - throws MetadataResolutionException + throws Exception { assertEquals( Collections.<ArtifactMetadata>emptyList(), new ArrayList<ArtifactMetadata>( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) ); @@ -192,7 +195,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testUpdateProjectVersionMetadataWithNoOtherArchives() - throws MetadataResolutionException + throws Exception { ProjectVersionMetadata metadata = new ProjectVersionMetadata(); metadata.setId( TEST_PROJECT_VERSION ); @@ -211,7 +214,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testUpdateProjectVersionMetadataWithAllElements() - throws MetadataResolutionException + throws Exception { ProjectVersionMetadata metadata = new ProjectVersionMetadata(); metadata.setId( TEST_PROJECT_VERSION ); @@ -303,6 +306,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testUpdateProjectReference() + throws Exception { ProjectVersionReference reference = new ProjectVersionReference(); reference.setNamespace( "another.namespace" ); @@ -325,6 +329,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetRepositories() + throws Exception { // currently set up this way so the behaviour of both the test and the mock config return the same repository // set as the File implementation just uses the config rather than the content @@ -336,7 +341,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testUpdateProjectVersionMetadataIncomplete() - throws MetadataResolutionException + throws Exception { ProjectVersionMetadata metadata = new ProjectVersionMetadata(); metadata.setId( TEST_PROJECT_VERSION ); @@ -359,7 +364,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testUpdateProjectVersionMetadataWithExistingFacets() - throws MetadataResolutionException + throws Exception { ProjectVersionMetadata metadata = new ProjectVersionMetadata(); metadata.setId( TEST_PROJECT_VERSION ); @@ -381,7 +386,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testUpdateProjectVersionMetadataWithNoExistingFacets() - throws MetadataResolutionException + throws Exception { ProjectVersionMetadata metadata = new ProjectVersionMetadata(); metadata.setId( TEST_PROJECT_VERSION ); @@ -399,7 +404,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved() - throws MetadataResolutionException + throws Exception { ProjectVersionMetadata metadata = new ProjectVersionMetadata(); metadata.setId( TEST_PROJECT_VERSION ); @@ -433,7 +438,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved() - throws MetadataResolutionException + throws Exception { ArtifactMetadata metadata = createArtifact(); @@ -468,6 +473,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testUpdateArtifactMetadataWithExistingFacets() + throws Exception { ArtifactMetadata metadata = createArtifact(); MetadataFacet facet = new TestMetadataFacet( "baz" ); @@ -489,6 +495,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testUpdateArtifactMetadataWithNoExistingFacets() + throws Exception { ArtifactMetadata metadata = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata ); @@ -506,6 +513,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetMetadataFacet() + throws Exception { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); @@ -514,11 +522,15 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetMetadataFacetWhenEmpty() + throws Exception + { assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ); } public void testGetMetadataFacetWhenUnknownName() + throws Exception + { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); @@ -526,6 +538,8 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetMetadataFacetWhenDefaultValue() + throws Exception + { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( null ) ); @@ -535,11 +549,15 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetMetadataFacetWhenUnknownFacetId() + throws Exception + { assertNull( repository.getMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ) ); } public void testGetMetadataFacets() + throws Exception + { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); @@ -548,12 +566,16 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetMetadataFacetsWhenEmpty() + throws Exception + { List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); assertTrue( facets.isEmpty() ); } public void testRemoveFacets() + throws Exception + { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); @@ -567,6 +589,8 @@ public abstract class AbstractMetadataRepositoryTest } public void testRemoveFacetsWhenEmpty() + throws Exception + { List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); assertTrue( facets.isEmpty() ); @@ -578,18 +602,24 @@ public abstract class AbstractMetadataRepositoryTest } public void testRemoveFacetsWhenUnknown() + throws Exception + { // testing no exception repository.removeMetadataFacets( TEST_REPO_ID, UNKNOWN ); } public void testRemoveFacetWhenUnknown() + throws Exception + { // testing no exception repository.removeMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ); } public void testRemoveFacet() + throws Exception + { TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE ); repository.addMetadataFacet( TEST_REPO_ID, metadataFacet ); @@ -606,6 +636,8 @@ public abstract class AbstractMetadataRepositoryTest } public void testRemoveFacetWhenEmpty() + throws Exception + { List<String> facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); assertTrue( facets.isEmpty() ); @@ -619,6 +651,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifacts() + throws Exception { ArtifactMetadata artifact1 = createArtifact(); ArtifactMetadata artifact2 = createArtifact( "pom" ); @@ -639,6 +672,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactVersions() + throws Exception { ArtifactMetadata artifact1 = createArtifact(); String version1 = "1.0-20091212.012345-1"; @@ -659,6 +693,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactVersionsMultipleArtifactsSingleVersion() + throws Exception { ArtifactMetadata artifact1 = createArtifact(); artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" ); @@ -674,6 +709,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByDateRangeOpen() + throws Exception { ArtifactMetadata artifact = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); @@ -683,6 +719,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByDateRangeSparseNamespace() + throws Exception { String namespace = "org.apache.archiva"; ArtifactMetadata artifact = createArtifact(); @@ -694,6 +731,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByDateRangeLowerBound() + throws Exception { ArtifactMetadata artifact = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); @@ -704,6 +742,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByDateRangeLowerBoundOutOfRange() + throws Exception { ArtifactMetadata artifact = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); @@ -713,6 +752,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByDateRangeLowerAndUpperBound() + throws Exception { ArtifactMetadata artifact = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); @@ -724,6 +764,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByDateRangeUpperBound() + throws Exception { ArtifactMetadata artifact = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); @@ -734,6 +775,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByDateRangeUpperBoundOutOfRange() + throws Exception { ArtifactMetadata artifact = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); @@ -743,6 +785,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByRepoId() + throws Exception { ArtifactMetadata artifact = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); @@ -750,6 +793,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetNamespacesWithSparseDepth() + throws Exception { repository.updateNamespace( TEST_REPO_ID, "org.apache.maven.shared" ); @@ -760,6 +804,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByChecksumSingleResultMd5() + throws Exception { ArtifactMetadata artifact = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); @@ -769,6 +814,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByChecksumSingleResultSha1() + throws Exception { ArtifactMetadata artifact = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); @@ -778,6 +824,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByChecksumDeepNamespace() + throws Exception { ArtifactMetadata artifact = createArtifact(); String namespace = "multi.level.ns"; @@ -789,6 +836,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByChecksumMultipleResult() + throws Exception { ArtifactMetadata artifact1 = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 ); @@ -805,6 +853,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testGetArtifactsByChecksumNoResult() + throws Exception { ArtifactMetadata artifact = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); @@ -814,6 +863,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testDeleteArtifact() + throws Exception { ArtifactMetadata artifact = createArtifact(); artifact.addFacet( new TestMetadataFacet( "value" ) ); @@ -830,6 +880,7 @@ public abstract class AbstractMetadataRepositoryTest } public void testDeleteRepository() + throws Exception { repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE ); diff --git a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java index 29665e5a6..23c0f674c 100644 --- a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java +++ b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java @@ -19,17 +19,22 @@ package org.apache.archiva.audit; * under the License. */ +import org.apache.archiva.metadata.repository.MetadataRepositoryException; + import java.util.Collection; import java.util.Date; import java.util.List; public interface AuditManager { - List<AuditEvent> getMostRecentAuditEvents( List<String> repositoryIds ); + List<AuditEvent> getMostRecentAuditEvents( List<String> repositoryIds ) + throws MetadataRepositoryException; - void addAuditEvent( AuditEvent event ); + void addAuditEvent( AuditEvent event ) + throws MetadataRepositoryException; - void deleteAuditEvents( String repositoryId ); + void deleteAuditEvents( String repositoryId ) + throws MetadataRepositoryException; /** * Get all audit events from the given repositories that match a certain range @@ -39,7 +44,8 @@ public interface AuditManager * @param endTime find events only before this time * @return the list of events found */ - List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, Date startTime, Date endTime ); + List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, Date startTime, Date endTime ) + throws MetadataRepositoryException; /** * Get all audit events from the given repositories that match a certain range and resource pattern @@ -51,5 +57,6 @@ public interface AuditManager * @return the list of events found */ List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, String resourcePattern, Date startTime, - Date endTime ); + Date endTime ) + throws MetadataRepositoryException; } diff --git a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java index 73c9094e4..9474ce54c 100644 --- a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java +++ b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java @@ -20,6 +20,7 @@ package org.apache.archiva.audit; */ import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,6 +52,7 @@ public class DefaultAuditManager private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" ); public List<AuditEvent> getMostRecentAuditEvents( List<String> repositoryIds ) + throws MetadataRepositoryException { // TODO: consider a more efficient implementation that directly gets the last ten from the content repository List<AuditRecord> records = new ArrayList<AuditRecord>(); @@ -68,15 +70,16 @@ public class DefaultAuditManager List<AuditEvent> events = new ArrayList<AuditEvent>( records.size() ); for ( AuditRecord record : records ) { - AuditEvent auditEvent = - (AuditEvent) metadataRepository.getMetadataFacet( record.repositoryId, AuditEvent.FACET_ID, - record.name ); + AuditEvent auditEvent = (AuditEvent) metadataRepository.getMetadataFacet( record.repositoryId, + AuditEvent.FACET_ID, + record.name ); events.add( auditEvent ); } return events; } public void addAuditEvent( AuditEvent event ) + throws MetadataRepositoryException { // ignore those with no repository - they will still be logged to the textual audit log if ( event.getRepositoryId() != null ) @@ -86,17 +89,20 @@ public class DefaultAuditManager } public void deleteAuditEvents( String repositoryId ) + throws MetadataRepositoryException { metadataRepository.removeMetadataFacets( repositoryId, AuditEvent.FACET_ID ); } public List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, Date startTime, Date endTime ) + throws MetadataRepositoryException { return getAuditEventsInRange( repositoryIds, null, startTime, endTime ); } public List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, String resource, Date startTime, Date endTime ) + throws MetadataRepositoryException { List<AuditEvent> results = new ArrayList<AuditEvent>(); for ( String repositoryId : repositoryIds ) @@ -107,11 +113,12 @@ public class DefaultAuditManager try { Date date = createNameFormat().parse( name ); - if ( ( startTime == null || !date.before( startTime ) ) && - ( endTime == null || !date.after( endTime ) ) ) + if ( ( startTime == null || !date.before( startTime ) ) && ( endTime == null || !date.after( + endTime ) ) ) { - AuditEvent event = - (AuditEvent) metadataRepository.getMetadataFacet( repositoryId, AuditEvent.FACET_ID, name ); + AuditEvent event = (AuditEvent) metadataRepository.getMetadataFacet( repositoryId, + AuditEvent.FACET_ID, + name ); if ( resource == null || event.getResource().startsWith( resource ) ) { diff --git a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java index 66383892e..632187c62 100644 --- a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java +++ b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java @@ -19,12 +19,18 @@ package org.apache.archiva.audit; * under the License. */ +import org.apache.archiva.metadata.repository.MetadataRepositoryException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * @plexus.component role="org.apache.archiva.audit.AuditListener" role-hint="metadata" */ public class MetadataAuditListener implements AuditListener { + private static final Logger log = LoggerFactory.getLogger( MetadataAuditListener.class ); + /** * @plexus.requirement */ @@ -36,7 +42,14 @@ public class MetadataAuditListener if ( event.getAction().equals( AuditEvent.CREATE_FILE ) || event.getAction().equals( AuditEvent.UPLOAD_FILE ) || event.getAction().equals( AuditEvent.MERGING_REPOSITORIES ) ) { - auditManager.addAuditEvent( event ); + try + { + auditManager.addAuditEvent( event ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to write audit event to repository: " + e.getMessage(), e ); + } } } } diff --git a/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java b/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java index a4e6012d3..2ac2ddcc0 100644 --- a/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java +++ b/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java @@ -86,7 +86,7 @@ public class AuditManagerTest } public void testGetMostRecentEvents() - throws ParseException + throws Exception { int numEvents = 11; List<AuditEvent> expectedEvents = new ArrayList<AuditEvent>( numEvents ); @@ -96,14 +96,15 @@ public class AuditManagerTest expectedEvents.add( event ); } - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), - getEventNames( expectedEvents ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + AuditEvent.FACET_ID ), + getEventNames( expectedEvents ) ); for ( AuditEvent event : expectedEvents.subList( 1, expectedEvents.size() ) ) { - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, event.getName() ), event ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + event.getName() ), event ); } metadataRepositoryControl.replay(); @@ -122,7 +123,7 @@ public class AuditManagerTest } public void testGetMostRecentEventsLessThan10() - throws ParseException + throws Exception { int numEvents = 5; List<AuditEvent> expectedEvents = new ArrayList<AuditEvent>( numEvents ); @@ -131,14 +132,15 @@ public class AuditManagerTest expectedEvents.add( createEvent( AUDIT_EVENT_BASE + MILLIS_FORMAT.format( i ) ) ); } - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), - getEventNames( expectedEvents ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + AuditEvent.FACET_ID ), + getEventNames( expectedEvents ) ); for ( AuditEvent event : expectedEvents ) { - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, event.getName() ), event ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + event.getName() ), event ); } metadataRepositoryControl.replay(); @@ -157,7 +159,7 @@ public class AuditManagerTest } public void testGetMostRecentEventsInterleavedRepositories() - throws ParseException + throws Exception { int numEvents = 11; Map<String, List<String>> eventNames = new LinkedHashMap<String, List<String>>(); @@ -173,17 +175,18 @@ public class AuditManagerTest eventNames.get( repositoryId ).add( event.getName() ); } - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), eventNames.get( TEST_REPO_ID ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID_2, AuditEvent.FACET_ID ), - eventNames.get( TEST_REPO_ID_2 ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + AuditEvent.FACET_ID ), + eventNames.get( TEST_REPO_ID ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID_2, + AuditEvent.FACET_ID ), + eventNames.get( TEST_REPO_ID_2 ) ); for ( AuditEvent event : events.subList( 1, events.size() ) ) { - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( event.getRepositoryId(), AuditEvent.FACET_ID, event.getName() ), - event ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( event.getRepositoryId(), + AuditEvent.FACET_ID, + event.getName() ), event ); } metadataRepositoryControl.replay(); @@ -203,9 +206,12 @@ public class AuditManagerTest } public void testGetMostRecentEventsWhenEmpty() + throws Exception + { - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), Collections.emptyList() ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + AuditEvent.FACET_ID ), + Collections.emptyList() ); metadataRepositoryControl.replay(); assertTrue( auditManager.getMostRecentAuditEvents( Collections.singletonList( TEST_REPO_ID ) ).isEmpty() ); @@ -214,7 +220,8 @@ public class AuditManagerTest } public void testAddAuditEvent() - throws ParseException + throws Exception + { AuditEvent event = createEvent( new Date() ); @@ -228,7 +235,7 @@ public class AuditManagerTest } public void testAddAuditEventNoRepositoryId() - throws ParseException + throws Exception { AuditEvent event = createEvent( new Date() ); event.setRepositoryId( null ); @@ -243,6 +250,8 @@ public class AuditManagerTest } public void testDeleteStats() + throws Exception + { metadataRepository.removeMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ); @@ -254,7 +263,8 @@ public class AuditManagerTest } public void testGetEventsRangeInside() - throws ParseException + throws Exception + { Date current = new Date(); @@ -263,20 +273,22 @@ public class AuditManagerTest AuditEvent expectedEvent = createEvent( expectedTimestamp ); AuditEvent event3 = createEvent( new Date( current.getTime() - 1000 ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), - Arrays.asList( event1.getName(), expectedEvent.getName(), event3.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + AuditEvent.FACET_ID ), + Arrays.asList( event1.getName(), expectedEvent.getName(), + event3.getName() ) ); // only match the middle one - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent.getName() ), - expectedEvent ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent.getName() ), + expectedEvent ); metadataRepositoryControl.replay(); List<AuditEvent> events = auditManager.getAuditEventsInRange( Collections.singletonList( TEST_REPO_ID ), - new Date( current.getTime() - 4000 ), - new Date( current.getTime() - 2000 ) ); + new Date( current.getTime() - 4000 ), new Date( + current.getTime() - 2000 ) ); assertEquals( 1, events.size() ); assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent.getResource() ); @@ -285,7 +297,7 @@ public class AuditManagerTest } public void testGetEventsRangeUpperOutside() - throws ParseException + throws Exception { Date current = new Date(); @@ -295,16 +307,19 @@ public class AuditManagerTest Date ts3 = new Date( current.getTime() - 1000 ); AuditEvent expectedEvent3 = createEvent( ts3 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), - Arrays.asList( event1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + AuditEvent.FACET_ID ), + Arrays.asList( event1.getName(), expectedEvent2.getName(), + expectedEvent3.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ), - expectedEvent2 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ), - expectedEvent3 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent2.getName() ), + expectedEvent2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent3.getName() ), + expectedEvent3 ); metadataRepositoryControl.replay(); @@ -319,7 +334,7 @@ public class AuditManagerTest } public void testGetEventsRangeLowerOutside() - throws ParseException + throws Exception { Date current = new Date(); @@ -329,22 +344,25 @@ public class AuditManagerTest AuditEvent expectedEvent2 = createEvent( expectedTimestamp ); AuditEvent event3 = createEvent( new Date( current.getTime() - 1000 ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), - Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), event3.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + AuditEvent.FACET_ID ), + Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), + event3.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ), - expectedEvent1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ), - expectedEvent2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent1.getName() ), + expectedEvent1 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent2.getName() ), + expectedEvent2 ); metadataRepositoryControl.replay(); List<AuditEvent> events = auditManager.getAuditEventsInRange( Collections.singletonList( TEST_REPO_ID ), - new Date( current.getTime() - 20000 ), - new Date( current.getTime() - 2000 ) ); + new Date( current.getTime() - 20000 ), new Date( + current.getTime() - 2000 ) ); assertEquals( 2, events.size() ); assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent2.getResource() ); @@ -354,7 +372,7 @@ public class AuditManagerTest } public void testGetEventsRangeLowerAndUpperOutside() - throws ParseException + throws Exception { Date current = new Date(); @@ -365,19 +383,23 @@ public class AuditManagerTest Date ts3 = new Date( current.getTime() - 1000 ); AuditEvent expectedEvent3 = createEvent( ts3 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), - Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) ); - - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ), - expectedEvent1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ), - expectedEvent2 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ), - expectedEvent3 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + AuditEvent.FACET_ID ), + Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), + expectedEvent3.getName() ) ); + + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent1.getName() ), + expectedEvent1 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent2.getName() ), + expectedEvent2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent3.getName() ), + expectedEvent3 ); metadataRepositoryControl.replay(); @@ -393,7 +415,7 @@ public class AuditManagerTest } public void testGetEventsWithResource() - throws ParseException + throws Exception { Date current = new Date(); @@ -405,25 +427,29 @@ public class AuditManagerTest Date ts3 = new Date( current.getTime() - 1000 ); AuditEvent expectedEvent3 = createEvent( ts3 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), - Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) ); - - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ), - expectedEvent1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ), - expectedEvent2 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ), - expectedEvent3 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + AuditEvent.FACET_ID ), + Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), + expectedEvent3.getName() ) ); + + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent1.getName() ), + expectedEvent1 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent2.getName() ), + expectedEvent2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent3.getName() ), + expectedEvent3 ); metadataRepositoryControl.replay(); - List<AuditEvent> events = - auditManager.getAuditEventsInRange( Collections.singletonList( TEST_REPO_ID ), TEST_RESOURCE_BASE, - new Date( current.getTime() - 20000 ), current ); + List<AuditEvent> events = auditManager.getAuditEventsInRange( Collections.singletonList( TEST_REPO_ID ), + TEST_RESOURCE_BASE, new Date( + current.getTime() - 20000 ), current ); assertEquals( 2, events.size() ); assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( ts3 ), expectedEvent3.getResource() ); @@ -433,7 +459,7 @@ public class AuditManagerTest } public void testGetEventsWithNonExistantResource() - throws ParseException + throws Exception { Date current = new Date(); @@ -443,19 +469,23 @@ public class AuditManagerTest expectedEvent2.setResource( "different-resource" ); AuditEvent expectedEvent3 = createEvent( new Date( current.getTime() - 1000 ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), - Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) ); - - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ), - expectedEvent1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ), - expectedEvent2 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ), - expectedEvent3 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + AuditEvent.FACET_ID ), + Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), + expectedEvent3.getName() ) ); + + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent1.getName() ), + expectedEvent1 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent2.getName() ), + expectedEvent2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent3.getName() ), + expectedEvent3 ); metadataRepositoryControl.replay(); @@ -468,7 +498,7 @@ public class AuditManagerTest } public void testGetEventsRangeMultipleRepositories() - throws ParseException + throws Exception { Date current = new Date(); @@ -480,22 +510,26 @@ public class AuditManagerTest Date ts3 = new Date( current.getTime() - 1000 ); AuditEvent expectedEvent3 = createEvent( ts3 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), - Arrays.asList( expectedEvent1.getName(), expectedEvent3.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID_2, AuditEvent.FACET_ID ), - Arrays.asList( expectedEvent2.getName() ) ); - - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ), - expectedEvent1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID_2, AuditEvent.FACET_ID, expectedEvent2.getName() ), - expectedEvent2 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ), - expectedEvent3 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + AuditEvent.FACET_ID ), + Arrays.asList( expectedEvent1.getName(), + expectedEvent3.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID_2, + AuditEvent.FACET_ID ), + Arrays.asList( expectedEvent2.getName() ) ); + + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent1.getName() ), + expectedEvent1 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID_2, + AuditEvent.FACET_ID, + expectedEvent2.getName() ), + expectedEvent2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + AuditEvent.FACET_ID, + expectedEvent3.getName() ), + expectedEvent3 ); metadataRepositoryControl.replay(); @@ -512,7 +546,7 @@ public class AuditManagerTest } public void testGetEventsRangeNotInside() - throws ParseException + throws Exception { Date current = new Date(); @@ -521,15 +555,15 @@ public class AuditManagerTest String name2 = createEvent( expectedTimestamp ).getName(); String name3 = createEvent( new Date( current.getTime() - 1000 ) ).getName(); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ), - Arrays.asList( name1, name2, name3 ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + AuditEvent.FACET_ID ), + Arrays.asList( name1, name2, name3 ) ); metadataRepositoryControl.replay(); List<AuditEvent> events = auditManager.getAuditEventsInRange( Collections.singletonList( TEST_REPO_ID ), - new Date( current.getTime() - 20000 ), - new Date( current.getTime() - 16000 ) ); + new Date( current.getTime() - 20000 ), new Date( + current.getTime() - 16000 ) ); assertEquals( 0, events.size() ); @@ -550,8 +584,9 @@ public class AuditManagerTest private static AuditEvent createEvent( String ts ) throws ParseException { - return createEvent( TEST_REPO_ID, ts, getDefaultTestResourceName( - ts.substring( AUDIT_EVENT_BASE.length(), AUDIT_EVENT_BASE.length() + 3 ) ) ); + return createEvent( TEST_REPO_ID, ts, getDefaultTestResourceName( ts.substring( AUDIT_EVENT_BASE.length(), + AUDIT_EVENT_BASE.length() + + 3 ) ) ); } private static AuditEvent createEvent( String repositoryId, String timestamp, String resource ) 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 ab6cc04b5..107d616ed 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 @@ -19,16 +19,7 @@ package org.apache.archiva.dependency.tree.maven2; * under the License. */ -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - +import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.metadata.repository.storage.maven2.RepositoryModelResolver; @@ -72,6 +63,16 @@ import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor; import org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor; import org.codehaus.plexus.logging.AbstractLogEnabled; +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + /** * Default implementation of <code>DependencyTreeBuilder</code>. Customized wrapper for maven-dependency-tree to use * maven-model-builder instead of maven-project. Note that the role must differ to avoid conflicting with the @@ -130,8 +131,8 @@ public class DefaultDependencyTreeBuilder try { - Model model = - buildProject( new RepositoryModelResolver( basedir, pathTranslator ), groupId, artifactId, version ); + Model model = buildProject( new RepositoryModelResolver( basedir, pathTranslator ), groupId, artifactId, + version ); Map managedVersions = createManagedVersionMap( model ); @@ -150,12 +151,12 @@ public class DefaultDependencyTreeBuilder DependencyNodeVisitor visitor = new BuildingDependencyNodeVisitor( nodeVisitor ); CollectingDependencyNodeVisitor collectingVisitor = new CollectingDependencyNodeVisitor(); - DependencyNodeVisitor firstPassVisitor = - new FilteringDependencyNodeVisitor( collectingVisitor, StateDependencyNodeFilter.INCLUDED ); + DependencyNodeVisitor firstPassVisitor = new FilteringDependencyNodeVisitor( collectingVisitor, + StateDependencyNodeFilter.INCLUDED ); rootNode.accept( firstPassVisitor ); - DependencyNodeFilter secondPassFilter = - new AncestorOrSelfDependencyNodeFilter( collectingVisitor.getNodes() ); + DependencyNodeFilter secondPassFilter = new AncestorOrSelfDependencyNodeFilter( + collectingVisitor.getNodes() ); visitor = new FilteringDependencyNodeVisitor( visitor, secondPassFilter ); rootNode.accept( visitor ); @@ -231,10 +232,10 @@ public class DefaultDependencyTreeBuilder } VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() ); - Artifact artifact = - factory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), versionRange, - dependency.getType(), dependency.getClassifier(), scope, null, - dependency.isOptional() ); + Artifact artifact = factory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), + versionRange, dependency.getType(), + dependency.getClassifier(), scope, null, + dependency.isOptional() ); if ( Artifact.SCOPE_SYSTEM.equals( scope ) ) { @@ -303,10 +304,10 @@ public class DefaultDependencyTreeBuilder VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() ); - Artifact artifact = - factory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), versionRange, - dependency.getType(), dependency.getClassifier(), - dependency.getScope(), dependency.isOptional() ); + Artifact artifact = factory.createDependencyArtifact( dependency.getGroupId(), + dependency.getArtifactId(), versionRange, + dependency.getType(), dependency.getClassifier(), + dependency.getScope(), dependency.isOptional() ); if ( getLogger().isDebugEnabled() ) { getLogger().debug( " " + artifact ); @@ -359,9 +360,8 @@ public class DefaultDependencyTreeBuilder // TODO: we removed relocation support here. This is something that might need to be generically handled // throughout this module - Artifact pomArtifact = - factory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), - artifact.getScope() ); + Artifact pomArtifact = factory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion(), artifact.getScope() ); File basedir = findArtifactInRepositories( repositoryIds, pomArtifact ); @@ -370,9 +370,8 @@ public class DefaultDependencyTreeBuilder { try { - project = - buildProject( new RepositoryModelResolver( basedir, pathTranslator ), artifact.getGroupId(), - artifact.getArtifactId(), artifact.getVersion() ); + project = buildProject( new RepositoryModelResolver( basedir, pathTranslator ), + artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); } catch ( ModelBuildingException e ) { @@ -423,8 +422,16 @@ public class DefaultDependencyTreeBuilder Set<ArtifactVersion> versions = new HashSet<ArtifactVersion>(); for ( String repoId : repositoryIds ) { - Collection<String> projectVersions = - metadataResolver.getProjectVersions( repoId, artifact.getGroupId(), artifact.getArtifactId() ); + Collection<String> projectVersions; + try + { + projectVersions = metadataResolver.getProjectVersions( repoId, artifact.getGroupId(), + artifact.getArtifactId() ); + } + catch ( MetadataResolutionException e ) + { + throw new ArtifactMetadataRetrievalException( e.getMessage(), e, artifact ); + } for ( String version : projectVersions ) { versions.add( new DefaultArtifactVersion( version ) ); 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 611861cd7..66a41c02a 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 @@ -26,6 +26,7 @@ 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.MetadataRepositoryException; import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.metadata.repository.filter.AllFilter; import org.apache.archiva.metadata.repository.filter.Filter; @@ -116,7 +117,15 @@ public class Maven2RepositoryMetadataResolver // TODO: an event mechanism would remove coupling to the problem reporting plugin // TODO: this removes all problems - do we need something that just removes the problems created by this resolver? String name = RepositoryProblemFacet.createName( namespace, projectId, projectVersion, null ); - metadataRepository.removeMetadataFacet( repoId, RepositoryProblemFacet.FACET_ID, name ); + try + { + metadataRepository.removeMetadataFacet( repoId, RepositoryProblemFacet.FACET_ID, name ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to remove repository problem facets for the version being removed: " + e.getMessage(), + e ); + } ManagedRepositoryConfiguration repositoryConfiguration = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId ); @@ -251,7 +260,14 @@ public class Maven2RepositoryMetadataResolver problem.setRepositoryId( repoId ); problem.setVersion( projectVersion ); - metadataRepository.addMetadataFacet( repoId, problem ); + try + { + metadataRepository.addMetadataFacet( repoId, problem ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to add repository problem facets for the version being removed: " + e.getMessage(), e ); + } } private List<org.apache.archiva.metadata.model.Dependency> convertDependencies( List<Dependency> dependencies ) diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java index 33741e921..0bbdb48b3 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java @@ -33,6 +33,7 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.model.Scm; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.jackrabbit.commons.JcrUtils; import org.apache.jackrabbit.core.TransientRepository; @@ -69,7 +70,6 @@ import javax.jcr.query.QueryResult; /** * @plexus.component role="org.apache.archiva.metadata.repository.MetadataRepository" - * @todo below: exception handling * @todo below: revise storage format for project version metadata * @todo revise reference storage */ @@ -109,6 +109,7 @@ public class JcrMetadataRepository // TODO: shouldn't do this in constructor since it's a singleton session = repository.login( new SimpleCredentials( "username", "password".toCharArray() ) ); + // TODO: try moving this into the repo instantiation Workspace workspace = session.getWorkspace(); workspace.getNamespaceRegistry().registerNamespace( "archiva", "http://archiva.apache.org/jcr/" ); @@ -138,11 +139,13 @@ public class JcrMetadataRepository } public void updateProject( String repositoryId, ProjectMetadata project ) + throws MetadataRepositoryException { updateProject( repositoryId, project.getNamespace(), project.getId() ); } private void updateProject( String repositoryId, String namespace, String projectId ) + throws MetadataRepositoryException { updateNamespace( repositoryId, namespace ); @@ -152,13 +155,13 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } } public void updateArtifact( String repositoryId, String namespace, String projectId, String projectVersion, ArtifactMetadata artifactMeta ) + throws MetadataRepositoryException { updateNamespace( repositoryId, namespace ); @@ -202,13 +205,13 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } } public void updateProjectVersion( String repositoryId, String namespace, String projectId, ProjectVersionMetadata versionMetadata ) + throws MetadataRepositoryException { updateProject( repositoryId, namespace, projectId ); @@ -294,13 +297,13 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } } public void updateProjectReference( String repositoryId, String namespace, String projectId, String projectVersion, ProjectVersionReference reference ) + throws MetadataRepositoryException { // not using weak references, since they still need to exist upfront to be referred to try @@ -317,12 +320,12 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } } public void updateNamespace( String repositoryId, String namespace ) + throws MetadataRepositoryException { try { @@ -331,12 +334,12 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } } public List<String> getMetadataFacets( String repositoryId, String facetId ) + throws MetadataRepositoryException { List<String> facets = new ArrayList<String>(); @@ -356,8 +359,7 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } return facets; } @@ -381,6 +383,7 @@ public class JcrMetadataRepository } public MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name ) + throws MetadataRepositoryException { MetadataFacet metadataFacet = null; try @@ -410,13 +413,13 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } return metadataFacet; } public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet ) + throws MetadataRepositoryException { try { @@ -435,12 +438,12 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } } public void removeMetadataFacets( String repositoryId, String facetId ) + throws MetadataRepositoryException { try { @@ -453,12 +456,12 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } } public void removeMetadataFacet( String repositoryId, String facetId, String name ) + throws MetadataRepositoryException { try { @@ -479,12 +482,12 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } } public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime ) + throws MetadataRepositoryException { List<ArtifactMetadata> artifacts; @@ -523,13 +526,13 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } return artifacts; } public Collection<String> getRepositories() + throws MetadataRepositoryException { List<String> repositories; @@ -555,13 +558,13 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } return repositories; } public List<ArtifactMetadata> getArtifactsByChecksum( String repositoryId, String checksum ) + throws MetadataRepositoryException { List<ArtifactMetadata> artifacts; @@ -582,14 +585,14 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } return artifacts; } public void deleteArtifact( String repositoryId, String namespace, String projectId, String projectVersion, String id ) + throws MetadataRepositoryException { try { @@ -602,12 +605,12 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } } public void deleteRepository( String repositoryId ) + throws MetadataRepositoryException { try { @@ -620,12 +623,12 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } } public List<ArtifactMetadata> getArtifacts( String repositoryId ) + throws MetadataRepositoryException { List<ArtifactMetadata> artifacts; @@ -644,13 +647,13 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataRepositoryException( e.getMessage(), e ); } return artifacts; } public ProjectMetadata getProject( String repositoryId, String namespace, String projectId ) + throws MetadataResolutionException { ProjectMetadata metadata = null; @@ -669,8 +672,7 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataResolutionException( e.getMessage(), e ); } return metadata; @@ -852,8 +854,7 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataResolutionException( e.getMessage(), e ); } return versionMetadata; @@ -861,6 +862,7 @@ public class JcrMetadataRepository public Collection<String> getArtifactVersions( String repositoryId, String namespace, String projectId, String projectVersion ) + throws MetadataResolutionException { Set<String> versions = new LinkedHashSet<String>(); @@ -878,12 +880,10 @@ public class JcrMetadataRepository catch ( PathNotFoundException e ) { // ignore repo not found for now - // TODO: throw specific exception if repo doesn't exist } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataResolutionException( e.getMessage(), e ); } return versions; @@ -891,6 +891,7 @@ public class JcrMetadataRepository public Collection<ProjectVersionReference> getProjectReferences( String repositoryId, String namespace, String projectId, String projectVersion ) + throws MetadataResolutionException { List<ProjectVersionReference> references = new ArrayList<ProjectVersionReference>(); @@ -934,19 +935,20 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataResolutionException( e.getMessage(), e ); } return references; } public Collection<String> getRootNamespaces( String repositoryId ) + throws MetadataResolutionException { return getNamespaces( repositoryId, null ); } public Collection<String> getNamespaces( String repositoryId, String baseNamespace ) + throws MetadataResolutionException { String path = baseNamespace != null ? getNamespacePath( repositoryId, baseNamespace ) @@ -956,17 +958,20 @@ public class JcrMetadataRepository } public Collection<String> getProjects( String repositoryId, String namespace ) + throws MetadataResolutionException { return getNodeNames( getNamespacePath( repositoryId, namespace ) ); } public Collection<String> getProjectVersions( String repositoryId, String namespace, String projectId ) + throws MetadataResolutionException { return getNodeNames( getProjectPath( repositoryId, namespace, projectId ) ); } public Collection<ArtifactMetadata> getArtifacts( String repositoryId, String namespace, String projectId, String projectVersion ) + throws MetadataResolutionException { List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(); @@ -987,8 +992,7 @@ public class JcrMetadataRepository } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataResolutionException( e.getMessage(), e ); } return artifacts; @@ -1104,6 +1108,7 @@ public class JcrMetadataRepository } private Collection<String> getNodeNames( String path ) + throws MetadataResolutionException { List<String> names = new ArrayList<String>(); @@ -1123,12 +1128,10 @@ public class JcrMetadataRepository catch ( PathNotFoundException e ) { // ignore repo not found for now - // TODO: throw specific exception if repo doesn't exist } catch ( RepositoryException e ) { - // TODO - throw new RuntimeException( e ); + throw new MetadataResolutionException( e.getMessage(), e ); } return names; diff --git a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java index cec2b0861..fe4201056 100644 --- a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java +++ b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java @@ -20,7 +20,10 @@ package org.apache.archiva.reports; */ import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.repository.events.RepositoryListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Process repository management events and respond appropriately. @@ -30,6 +33,8 @@ import org.apache.archiva.repository.events.RepositoryListener; public class RepositoryProblemEventListener implements RepositoryListener { + private Logger log = LoggerFactory.getLogger( RepositoryProblemEventListener.class ); + /** * @plexus.requirement */ @@ -39,6 +44,13 @@ public class RepositoryProblemEventListener { String name = RepositoryProblemFacet.createName( namespace, project, version, id ); - metadataRepository.removeMetadataFacet( repositoryId, RepositoryProblemFacet.FACET_ID, name ); + try + { + metadataRepository.removeMetadataFacet( repositoryId, RepositoryProblemFacet.FACET_ID, name ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to remove metadata facet as part of delete event: " + e.getMessage(), e ); + } } }
\ No newline at end of file diff --git a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java index 95572ec64..82bbc2b13 100644 --- a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java +++ b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java @@ -23,6 +23,7 @@ import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.reports.RepositoryProblemFacet; import org.apache.commons.collections.CollectionUtils; @@ -96,6 +97,7 @@ public class DuplicateArtifactsConsumer /** * FIXME: needs to be selected based on the repository in question + * * @plexus.requirement role-hint="maven2" */ private RepositoryPathTranslator pathTranslator; @@ -135,7 +137,7 @@ public class DuplicateArtifactsConsumer public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered, boolean executeOnEntireRepo ) throws ConsumerException { - beginScan( repo, whenGathered ); + beginScan( repo, whenGathered ); } public void processFile( String path ) @@ -158,7 +160,15 @@ public class DuplicateArtifactsConsumer throw new ConsumerException( e.getMessage(), e ); } - List<ArtifactMetadata> results = metadataRepository.getArtifactsByChecksum( repoId, checksumSha1 ); + List<ArtifactMetadata> results; + try + { + results = metadataRepository.getArtifactsByChecksum( repoId, checksumSha1 ); + } + catch ( MetadataRepositoryException e ) + { + throw new ConsumerException( e.getMessage(), e ); + } if ( CollectionUtils.isNotEmpty( results ) ) { @@ -203,7 +213,14 @@ public class DuplicateArtifactsConsumer dupArtifact.getId() ) ); problem.setProblem( "duplicate-artifact" ); - metadataRepository.addMetadataFacet( repoId, problem ); + try + { + metadataRepository.addMetadataFacet( repoId, problem ); + } + catch ( MetadataRepositoryException e ) + { + throw new ConsumerException( e.getMessage(), e ); + } } } } @@ -211,7 +228,7 @@ public class DuplicateArtifactsConsumer public void processFile( String path, boolean executeOnEntireRepo ) throws ConsumerException { - processFile( path ); + processFile( path ); } public void completeScan() diff --git a/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java b/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java index e4fd2c62e..a69223a01 100644 --- a/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java +++ b/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java @@ -83,7 +83,7 @@ public class DuplicateArtifactsConsumerTest } public void testConsumerArtifactNotDuplicated() - throws ConsumerException + throws Exception { when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn( Arrays.asList( TEST_METADATA ) ); @@ -110,7 +110,7 @@ public class DuplicateArtifactsConsumerTest // } public void testConsumerArtifactDuplicated() - throws ConsumerException + throws Exception { when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn( Arrays.asList( TEST_METADATA, createMetadata( "1.0" ) ) ); @@ -126,7 +126,7 @@ public class DuplicateArtifactsConsumerTest } public void testConsumerArtifactDuplicatedButSelfNotInMetadataRepository() - throws ConsumerException + throws Exception { when( metadataRepository.getArtifactsByChecksum( TEST_REPO, TEST_CHECKSUM ) ).thenReturn( Arrays.asList( createMetadata( "1.0" ) ) ); @@ -142,7 +142,7 @@ public class DuplicateArtifactsConsumerTest } public void testConsumerArtifactFileNotExist() - throws ConsumerException + throws Exception { consumer.beginScan( config, new Date() ); try @@ -163,7 +163,7 @@ public class DuplicateArtifactsConsumerTest } public void testConsumerArtifactNotAnArtifactPathNoResults() - throws ConsumerException + throws Exception { consumer.beginScan( config, new Date() ); // No exception unnecessarily for something we can't report on @@ -174,7 +174,7 @@ public class DuplicateArtifactsConsumerTest } public void testConsumerArtifactNotAnArtifactPathResults() - throws ConsumerException + throws Exception { when( metadataRepository.getArtifactsByChecksum( eq( TEST_REPO ), anyString() ) ).thenReturn( Arrays.asList( TEST_METADATA, createMetadata( "1.0" ) ) ); 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 7f2466470..876ff19bc 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,6 +21,8 @@ package org.apache.archiva.metadata.repository.stats; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; +import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,6 +52,7 @@ public class DefaultRepositoryStatisticsManager private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" ); public RepositoryStatistics getLastStatistics( String repositoryId ) + throws MetadataRepositoryException { // 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 ); @@ -67,6 +70,7 @@ public class DefaultRepositoryStatisticsManager } private void walkRepository( RepositoryStatistics stats, String repositoryId, String ns ) + throws MetadataResolutionException { for ( String namespace : metadataRepository.getNamespaces( repositoryId, ns ) ) { @@ -89,7 +93,8 @@ public class DefaultRepositoryStatisticsManager stats.setTotalArtifactCount( stats.getTotalArtifactCount() + 1 ); stats.setTotalArtifactFileSize( stats.getTotalArtifactFileSize() + artifact.getSize() ); - MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet( MavenArtifactFacet.FACET_ID ); + MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet( + MavenArtifactFacet.FACET_ID ); if ( facet != null ) { String type = facet.getType(); @@ -104,6 +109,7 @@ public class DefaultRepositoryStatisticsManager public void addStatisticsAfterScan( String repositoryId, Date startTime, Date endTime, long totalFiles, long newFiles ) + throws MetadataRepositoryException { RepositoryStatistics repositoryStatistics = new RepositoryStatistics(); repositoryStatistics.setScanStartTime( startTime ); @@ -121,9 +127,16 @@ public class DefaultRepositoryStatisticsManager // 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 ) ) + try { - walkRepository( repositoryStatistics, repositoryId, ns ); + for ( String ns : metadataRepository.getRootNamespaces( repositoryId ) ) + { + walkRepository( repositoryStatistics, repositoryId, ns ); + } + } + catch ( MetadataResolutionException e ) + { + throw new MetadataRepositoryException( e.getMessage(), e ); } log.info( "Repository walk for statistics executed in " + ( System.currentTimeMillis() - startWalk ) + "ms" ); @@ -131,11 +144,13 @@ public class DefaultRepositoryStatisticsManager } public void deleteStatistics( String repositoryId ) + throws MetadataRepositoryException { metadataRepository.removeMetadataFacets( repositoryId, RepositoryStatistics.FACET_ID ); } public List<RepositoryStatistics> getStatisticsInRange( String repositoryId, Date startTime, Date endTime ) + throws MetadataRepositoryException { List<RepositoryStatistics> results = new ArrayList<RepositoryStatistics>(); List<String> list = metadataRepository.getMetadataFacets( repositoryId, RepositoryStatistics.FACET_ID ); @@ -145,13 +160,11 @@ public class DefaultRepositoryStatisticsManager try { Date date = createNameFormat().parse( name ); - if ( ( startTime == null || !date.before( startTime ) ) && - ( endTime == null || !date.after( endTime ) ) ) + if ( ( startTime == null || !date.before( startTime ) ) && ( endTime == null || !date.after( + endTime ) ) ) { - RepositoryStatistics stats = - (RepositoryStatistics) metadataRepository.getMetadataFacet( repositoryId, - RepositoryStatistics.FACET_ID, - name ); + RepositoryStatistics stats = (RepositoryStatistics) metadataRepository.getMetadataFacet( + repositoryId, RepositoryStatistics.FACET_ID, name ); results.add( stats ); } } 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 6abc44348..69fed9f65 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 @@ -19,16 +19,22 @@ package org.apache.archiva.metadata.repository.stats; * under the License. */ +import org.apache.archiva.metadata.repository.MetadataRepositoryException; + import java.util.Date; import java.util.List; public interface RepositoryStatisticsManager { - RepositoryStatistics getLastStatistics( String repositoryId ); + RepositoryStatistics getLastStatistics( String repositoryId ) + throws MetadataRepositoryException; - void addStatisticsAfterScan( String repositoryId, Date startTime, Date endTime, long totalFiles, long newFiles ); + void addStatisticsAfterScan( String repositoryId, Date startTime, Date endTime, long totalFiles, long newFiles ) + throws MetadataRepositoryException; - void deleteStatistics( String repositoryId ); + void deleteStatistics( String repositoryId ) + throws MetadataRepositoryException; - List<RepositoryStatistics> getStatisticsInRange( String repositoryId, Date startTime, Date endTime ); + List<RepositoryStatistics> getStatisticsInRange( String repositoryId, Date startTime, Date endTime ) + throws MetadataRepositoryException; } 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 5603c5d38..9757ca910 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 @@ -25,7 +25,6 @@ import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.easymock.MockControl; -import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -76,7 +75,7 @@ public class RepositoryStatisticsManagerTest } public void testGetLatestStats() - throws ParseException + throws Exception { Date startTime = TIMESTAMP_FORMAT.parse( SECOND_TEST_SCAN ); Date endTime = new Date( startTime.getTime() + 60000 ); @@ -91,12 +90,12 @@ public class RepositoryStatisticsManagerTest 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.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 ); @@ -115,10 +114,11 @@ public class RepositoryStatisticsManagerTest } public void testGetLatestStatsWhenEmpty() + throws Exception { - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), - Collections.emptyList() ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + Collections.emptyList() ); metadataRepositoryControl.replay(); RepositoryStatistics stats = repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ); @@ -128,6 +128,8 @@ public class RepositoryStatisticsManagerTest } public void testAddNewStats() + throws Exception + { Date current = new Date(); Date startTime = new Date( current.getTime() - 12345 ); @@ -137,12 +139,12 @@ public class RepositoryStatisticsManagerTest walkRepository( 1 ); metadataRepository.addMetadataFacet( TEST_REPO_ID, stats ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), - Arrays.asList( stats.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats.getName() ), - stats ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + Arrays.asList( stats.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + stats.getName() ), stats ); metadataRepositoryControl.replay(); @@ -163,6 +165,8 @@ public class RepositoryStatisticsManagerTest } public void testDeleteStats() + throws Exception + { walkRepository( 2 ); @@ -176,18 +180,18 @@ public class RepositoryStatisticsManagerTest RepositoryStatistics stats2 = createTestStats( startTime2, current ); metadataRepository.addMetadataFacet( TEST_REPO_ID, stats2 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), - Arrays.asList( stats1.getName(), stats2.getName() ) ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats2.getName() ), - stats2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + Arrays.asList( stats1.getName(), stats2.getName() ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + stats2.getName() ), stats2 ); metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), - Collections.emptyList() ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + Collections.emptyList() ); metadataRepositoryControl.replay(); @@ -206,10 +210,12 @@ public class RepositoryStatisticsManagerTest } public void testDeleteStatsWhenEmpty() + throws Exception + { - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), - Collections.emptyList(), 2 ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + Collections.emptyList(), 2 ); metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ); metadataRepositoryControl.replay(); @@ -224,6 +230,8 @@ public class RepositoryStatisticsManagerTest } public void testGetStatsRangeInside() + throws Exception + { walkRepository( 3 ); @@ -234,14 +242,16 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + keys ); // only match the middle one String key = keys.get( 1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); metadataRepositoryControl.replay(); @@ -251,9 +261,8 @@ public class RepositoryStatisticsManagerTest stats.getScanEndTime(), 56345, 45 ); } - List<RepositoryStatistics> list = - repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 4000 ), - new Date( current.getTime() - 2000 ) ); + List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( + current.getTime() - 4000 ), new Date( current.getTime() - 2000 ) ); assertEquals( 1, list.size() ); assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() ); @@ -262,6 +271,8 @@ public class RepositoryStatisticsManagerTest } public void testGetStatsRangeUpperOutside() + throws Exception + { walkRepository( 3 ); @@ -272,17 +283,20 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + keys ); String key = keys.get( 1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); key = keys.get( 2 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); metadataRepositoryControl.replay(); @@ -292,9 +306,8 @@ public class RepositoryStatisticsManagerTest stats.getScanEndTime(), 56345, 45 ); } - List<RepositoryStatistics> list = - repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 4000 ), - current ); + List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( + current.getTime() - 4000 ), current ); assertEquals( 2, list.size() ); assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() ); @@ -304,6 +317,8 @@ public class RepositoryStatisticsManagerTest } public void testGetStatsRangeLowerOutside() + throws Exception + { walkRepository( 3 ); @@ -314,17 +329,20 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + keys ); String key = keys.get( 0 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); key = keys.get( 1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); metadataRepositoryControl.replay(); @@ -334,9 +352,8 @@ public class RepositoryStatisticsManagerTest stats.getScanEndTime(), 56345, 45 ); } - List<RepositoryStatistics> list = - repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 20000 ), - new Date( current.getTime() - 2000 ) ); + List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( + current.getTime() - 20000 ), new Date( current.getTime() - 2000 ) ); assertEquals( 2, list.size() ); assertEquals( new Date( current.getTime() - 12345 ), list.get( 1 ).getScanStartTime() ); @@ -346,6 +363,8 @@ public class RepositoryStatisticsManagerTest } public void testGetStatsRangeLowerAndUpperOutside() + throws Exception + { walkRepository( 3 ); @@ -356,21 +375,25 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + keys ); String key = keys.get( 0 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); key = keys.get( 1 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); key = keys.get( 2 ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ), - statsCreated.get( key ) ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, + RepositoryStatistics.FACET_ID, + key ), statsCreated.get( + key ) ); metadataRepositoryControl.replay(); @@ -380,9 +403,8 @@ public class RepositoryStatisticsManagerTest stats.getScanEndTime(), 56345, 45 ); } - List<RepositoryStatistics> list = - repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 20000 ), - current ); + List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( + current.getTime() - 20000 ), current ); assertEquals( 3, list.size() ); assertEquals( new Date( current.getTime() - 12345 ), list.get( 2 ).getScanStartTime() ); @@ -393,6 +415,8 @@ public class RepositoryStatisticsManagerTest } public void testGetStatsRangeNotInside() + throws Exception + { walkRepository( 3 ); @@ -403,8 +427,9 @@ public class RepositoryStatisticsManagerTest addStats( new Date( current.getTime() - 1000 ), current ); ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() ); - metadataRepositoryControl.expectAndReturn( - metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, + RepositoryStatistics.FACET_ID ), + keys ); metadataRepositoryControl.replay(); @@ -414,9 +439,8 @@ public class RepositoryStatisticsManagerTest stats.getScanEndTime(), 56345, 45 ); } - List<RepositoryStatistics> list = - repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 20000 ), - new Date( current.getTime() - 16000 ) ); + List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( + current.getTime() - 20000 ), new Date( current.getTime() - 16000 ) ); assertEquals( 0, list.size() ); @@ -424,6 +448,8 @@ public class RepositoryStatisticsManagerTest } private void addStats( Date startTime, Date endTime ) + throws Exception + { RepositoryStatistics stats = createTestStats( startTime, endTime ); metadataRepository.addMetadataFacet( TEST_REPO_ID, stats ); @@ -465,6 +491,7 @@ public class RepositoryStatisticsManagerTest } private void walkRepository( int count ) + throws Exception { for ( int i = 0; i < count; i++ ) { @@ -478,89 +505,124 @@ public class RepositoryStatisticsManagerTest 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.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-model", "1.3-SNAPSHOT", "jar" ), - createArtifact( "org.apache.archiva", "metadata-model", "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-model", "1.3", "jar" ), - createArtifact( "org.apache.archiva", "metadata-model", "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", "maven-model", "2.2.1", "jar" ), - createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "pom" ) ) ); + 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-model", "1.3-SNAPSHOT", "jar" ), createArtifact( + "org.apache.archiva", "metadata-model", "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-model", "1.3", "jar" ), + createArtifact( "org.apache.archiva", + "metadata-model", "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", + "maven-model", "2.2.1", "jar" ), + createArtifact( "org.apache.archiva", + "maven-model", "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" ) ) ); + 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" ) ) ); } } } |