summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2009-11-30 14:19:56 +0000
committerBrett Porter <brett@apache.org>2009-11-30 14:19:56 +0000
commit3278cdc8ae95cc9c59f431bec145d9a01b2cf014 (patch)
tree4bb41ab5ae8721e1e6d590d05b0a4123b937eead
parentbfc001b7e1dcd0c983219e301c2b98b00908f4e3 (diff)
downloadarchiva-3278cdc8ae95cc9c59f431bec145d9a01b2cf014.tar.gz
archiva-3278cdc8ae95cc9c59f431bec145d9a01b2cf014.zip
[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
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml2
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml4
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java56
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java80
-rw-r--r--pom.xml5
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 @@
<bean name="searchService" lazy-init="true" scope="singleton" class="org.apache.archiva.web.xmlrpc.services.SearchServiceImpl">
<constructor-arg ref="xmlRpcUserRepositories"/>
<constructor-arg ref="archivaDAO#jdo"/>
- <constructor-arg ref="repositoryBrowsing"/>
+ <constructor-arg ref="metadataResolver"/>
<constructor-arg ref="nexusSearch"/>
</bean>
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
@@ -71,6 +71,10 @@
<artifactId>metadata-repository-api</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>maven2-repository</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-spring</artifactId>
<scope>test</scope>
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,35 +107,34 @@ 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 );
-
- String repoId = repoBrowsing.getRepositoryId( "", observableRepos, resultHit.getGroupId(),
- resultHit.getArtifactId(), version );
-
- Artifact artifact = null;
- if ( model == 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.
+ ProjectVersionMetadata model =
+ metadataResolver.getProjectVersion( repoId, resultHit.getGroupId(),
+ resultHit.getArtifactId(), version );
+
+ 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;
}
- artifacts.add( artifact );
- }
- catch ( ObjectNotFoundException e )
- {
- log.debug( "Unable to find pom artifact : " + e.getMessage() );
}
- catch ( ArchivaDatabaseException e )
+
+ if ( artifact != null )
{
- log.debug( "Error occurred while getting pom artifact from database : " + e.getMessage() );
+ artifacts.add( artifact );
}
}
}
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<Artifact> 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<Artifact> 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" );
-
- repoBrowsingControl.expectAndReturn(
- repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
- model );
+ ProjectVersionMetadata model = new ProjectVersionMetadata();
+ model.setId( "1.0" );
+ MavenProjectFacet facet = new MavenProjectFacet();
+ facet.setPackaging( "jar" );
+ model.addFacet( facet );
- 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<Artifact> 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
@@ -305,6 +305,11 @@
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
+ <artifactId>maven2-repository</artifactId>
+ <version>1.3-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
<artifactId>archiva-applet</artifactId>
<version>1.3-SNAPSHOT</version>
</dependency>