diff options
author | Brett Porter <brett@apache.org> | 2010-12-29 07:06:17 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2010-12-29 07:06:17 +0000 |
commit | e7c8bea2e6355f471556080ec33d4ba8e7f66629 (patch) | |
tree | a1c4d8d7bef6c3c85b947eb11a034d1f78b71efb /archiva-modules | |
parent | f56609efad6393b10c861446ec11ddda00f9a218 (diff) | |
download | archiva-e7c8bea2e6355f471556080ec33d4ba8e7f66629.tar.gz archiva-e7c8bea2e6355f471556080ec33d4ba8e7f66629.zip |
[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
Diffstat (limited to 'archiva-modules')
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,6 +86,13 @@ public class DuplicateArtifactsConsumer */ private FileTypes filetypes; + /** + * FIXME: can be of other types + * + * @plexus.requirement + */ + private RepositorySessionFactory repositorySessionFactory; + private List<String> includes = new ArrayList<String>(); private File repositoryDir; @@ -91,17 +100,14 @@ public class DuplicateArtifactsConsumer private String repoId; /** - * @plexus.requirement - */ - private MetadataRepository metadataRepository; - - /** * FIXME: needs to be selected based on the repository in question * * @plexus.requirement role-hint="maven2" */ 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<ArtifactMetadata> 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 @@ <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - <bean id="metadataRepositoryFactory" class="org.apache.archiva.reports.consumers.MockitoFactory" - name="metadataRepository"> - <constructor-arg value="org.apache.archiva.metadata.repository.MetadataRepository"/> + <bean id="repositorySessionFactoryFactory" class="org.apache.archiva.reports.consumers.MockitoFactory" + name="repositorySessionFactory"> + <constructor-arg value="org.apache.archiva.metadata.repository.RepositorySessionFactory"/> </bean> <bean id="repositoryPathTranslatorFactory" class="org.apache.archiva.reports.consumers.MockitoFactory" name="repositoryPathTranslator#maven2"> |