diff options
author | Brett Porter <brett@apache.org> | 2010-12-29 06:14:04 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2010-12-29 06:14:04 +0000 |
commit | f56609efad6393b10c861446ec11ddda00f9a218 (patch) | |
tree | 05aad2cd341eff4c2c1e3397e8a93570ef27bcfc /archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services | |
parent | a44b2ac9dd664f3a93e2a7001afd507abb218110 (diff) | |
download | archiva-f56609efad6393b10c861446ec11ddda00f9a218.tar.gz archiva-f56609efad6393b10c861446ec11ddda00f9a218.zip |
[MRM-1330] refactor access around the concept of a "repository session". See Javadoc for some notes. This should be a single entry point for application users of either the metadata repository, resolution, or storage access. The session needs to be explicitly closed (and modifications saved) to facilitate some storage mechanisms.
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1053542 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services')
5 files changed, 294 insertions, 166 deletions
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml index 06377c24d..2d6742b88 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml @@ -18,7 +18,8 @@ ~ under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.archiva</groupId> @@ -49,7 +50,7 @@ <dependency> <groupId>org.apache.archiva</groupId> <artifactId>audit</artifactId> - </dependency> + </dependency> <dependency> <groupId>org.apache.archiva</groupId> <artifactId>archiva-repository-scanner</artifactId> @@ -83,6 +84,11 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <scope>test</scope> - </dependency> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java index 1250ec447..422960e22 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java @@ -23,6 +23,8 @@ import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.audit.AuditListener; import org.apache.archiva.metadata.model.ArtifactMetadata; 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.filter.Filter; import org.apache.archiva.metadata.repository.filter.IncludesFilter; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; @@ -84,8 +86,6 @@ public class AdministrationServiceImpl private Collection<RepositoryListener> listeners; - private MetadataRepository metadataRepository; - private RepositoryStatisticsManager repositoryStatisticsManager; private RepositoryMerger repositoryMerger; @@ -94,8 +94,11 @@ public class AdministrationServiceImpl private AuditListener auditListener; + private RepositorySessionFactory repositorySessionFactory; + public AdministrationServiceImpl( ArchivaConfiguration archivaConfig, RepositoryContentConsumers repoConsumersUtil, - RepositoryContentFactory repoFactory, MetadataRepository metadataRepository, + RepositoryContentFactory repoFactory, + RepositorySessionFactory repositorySessionFactory, RepositoryArchivaTaskScheduler repositoryTaskScheduler, Collection<RepositoryListener> listeners, RepositoryStatisticsManager repositoryStatisticsManager, @@ -106,7 +109,7 @@ public class AdministrationServiceImpl this.repoFactory = repoFactory; this.repositoryTaskScheduler = repositoryTaskScheduler; this.listeners = listeners; - this.metadataRepository = metadataRepository; + this.repositorySessionFactory = repositorySessionFactory; this.repositoryStatisticsManager = repositoryStatisticsManager; this.repositoryMerger = repositoryMerger; this.auditListener = auditListener; @@ -186,6 +189,7 @@ public class AdministrationServiceImpl throw new Exception( "Repository does not exist." ); } + RepositorySession repositorySession = repositorySessionFactory.createSession(); try { ManagedRepositoryContent repoContent = repoFactory.getManagedRepositoryContent( repoId ); @@ -197,6 +201,7 @@ public class AdministrationServiceImpl // delete from file system repoContent.deleteVersion( ref ); + MetadataRepository metadataRepository = repositorySession.getRepository(); Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts( repoId, groupId, artifactId, version ); @@ -212,11 +217,12 @@ public class AdministrationServiceImpl // repository metadata to an artifact for ( RepositoryListener listener : listeners ) { - listener.deleteArtifact( repoId, artifact.getNamespace(), artifact.getProject(), - artifact.getVersion(), artifact.getId() ); + listener.deleteArtifact( metadataRepository, repoId, artifact.getNamespace(), + artifact.getProject(), artifact.getVersion(), artifact.getId() ); } } } + repositorySession.save(); } catch ( ContentNotFoundException e ) { @@ -230,6 +236,10 @@ public class AdministrationServiceImpl { throw new Exception( "Repository exception occurred." ); } + finally + { + repositorySession.close(); + } return true; } @@ -407,8 +417,18 @@ public class AdministrationServiceImpl throw new Exception( "A repository with that id does not exist" ); } - metadataRepository.removeRepository( repository.getId() ); - repositoryStatisticsManager.deleteStatistics( repository.getId() ); + RepositorySession repositorySession = repositorySessionFactory.createSession(); + try + { + MetadataRepository metadataRepository = repositorySession.getRepository(); + metadataRepository.removeRepository( repository.getId() ); + repositoryStatisticsManager.deleteStatistics( metadataRepository, repository.getId() ); + repositorySession.save(); + } + finally + { + repositorySession.close(); + } config.removeManagedRepository( repository ); try @@ -476,108 +496,116 @@ public class AdministrationServiceImpl log.debug( "Retrieved repository configuration for repo '" + repoId + "'" ); - if ( repoConfig != null ) + RepositorySession repositorySession = repositorySessionFactory.createSession(); + try { - stagingConfig = config.findManagedRepositoryById( stagingId ); - - if ( stagingConfig != null ) + MetadataRepository metadataRepository = repositorySession.getRepository(); + if ( repoConfig != null ) { - List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( stagingId ); + stagingConfig = config.findManagedRepositoryById( stagingId ); - if ( repoConfig.isReleases() && !repoConfig.isSnapshots() ) + if ( stagingConfig != null ) { - log.info( "Repository to be merged contains releases only.." ); - if ( skipConflicts ) - { - List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts( repoId, - stagingId ); + List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( stagingId ); - if ( log.isDebugEnabled() ) + if ( repoConfig.isReleases() && !repoConfig.isSnapshots() ) + { + log.info( "Repository to be merged contains releases only.." ); + if ( skipConflicts ) { - log.debug( "Artifacts in conflict.." ); - for ( ArtifactMetadata metadata : conflicts ) + List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts( + metadataRepository, repoId, stagingId ); + + if ( log.isDebugEnabled() ) { - log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":" + - metadata.getProjectVersion() ); + log.debug( "Artifacts in conflict.." ); + for ( ArtifactMetadata metadata : conflicts ) + { + log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":" + + metadata.getProjectVersion() ); + } } - } - sourceArtifacts.removeAll( conflicts ); + sourceArtifacts.removeAll( conflicts ); - log.debug( "Source artifacts size :: " + sourceArtifacts.size() ); - mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId ); + log.debug( "Source artifacts size :: " + sourceArtifacts.size() ); + mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId, null ); + } + else + { + log.debug( "Source artifacts size :: " + sourceArtifacts.size() ); + mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId, null ); + } } else { - log.debug( "Source artifacts size :: " + sourceArtifacts.size() ); - mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId ); - } - } - else - { - log.info( "Repository to be merged has snapshot artifacts.." ); - if ( skipConflicts ) - { - List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts( repoId, - stagingId ); - - if ( log.isDebugEnabled() ) + log.info( "Repository to be merged has snapshot artifacts.." ); + if ( skipConflicts ) { - log.debug( "Artifacts in conflict.." ); - for ( ArtifactMetadata metadata : conflicts ) + List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts( + metadataRepository, repoId, stagingId ); + + if ( log.isDebugEnabled() ) { - log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":" + - metadata.getProjectVersion() ); + log.debug( "Artifacts in conflict.." ); + for ( ArtifactMetadata metadata : conflicts ) + { + log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":" + + metadata.getProjectVersion() ); + } } - } - sourceArtifacts.removeAll( conflicts ); + sourceArtifacts.removeAll( conflicts ); - log.debug( "Source artifacts size :: " + sourceArtifacts.size() ); + log.debug( "Source artifacts size :: " + sourceArtifacts.size() ); - Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>( - sourceArtifacts ); - repositoryMerger.merge( stagingId, repoId, artifactsWithOutConflicts ); + Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>( + sourceArtifacts ); + repositoryMerger.merge( metadataRepository, stagingId, repoId, artifactsWithOutConflicts ); - log.info( - "Staging repository '" + stagingId + "' merged successfully with managed repo '" + repoId + - "'." ); - } - else - { - repositoryMerger.merge( stagingId, repoId ); + log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '" + + repoId + "'." ); + } + else + { + repositoryMerger.merge( metadataRepository, stagingId, repoId ); - log.info( - "Staging repository '" + stagingId + "' merged successfully with managed repo '" + repoId + - "'." ); + log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '" + + repoId + "'." ); + } } } + else + { + throw new Exception( "Staging Id : " + stagingId + " not found." ); + } } else { - throw new Exception( "Staging Id : " + stagingId + " not found." ); + throw new Exception( "Repository Id : " + repoId + " not found." ); } - } - else - { - throw new Exception( "Repository Id : " + repoId + " not found." ); - } - if ( !repositoryTaskScheduler.isProcessingRepositoryTask( repoId ) ) - { - RepositoryTask task = new RepositoryTask(); - task.setRepositoryId( repoId ); + if ( !repositoryTaskScheduler.isProcessingRepositoryTask( repoId ) ) + { + RepositoryTask task = new RepositoryTask(); + task.setRepositoryId( repoId ); - repositoryTaskScheduler.queueTask( task ); - } + repositoryTaskScheduler.queueTask( task ); + } - AuditEvent event = createAuditEvent( repoConfig ); + AuditEvent event = createAuditEvent( repoConfig ); - // add event for audit log reports - metadataRepository.addMetadataFacet( event.getRepositoryId(), event ); + // add event for audit log reports + metadataRepository.addMetadataFacet( event.getRepositoryId(), event ); - // log event in archiva audit log - auditListener.auditEvent( createAuditEvent( repoConfig ) ); + // log event in archiva audit log + auditListener.auditEvent( createAuditEvent( repoConfig ) ); + repositorySession.save(); + } + finally + { + repositorySession.close(); + } return true; } @@ -614,7 +642,8 @@ public class AdministrationServiceImpl return event; } - private void mergeWithOutSnapshots( List<ArtifactMetadata> sourceArtifacts, String sourceRepoId, String repoid ) + private void mergeWithOutSnapshots( List<ArtifactMetadata> sourceArtifacts, String sourceRepoId, String repoid, + MetadataRepository metadataRepository ) throws Exception { List<ArtifactMetadata> artifactsWithOutSnapshots = new ArrayList<ArtifactMetadata>(); @@ -631,7 +660,7 @@ public class AdministrationServiceImpl Filter<ArtifactMetadata> artifactListWithOutSnapShots = new IncludesFilter<ArtifactMetadata>( sourceArtifacts ); - repositoryMerger.merge( sourceRepoId, repoid, artifactListWithOutSnapShots ); + repositoryMerger.merge( metadataRepository, sourceRepoId, repoid, artifactListWithOutSnapShots ); } private ManagedRepositoryConfiguration getStageRepoConfig( ManagedRepositoryConfiguration repository ) diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java index 2f998f406..316fe6aac 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java @@ -29,6 +29,8 @@ 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.MetadataResolver; +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet; import org.apache.archiva.web.xmlrpc.api.SearchService; @@ -48,17 +50,14 @@ public class SearchServiceImpl private XmlRpcUserRepositories xmlRpcUserRepositories; - private MetadataResolver metadataResolver; + private RepositorySessionFactory repositorySessionFactory; - private MetadataRepository metadataRepository; - - public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, MetadataResolver metadataResolver, - MetadataRepository metadataRepository, RepositorySearch search ) + public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, + RepositorySessionFactory repositorySessionFactory, RepositorySearch search ) { this.xmlRpcUserRepositories = xmlRpcUserRepositories; this.search = search; - this.metadataResolver = metadataResolver; - this.metadataRepository = metadataRepository; + this.repositorySessionFactory = repositorySessionFactory; } @SuppressWarnings( "unchecked" ) @@ -72,45 +71,57 @@ public class SearchServiceImpl results = search.search( "", observableRepos, queryString, limits, null ); - for ( SearchResultHit resultHit : results.getHits() ) + RepositorySession repositorySession = repositorySessionFactory.createSession(); + try { - List<String> resultHitVersions = resultHit.getVersions(); - if ( resultHitVersions != null ) + MetadataResolver metadataResolver = repositorySession.getResolver(); + + for ( SearchResultHit resultHit : results.getHits() ) { - for ( String version : resultHitVersions ) + List<String> resultHitVersions = resultHit.getVersions(); + if ( resultHitVersions != null ) { - Artifact artifact = null; - for ( String repoId : observableRepos ) + for ( String version : resultHitVersions ) { - // slight behaviour change to previous implementation: instead of allocating "jar" when not - // found in the database, we can rely on the metadata repository to create it on the fly. We - // just allocate the default packaging if the Maven facet is not found. - FacetedMetadata model = metadataResolver.resolveProjectVersion( repoId, resultHit.getGroupId(), - resultHit.getArtifactId(), - version ); - - if ( model != null ) + Artifact artifact = null; + for ( String repoId : observableRepos ) { - String packaging = "jar"; - - MavenProjectFacet facet = (MavenProjectFacet) model.getFacet( MavenProjectFacet.FACET_ID ); - if ( facet != null && facet.getPackaging() != null ) + // slight behaviour change to previous implementation: instead of allocating "jar" when not + // found in the database, we can rely on the metadata repository to create it on the fly. We + // just allocate the default packaging if the Maven facet is not found. + FacetedMetadata model = metadataResolver.resolveProjectVersion( repositorySession, repoId, + resultHit.getGroupId(), + resultHit.getArtifactId(), + version ); + + if ( model != null ) { - packaging = facet.getPackaging(); + String packaging = "jar"; + + MavenProjectFacet facet = (MavenProjectFacet) model.getFacet( + MavenProjectFacet.FACET_ID ); + if ( facet != null && facet.getPackaging() != null ) + { + packaging = facet.getPackaging(); + } + artifact = new Artifact( repoId, resultHit.getGroupId(), resultHit.getArtifactId(), + version, packaging ); + break; } - artifact = new Artifact( repoId, resultHit.getGroupId(), resultHit.getArtifactId(), version, - packaging ); - break; } - } - if ( artifact != null ) - { - artifacts.add( artifact ); + if ( artifact != null ) + { + artifacts.add( artifact ); + } } } } } + finally + { + repositorySession.close(); + } return artifacts; } @@ -120,18 +131,30 @@ public class SearchServiceImpl { List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories(); + RepositorySession repositorySession = repositorySessionFactory.createSession(); + List<Artifact> results = new ArrayList<Artifact>(); - for ( String repoId : observableRepos ) + try { - for ( ArtifactMetadata artifact : metadataRepository.getArtifactsByChecksum( repoId, checksum ) ) + MetadataRepository metadataRepository = repositorySession.getRepository(); + + for ( String repoId : observableRepos ) { - // TODO: customise XMLRPC to handle non-Maven artifacts - MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet( MavenArtifactFacet.FACET_ID ); + for ( ArtifactMetadata artifact : metadataRepository.getArtifactsByChecksum( repoId, checksum ) ) + { + // TODO: customise XMLRPC to handle non-Maven artifacts + MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet( MavenArtifactFacet.FACET_ID ); - results.add( new Artifact( artifact.getRepositoryId(), artifact.getNamespace(), artifact.getProject(), - artifact.getVersion(), facet != null ? facet.getType() : null ) ); + results.add( new Artifact( artifact.getRepositoryId(), artifact.getNamespace(), + artifact.getProject(), artifact.getVersion(), + facet != null ? facet.getType() : null ) ); + } } } + finally + { + repositorySession.close(); + } return results; } @@ -141,17 +164,28 @@ public class SearchServiceImpl List<Artifact> artifacts = new ArrayList<Artifact>(); List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories(); - for ( String repoId : observableRepos ) + RepositorySession repositorySession = repositorySessionFactory.createSession(); + try { - Collection<String> results = metadataResolver.resolveProjectVersions( repoId, groupId, artifactId ); + MetadataResolver metadataResolver = repositorySession.getResolver(); - for ( final String version : results ) + for ( String repoId : observableRepos ) { - final Artifact artifact = new Artifact( repoId, groupId, artifactId, version, "pom" ); + Collection<String> results = metadataResolver.resolveProjectVersions( repositorySession, repoId, + groupId, artifactId ); - artifacts.add( artifact ); + for ( final String version : results ) + { + final Artifact artifact = new Artifact( repoId, groupId, artifactId, version, "pom" ); + + artifacts.add( artifact ); + } } } + finally + { + repositorySession.close(); + } return artifacts; } @@ -174,23 +208,33 @@ public class SearchServiceImpl { List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories(); - for ( String repoId : observableRepos ) + RepositorySession repositorySession = repositorySessionFactory.createSession(); + try { - ProjectVersionMetadata model = metadataResolver.resolveProjectVersion( repoId, groupId, artifactId, - version ); - if ( model != null ) + MetadataResolver metadataResolver = repositorySession.getResolver(); + + for ( String repoId : observableRepos ) { - List<Dependency> dependencies = new ArrayList<Dependency>(); - List<org.apache.archiva.metadata.model.Dependency> modelDeps = model.getDependencies(); - for ( org.apache.archiva.metadata.model.Dependency dep : modelDeps ) + ProjectVersionMetadata model = metadataResolver.resolveProjectVersion( repositorySession, repoId, + groupId, artifactId, version ); + if ( model != null ) { - Dependency dependency = new Dependency( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), - dep.getClassifier(), dep.getType(), dep.getScope() ); - dependencies.add( dependency ); + List<Dependency> dependencies = new ArrayList<Dependency>(); + List<org.apache.archiva.metadata.model.Dependency> modelDeps = model.getDependencies(); + for ( org.apache.archiva.metadata.model.Dependency dep : modelDeps ) + { + Dependency dependency = new Dependency( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), + dep.getClassifier(), dep.getType(), dep.getScope() ); + dependencies.add( dependency ); + } + return dependencies; } - return dependencies; } } + finally + { + repositorySession.close(); + } throw new Exception( "Artifact does not exist." ); } @@ -209,16 +253,28 @@ public class SearchServiceImpl List<Artifact> artifacts = new ArrayList<Artifact>(); List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories(); - for ( String repoId : observableRepos ) + RepositorySession repositorySession = repositorySessionFactory.createSession(); + try { - Collection<ProjectVersionReference> refs = metadataResolver.resolveProjectReferences( repoId, groupId, - artifactId, version ); - for ( ProjectVersionReference ref : refs ) + MetadataResolver metadataResolver = repositorySession.getResolver(); + + for ( String repoId : observableRepos ) { - artifacts.add( new Artifact( repoId, ref.getNamespace(), ref.getProjectId(), ref.getProjectVersion(), - "" ) ); + Collection<ProjectVersionReference> refs = metadataResolver.resolveProjectReferences( repositorySession, + repoId, groupId, + artifactId, + version ); + for ( ProjectVersionReference ref : refs ) + { + artifacts.add( new Artifact( repoId, ref.getNamespace(), ref.getProjectId(), + ref.getProjectVersion(), "" ) ); + } } } + finally + { + repositorySession.close(); + } return artifacts; } diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java index d4126351f..53620eb7b 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java @@ -23,6 +23,8 @@ import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.audit.AuditListener; import org.apache.archiva.metadata.model.ArtifactMetadata; 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.filter.Filter; import org.apache.archiva.metadata.repository.filter.IncludesFilter; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; @@ -63,6 +65,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * AdministrationServiceImplTest * @@ -162,6 +167,12 @@ public class AdministrationServiceImplTest metadataRepositoryControl = MockControl.createControl( MetadataRepository.class ); metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock(); + RepositorySession repositorySession = mock( RepositorySession.class ); + when( repositorySession.getRepository() ).thenReturn( metadataRepository ); + + RepositorySessionFactory repositorySessionFactory = mock( RepositorySessionFactory.class ); + when( repositorySessionFactory.createSession() ).thenReturn( repositorySession ); + listenerControl = MockControl.createControl( RepositoryListener.class ); listener = (RepositoryListener) listenerControl.getMock(); @@ -175,8 +186,9 @@ public class AdministrationServiceImplTest auditListener = (AuditListener) auditListenerControl.getMock(); service = new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, repositoryFactory, - metadataRepository, repositoryTaskScheduler, Collections.singletonList( - listener ), repositoryStatisticsManager, repositoryMerger, auditListener ); + repositorySessionFactory, repositoryTaskScheduler, + Collections.singletonList( listener ), repositoryStatisticsManager, + repositoryMerger, auditListener ); } /* Tests for repository consumers */ @@ -342,8 +354,8 @@ public class AdministrationServiceImplTest metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), artifact.getVersion(), artifact.getId() ); - listener.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), - artifact.getVersion(), artifact.getId() ); + listener.deleteArtifact( metadataRepository, repoContent.getId(), artifact.getNamespace(), + artifact.getProject(), artifact.getVersion(), artifact.getId() ); listenerControl.setVoidCallable( 1 ); archivaConfigControl.replay(); @@ -399,8 +411,8 @@ public class AdministrationServiceImplTest metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), artifact.getVersion(), artifact.getId() ); - listener.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), - artifact.getVersion(), artifact.getId() ); + listener.deleteArtifact( metadataRepository, repoContent.getId(), artifact.getNamespace(), + artifact.getProject(), artifact.getVersion(), artifact.getId() ); listenerControl.setVoidCallable( 1 ); archivaConfigControl.replay(); @@ -725,10 +737,11 @@ public class AdministrationServiceImplTest configControl.expectAndReturn( config.findManagedRepositoryById( "merge-stage" ), staging ); metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources ); - repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( staging.getId(), + repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( metadataRepository, + staging.getId(), merge.getId() ), sources ); - repositoryMerger.merge( staging.getId(), merge.getId() ); + repositoryMerger.merge( metadataRepository, staging.getId(), merge.getId() ); repositoryMergerControl.setVoidCallable(); repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "merge" ), false ); @@ -794,10 +807,11 @@ public class AdministrationServiceImplTest configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), staging ); metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources ); - repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( staging.getId(), + repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( metadataRepository, + staging.getId(), repo.getId() ), conflicts ); - repositoryMerger.merge( staging.getId(), repo.getId(), artifactsWithOutConflicts ); + repositoryMerger.merge( metadataRepository, staging.getId(), repo.getId(), artifactsWithOutConflicts ); repositoryMergerControl.setMatcher( MockControl.ALWAYS_MATCHER ); repositoryMergerControl.setVoidCallable(); repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "repo" ), diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java index 7c224cf99..883e07375 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java @@ -30,6 +30,8 @@ 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.MetadataResolver; +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet; import org.apache.archiva.web.xmlrpc.api.SearchService; @@ -46,6 +48,9 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * SearchServiceImplTest * @@ -80,6 +85,8 @@ public class SearchServiceImplTest private static final String TEST_REPO = "test-repo"; + private RepositorySession repositorySession; + @Override public void setUp() throws Exception @@ -97,7 +104,13 @@ public class SearchServiceImplTest metadataRepositoryControl = MockControl.createControl( MetadataRepository.class ); metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock(); - searchService = new SearchServiceImpl( userRepos, metadataResolver, metadataRepository, search ); + repositorySession = mock( RepositorySession.class ); + when( repositorySession.getResolver() ).thenReturn( metadataResolver ); + when( repositorySession.getRepository() ).thenReturn( metadataRepository ); + RepositorySessionFactory repositorySessionFactory = mock( RepositorySessionFactory.class ); + when( repositorySessionFactory.createSession() ).thenReturn( repositorySession ); + + searchService = new SearchServiceImpl( userRepos, repositorySessionFactory, search ); } // MRM-1230 @@ -134,7 +147,8 @@ public class SearchServiceImplTest facet.setPackaging( "war" ); model.addFacet( facet ); - metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( "repo1.mirror", + metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( repositorySession, + "repo1.mirror", ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ), model ); @@ -189,14 +203,16 @@ public class SearchServiceImplTest searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), results ); - metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( "repo1.mirror", + metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( repositorySession, + "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), null ); ProjectVersionMetadata model = new ProjectVersionMetadata(); model.setId( "1.0" ); - metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( "public.releases", + metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( repositorySession, + "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), model ); @@ -256,7 +272,8 @@ public class SearchServiceImplTest facet.setPackaging( "jar" ); model.addFacet( facet ); - metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( "repo1.mirror", + metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( repositorySession, + "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), model ); @@ -349,11 +366,13 @@ public class SearchServiceImplTest observableRepoIds.add( "public.releases" ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); - metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersions( "repo1.mirror", + metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersions( repositorySession, + "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID ), Arrays.asList( "1.0", "1.1-beta-2", "1.2" ) ); - metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersions( "public.releases", + metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersions( repositorySession, + "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID ), Arrays.asList( "1.1-beta-1", "1.1", "1.2.1-SNAPSHOT" ) ); @@ -418,7 +437,8 @@ public class SearchServiceImplTest model.addDependency( dependency ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), Collections.singletonList( repoId ) ); - metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( repoId, ARCHIVA_TEST_GROUP_ID, + metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( repositorySession, repoId, + ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), model ); @@ -444,7 +464,8 @@ public class SearchServiceImplTest String repoId = "repo1.mirror"; userReposControl.expectAndReturn( userRepos.getObservableRepositories(), Collections.singletonList( repoId ) ); - metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( repoId, ARCHIVA_TEST_GROUP_ID, + metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( repositorySession, repoId, + ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), null ); @@ -498,7 +519,7 @@ public class SearchServiceImplTest dependeeModels.add( dependeeModel ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); - metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectReferences( repoId, + metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectReferences( repositorySession, repoId, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), dependeeModels ); @@ -529,12 +550,14 @@ public class SearchServiceImplTest // no longer differentiating between a project not being present and a project that is present but with // no references. If it is later determined to be needed, we will need to modify the metadata content repository userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); - metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectReferences( "repo1.mirror", + metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectReferences( repositorySession, + "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), Collections.<ProjectVersionReference>emptyList() ); - metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectReferences( "public.releases", + metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectReferences( repositorySession, + "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), |