aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2009-11-30 03:10:40 +0000
committerBrett Porter <brett@apache.org>2009-11-30 03:10:40 +0000
commitd6c5ea064e90818d7a27ff00b68cf262371a8b74 (patch)
treea8b7752d133d895b5eebc91e32f6882eadd5b053 /archiva-modules
parent0caebfc6b621579481aca223a76e24be0be9f0c3 (diff)
downloadarchiva-d6c5ea064e90818d7a27ff00b68cf262371a8b74.tar.gz
archiva-d6c5ea064e90818d7a27ff00b68cf262371a8b74.zip
[MRM-1288] migrate getDependees() to new API
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@885319 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java49
-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.java23
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java77
4 files changed, 106 insertions, 47 deletions
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java
index 7c1176cac..8ea155574 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java
@@ -45,6 +45,55 @@ public class Artifact
}
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() )
+ {
+ return false;
+ }
+
+ Artifact artifact = (Artifact) o;
+
+ if ( !artifactId.equals( artifact.artifactId ) )
+ {
+ return false;
+ }
+ if ( !groupId.equals( artifact.groupId ) )
+ {
+ return false;
+ }
+ if ( !repositoryId.equals( artifact.repositoryId ) )
+ {
+ return false;
+ }
+ if ( type != null ? !type.equals( artifact.type ) : artifact.type != null )
+ {
+ return false;
+ }
+ if ( !version.equals( artifact.version ) )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = repositoryId.hashCode();
+ result = 31 * result + groupId.hashCode();
+ result = 31 * result + artifactId.hashCode();
+ result = 31 * result + version.hashCode();
+ result = 31 * result + ( type != null ? type.hashCode() : 0 );
+ return result;
+ }
+
public Artifact( String repositoryId, String groupId, String artifactId, String version, String type )
// String type, Date whenGathered )
{
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 d960bdab9..97687d330 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
@@ -67,6 +67,10 @@
<artifactId>archiva-security</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>metadata-repository-api</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 30d819100..3f91f6849 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
@@ -20,6 +20,7 @@ package org.apache.archiva.web.xmlrpc.services;
*/
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -27,6 +28,8 @@ import org.apache.archiva.indexer.search.RepositorySearch;
import org.apache.archiva.indexer.search.SearchResultHit;
import org.apache.archiva.indexer.search.SearchResultLimits;
import org.apache.archiva.indexer.search.SearchResults;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
+import org.apache.archiva.metadata.repository.MetadataResolver;
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;
@@ -71,13 +74,17 @@ public class SearchServiceImpl
private RepositoryBrowsing repoBrowsing;
+ private MetadataResolver metadataResolver;
+
public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO,
- RepositoryBrowsing repoBrowsing, RepositorySearch search )
+ RepositoryBrowsing repoBrowsing, MetadataResolver metadataResolver,
+ RepositorySearch search )
{
this.xmlRpcUserRepositories = xmlRpcUserRepositories;
this.archivaDAO = archivaDAO;
this.repoBrowsing = repoBrowsing;
this.search = search;
+ this.metadataResolver = metadataResolver;
}
@SuppressWarnings("unchecked")
@@ -263,13 +270,15 @@ public class SearchServiceImpl
List<Artifact> artifacts = new ArrayList<Artifact>();
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
- List<ArchivaProjectModel> dependees =
- repoBrowsing.getUsedBy( "", observableRepos, groupId, artifactId, version );
- for ( ArchivaProjectModel model : dependees )
+ for ( String repoId : observableRepos )
{
- Artifact artifact = new Artifact( "", model.getGroupId(), model.getArtifactId(), model.getVersion(), "" );
- //model.getWhenIndexed() );
- artifacts.add( artifact );
+ Collection<ProjectVersionReference> refs =
+ metadataResolver.getProjectReferences( repoId, groupId, artifactId, version );
+ for ( ProjectVersionReference ref : refs )
+ {
+ artifacts.add(
+ new Artifact( repoId, ref.getNamespace(), ref.getProjectId(), ref.getProjectVersion(), "" ) );
+ }
}
return artifacts;
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 8ef4b076d..062aaf2af 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
@@ -29,6 +29,8 @@ import org.apache.archiva.indexer.search.SearchResultHit;
import org.apache.archiva.indexer.search.SearchResultLimits;
import org.apache.archiva.indexer.search.SearchResults;
import org.apache.archiva.indexer.util.SearchUtil;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
+import org.apache.archiva.metadata.repository.MetadataResolver;
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;
@@ -80,6 +82,10 @@ public class SearchServiceImplTest
private static final String ARCHIVA_TEST_GROUP_ID = "org.apache.archiva";
+ private MockControl metadataResolverControl;
+
+ private MetadataResolver metadataResolver;
+
@Override
public void setUp()
throws Exception
@@ -98,7 +104,10 @@ public class SearchServiceImplTest
searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
search = (RepositorySearch) searchControl.getMock();
- searchService = new SearchServiceImpl( userRepos, archivaDAO, repoBrowsing, search );
+ 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();
@@ -624,41 +633,42 @@ public class SearchServiceImplTest
public void testGetDependees()
throws Exception
{
- Date date = new Date();
List<String> observableRepoIds = new ArrayList<String>();
- observableRepoIds.add( "repo1.mirror" );
- observableRepoIds.add( "public.releases" );
-
- List<ArchivaProjectModel> dependeeModels = new ArrayList<ArchivaProjectModel>();
- ArchivaProjectModel dependeeModel = new ArchivaProjectModel();
- dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
- dependeeModel.setArtifactId( "archiva-dependee-one" );
- dependeeModel.setVersion( "1.0" );
- dependeeModel.setWhenIndexed( date );
+ String repoId = "repo1.mirror";
+ observableRepoIds.add( repoId );
+
+ List<ProjectVersionReference> dependeeModels = new ArrayList<ProjectVersionReference>();
+ ProjectVersionReference dependeeModel = new ProjectVersionReference();
+ dependeeModel.setNamespace( ARCHIVA_TEST_GROUP_ID );
+ dependeeModel.setProjectId( "archiva-dependee-one" );
+ dependeeModel.setProjectVersion( "1.0" );
dependeeModels.add( dependeeModel );
- dependeeModel = new ArchivaProjectModel();
- dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
- dependeeModel.setArtifactId( "archiva-dependee-two" );
- dependeeModel.setVersion( "1.0" );
- dependeeModel.setWhenIndexed( date );
+ dependeeModel = new ProjectVersionReference();
+ dependeeModel.setNamespace( ARCHIVA_TEST_GROUP_ID );
+ dependeeModel.setProjectId( "archiva-dependee-two" );
+ dependeeModel.setProjectVersion( "1.0" );
dependeeModels.add( dependeeModel );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
- repoBrowsingControl.expectAndReturn(
- repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
+ metadataResolverControl.expectAndReturn(
+ metadataResolver.getProjectReferences( repoId, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
dependeeModels );
- repoBrowsingControl.replay();
+ metadataResolverControl.replay();
userReposControl.replay();
List<Artifact> dependees = searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
- repoBrowsingControl.verify();
+ metadataResolverControl.verify();
userReposControl.verify();
assertNotNull( dependees );
assertEquals( 2, dependees.size() );
+ assertEquals( new Artifact( repoId, ARCHIVA_TEST_GROUP_ID, "archiva-dependee-one", "1.0", "" ),
+ dependees.get( 0 ) );
+ assertEquals( new Artifact( repoId, ARCHIVA_TEST_GROUP_ID, "archiva-dependee-two", "1.0", "" ),
+ dependees.get( 1 ) );
}
public void testGetDependeesArtifactDoesNotExist()
@@ -669,33 +679,20 @@ public class SearchServiceImplTest
observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" );
- List dependeeModels = new ArrayList();
- ArchivaProjectModel dependeeModel = new ArchivaProjectModel();
- dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
- dependeeModel.setArtifactId( "archiva-dependee-one" );
- dependeeModel.setVersion( "1.0" );
- dependeeModel.setWhenIndexed( date );
- dependeeModels.add( dependeeModel );
-
- dependeeModel = new ArchivaProjectModel();
- dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
- dependeeModel.setArtifactId( "archiva-dependee-two" );
- dependeeModel.setVersion( "1.0" );
- dependeeModel.setWhenIndexed( date );
- dependeeModels.add( dependeeModel );
-
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
- repoBrowsingControl.expectAndReturn(
- repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
- null );
+ metadataResolverControl.expectAndReturn(
+ metadataResolver.getProjectReferences( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
+ "1.0" ), null );
+ metadataResolverControl.expectAndReturn(
+ metadataResolver.getProjectReferences( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
+ "1.0" ), null );
repoBrowsingControl.replay();
userReposControl.replay();
try
{
- List<Artifact> dependees =
- searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
+ searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
fail( "An exception should have been thrown." );
}
catch ( Exception e )