From 3278cdc8ae95cc9c59f431bec145d9a01b2cf014 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Mon, 30 Nov 2009 14:19:56 +0000 Subject: [PATCH] [MRM-1288] move quickSearch from repository browsing to metadata content repository API git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@885430 13f79535-47bb-0310-9956-ffa450edef68 --- .../webapp/WEB-INF/applicationContext.xml | 2 +- .../archiva-xmlrpc-services/pom.xml | 4 + .../xmlrpc/services/SearchServiceImpl.java | 56 ++++++------- .../services/SearchServiceImplTest.java | 80 ++++++++----------- pom.xml | 5 ++ 5 files changed, 67 insertions(+), 80 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml index 492d422d8..314fda406 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml @@ -43,7 +43,7 @@ - + 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 97687d330..c332556dc 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 @@ -70,6 +70,10 @@ org.apache.archiva metadata-repository-api + + org.apache.archiva + maven2-repository + org.codehaus.plexus plexus-spring 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 473c97ddb..a9f3cccec 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 @@ -31,20 +31,17 @@ import org.apache.archiva.indexer.search.SearchResults; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.repository.MetadataResolver; +import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet; import org.apache.archiva.web.xmlrpc.api.SearchService; import org.apache.archiva.web.xmlrpc.api.beans.Artifact; import org.apache.archiva.web.xmlrpc.api.beans.Dependency; import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories; import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.database.ArchivaDAO; -import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.maven.archiva.database.ObjectNotFoundException; -import org.apache.maven.archiva.database.browsing.RepositoryBrowsing; import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint; import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; import org.apache.maven.archiva.model.ArchivaArtifact; -import org.apache.maven.archiva.model.ArchivaProjectModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -72,17 +69,13 @@ public class SearchServiceImpl private ArchivaDAO archivaDAO; - private RepositoryBrowsing repoBrowsing; - private MetadataResolver metadataResolver; public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO, - RepositoryBrowsing repoBrowsing, MetadataResolver metadataResolver, - RepositorySearch search ) + MetadataResolver metadataResolver, RepositorySearch search ) { this.xmlRpcUserRepositories = xmlRpcUserRepositories; this.archivaDAO = archivaDAO; - this.repoBrowsing = repoBrowsing; this.search = search; this.metadataResolver = metadataResolver; } @@ -114,36 +107,35 @@ public class SearchServiceImpl { for ( String version : resultHitVersions ) { - try + Artifact artifact = null; + for ( String repoId : observableRepos ) { - ArchivaProjectModel model = - repoBrowsing.selectVersion( "", observableRepos, resultHit.getGroupId(), - resultHit.getArtifactId(), version ); + // 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. + ProjectVersionMetadata model = + metadataResolver.getProjectVersion( repoId, resultHit.getGroupId(), + resultHit.getArtifactId(), version ); - String repoId = repoBrowsing.getRepositoryId( "", observableRepos, resultHit.getGroupId(), - resultHit.getArtifactId(), version ); - - Artifact artifact = null; - if ( model == null ) + if ( model != null ) { + 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, - "jar" ); - } - else - { - artifact = new Artifact( repoId, model.getGroupId(), model.getArtifactId(), version, - model.getPackaging() ); + packaging ); + break; } + } + + if ( artifact != null ) + { artifacts.add( artifact ); } - catch ( ObjectNotFoundException e ) - { - log.debug( "Unable to find pom artifact : " + e.getMessage() ); - } - catch ( ArchivaDatabaseException e ) - { - log.debug( "Error occurred while getting pom artifact from database : " + e.getMessage() ); - } } } } 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 a677b811d..1ba94877c 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 @@ -34,13 +34,13 @@ import org.apache.archiva.indexer.util.SearchUtil; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.repository.MetadataResolver; +import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet; import org.apache.archiva.web.xmlrpc.api.SearchService; import org.apache.archiva.web.xmlrpc.api.beans.Artifact; import org.apache.archiva.web.xmlrpc.api.beans.Dependency; import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories; import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.maven.archiva.database.browsing.RepositoryBrowsing; import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint; import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; import org.apache.maven.archiva.model.ArchivaArtifact; @@ -75,10 +75,6 @@ public class SearchServiceImplTest private ArtifactDAO artifactDAO; - private MockControl repoBrowsingControl; - - private RepositoryBrowsing repoBrowsing; - private static final String ARCHIVA_TEST_ARTIFACT_ID = "archiva-xmlrpc-test"; private static final String ARCHIVA_TEST_GROUP_ID = "org.apache.archiva"; @@ -98,9 +94,6 @@ public class SearchServiceImplTest archivaDAOControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); archivaDAO = (ArchivaDAO) archivaDAOControl.getMock(); - repoBrowsingControl = MockControl.createControl( RepositoryBrowsing.class ); - repoBrowsing = (RepositoryBrowsing) repoBrowsingControl.getMock(); - searchControl = MockControl.createControl( RepositorySearch.class ); searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); search = (RepositorySearch) searchControl.getMock(); @@ -108,10 +101,10 @@ public class SearchServiceImplTest metadataResolverControl = MockControl.createControl( MetadataResolver.class ); metadataResolver = (MetadataResolver) metadataResolverControl.getMock(); - searchService = new SearchServiceImpl( userRepos, archivaDAO, repoBrowsing, metadataResolver, search ); - artifactDAOControl = MockControl.createControl( ArtifactDAO.class ); artifactDAO = (ArtifactDAO) artifactDAOControl.getMock(); + + searchService = new SearchServiceImpl( userRepos, archivaDAO, metadataResolver, search ); } // MRM-1230 @@ -145,30 +138,26 @@ public class SearchServiceImplTest new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ), null ); - ArchivaProjectModel model = new ArchivaProjectModel(); - model.setGroupId( ARCHIVA_TEST_GROUP_ID ); - model.setArtifactId( "archiva-webapp" ); - model.setVersion( "1.0" ); - model.setPackaging( "war" ); + ProjectVersionMetadata model = new ProjectVersionMetadata(); + model.setId( "1.0" ); + MavenProjectFacet facet = new MavenProjectFacet(); + facet.setPackaging( "war" ); + model.addFacet( facet ); - repoBrowsingControl.expectAndReturn( - repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ), + metadataResolverControl.expectAndReturn( + metadataResolver.getProjectVersion( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ), model ); - repoBrowsingControl.expectAndReturn( - repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ), - "repo1.mirror" ); - userReposControl.replay(); searchControl.replay(); - repoBrowsingControl.replay(); + metadataResolverControl.replay(); archivaDAOControl.replay(); List artifacts = searchService.quickSearch( "archiva" ); userReposControl.verify(); searchControl.verify(); - repoBrowsingControl.verify(); + metadataResolverControl.verify(); archivaDAOControl.verify(); assertNotNull( artifacts ); @@ -213,24 +202,26 @@ public class SearchServiceImplTest new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ), null ); - repoBrowsingControl.expectAndReturn( - repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), - null ); + metadataResolverControl.expectAndReturn( + metadataResolver.getProjectVersion( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, + "1.0" ), null ); - repoBrowsingControl.expectAndReturn( - repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, - "1.0" ), null ); + ProjectVersionMetadata model = new ProjectVersionMetadata(); + model.setId( "1.0" ); + metadataResolverControl.expectAndReturn( + metadataResolver.getProjectVersion( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, + "1.0" ), model ); userReposControl.replay(); searchControl.replay(); - repoBrowsingControl.replay(); + metadataResolverControl.replay(); archivaDAOControl.replay(); List artifacts = searchService.quickSearch( "archiva" ); userReposControl.verify(); searchControl.verify(); - repoBrowsingControl.verify(); + metadataResolverControl.verify(); archivaDAOControl.verify(); assertNotNull( artifacts ); @@ -241,8 +232,7 @@ public class SearchServiceImplTest assertEquals( ARCHIVA_TEST_ARTIFACT_ID, artifact.getArtifactId() ); assertEquals( "1.0", artifact.getVersion() ); assertEquals( "jar", artifact.getType() ); - assertNull( "Repository should be null since the model was not found in the database!", - artifact.getRepositoryId() ); + assertEquals( "public.releases", artifact.getRepositoryId() ); } public void testQuickSearchArtifactRegularSearch() @@ -275,31 +265,27 @@ public class SearchServiceImplTest searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), results ); - ArchivaProjectModel model = new ArchivaProjectModel(); - model.setGroupId( ARCHIVA_TEST_GROUP_ID ); - model.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID ); - model.setVersion( "1.0" ); - model.setPackaging( "jar" ); + ProjectVersionMetadata model = new ProjectVersionMetadata(); + model.setId( "1.0" ); + MavenProjectFacet facet = new MavenProjectFacet(); + facet.setPackaging( "jar" ); + model.addFacet( facet ); - repoBrowsingControl.expectAndReturn( - repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), - model ); - - repoBrowsingControl.expectAndReturn( - repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, - "1.0" ), "repo1.mirror" ); + metadataResolverControl.expectAndReturn( + metadataResolver.getProjectVersion( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, + "1.0" ), model ); userReposControl.replay(); searchControl.replay(); archivaDAOControl.replay(); - repoBrowsingControl.replay(); + metadataResolverControl.replay(); List artifacts = searchService.quickSearch( "archiva" ); userReposControl.verify(); searchControl.verify(); archivaDAOControl.verify(); - repoBrowsingControl.verify(); + metadataResolverControl.verify(); assertNotNull( artifacts ); assertEquals( 1, artifacts.size() ); diff --git a/pom.xml b/pom.xml index 2a72ef0c3..238691eb0 100644 --- a/pom.xml +++ b/pom.xml @@ -303,6 +303,11 @@ metadata-repository-file 1.3-SNAPSHOT + + org.apache.archiva + maven2-repository + 1.3-SNAPSHOT + org.apache.archiva archiva-applet