From e7c8bea2e6355f471556080ec33d4ba8e7f66629 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Wed, 29 Dec 2010 07:06:17 +0000 Subject: [PATCH] [MRM-1330] update DuplicateArtifactsConsumer to the session-based API git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1053554 13f79535-47bb-0310-9956-ffa450edef68 --- .../consumers/DuplicateArtifactsConsumer.java | 21 +++++++++++++------ .../DuplicateArtifactsConsumerTest.java | 10 ++++++++- ...DuplicateArtifactsConsumerTest-context.xml | 6 +++--- 3 files changed, 27 insertions(+), 10 deletions(-) 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 5ba9abb12..ee77dcd96 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 @@ -24,6 +24,8 @@ 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.RepositorySession; +import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.reports.RepositoryProblemFacet; import org.apache.commons.collections.CollectionUtils; @@ -84,17 +86,19 @@ public class DuplicateArtifactsConsumer */ private FileTypes filetypes; + /** + * FIXME: can be of other types + * + * @plexus.requirement + */ + private RepositorySessionFactory repositorySessionFactory; + private List includes = new ArrayList(); private File repositoryDir; private String repoId; - /** - * @plexus.requirement - */ - private MetadataRepository metadataRepository; - /** * FIXME: needs to be selected based on the repository in question * @@ -102,6 +106,8 @@ public class DuplicateArtifactsConsumer */ private RepositoryPathTranslator pathTranslator; + private RepositorySession repositorySession; + public String getId() { return id; @@ -132,6 +138,7 @@ public class DuplicateArtifactsConsumer { repoId = repo.getId(); this.repositoryDir = new File( repo.getLocation() ); + repositorySession = repositorySessionFactory.createSession(); } public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered, boolean executeOnEntireRepo ) @@ -160,6 +167,8 @@ public class DuplicateArtifactsConsumer throw new ConsumerException( e.getMessage(), e ); } + MetadataRepository metadataRepository = repositorySession.getRepository(); + List results; try { @@ -233,7 +242,7 @@ public class DuplicateArtifactsConsumer public void completeScan() { - // nothing to do + repositorySession.close(); } public void completeScan( boolean executeOnEntireRepo ) 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 a69223a01..5dedab00b 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 @@ -22,6 +22,8 @@ package org.apache.archiva.reports.consumers; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.MetadataFacet; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.reports.RepositoryProblemFacet; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; @@ -76,7 +78,13 @@ public class DuplicateArtifactsConsumerTest config.setId( TEST_REPO ); config.setLocation( getTestFile( "target/test-repository" ).getAbsolutePath() ); - metadataRepository = (MetadataRepository) lookup( MetadataRepository.class ); + metadataRepository = mock( MetadataRepository.class ); + + RepositorySession session = mock( RepositorySession.class ); + when( session.getRepository() ).thenReturn( metadataRepository ); + + RepositorySessionFactory factory = (RepositorySessionFactory) lookup( RepositorySessionFactory.class ); + when( factory.createSession() ).thenReturn( session ); pathTranslator = (RepositoryPathTranslator) lookup( RepositoryPathTranslator.class, "maven2" ); when( pathTranslator.getArtifactForPath( TEST_REPO, TEST_FILE ) ).thenReturn( TEST_METADATA ); diff --git a/archiva-modules/plugins/problem-reports/src/test/resources/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest-context.xml b/archiva-modules/plugins/problem-reports/src/test/resources/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest-context.xml index 0aafa2680..8265901cd 100644 --- a/archiva-modules/plugins/problem-reports/src/test/resources/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest-context.xml +++ b/archiva-modules/plugins/problem-reports/src/test/resources/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest-context.xml @@ -21,9 +21,9 @@ - - + + -- 2.39.5