mirror of https://github.com/apache/archiva.git
[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
This commit is contained in:
parent
0caebfc6b6
commit
d6c5ea064e
|
@ -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 )
|
public Artifact( String repositoryId, String groupId, String artifactId, String version, String type )
|
||||||
// String type, Date whenGathered )
|
// String type, Date whenGathered )
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,6 +66,10 @@
|
||||||
<groupId>org.apache.archiva</groupId>
|
<groupId>org.apache.archiva</groupId>
|
||||||
<artifactId>archiva-security</artifactId>
|
<artifactId>archiva-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.archiva</groupId>
|
||||||
|
<artifactId>metadata-repository-api</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.plexus</groupId>
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
<artifactId>plexus-spring</artifactId>
|
<artifactId>plexus-spring</artifactId>
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.archiva.web.xmlrpc.services;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
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.SearchResultHit;
|
||||||
import org.apache.archiva.indexer.search.SearchResultLimits;
|
import org.apache.archiva.indexer.search.SearchResultLimits;
|
||||||
import org.apache.archiva.indexer.search.SearchResults;
|
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.SearchService;
|
||||||
import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
|
import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
|
||||||
import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
|
import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
|
||||||
|
@ -71,13 +74,17 @@ public class SearchServiceImpl
|
||||||
|
|
||||||
private RepositoryBrowsing repoBrowsing;
|
private RepositoryBrowsing repoBrowsing;
|
||||||
|
|
||||||
|
private MetadataResolver metadataResolver;
|
||||||
|
|
||||||
public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO,
|
public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO,
|
||||||
RepositoryBrowsing repoBrowsing, RepositorySearch search )
|
RepositoryBrowsing repoBrowsing, MetadataResolver metadataResolver,
|
||||||
|
RepositorySearch search )
|
||||||
{
|
{
|
||||||
this.xmlRpcUserRepositories = xmlRpcUserRepositories;
|
this.xmlRpcUserRepositories = xmlRpcUserRepositories;
|
||||||
this.archivaDAO = archivaDAO;
|
this.archivaDAO = archivaDAO;
|
||||||
this.repoBrowsing = repoBrowsing;
|
this.repoBrowsing = repoBrowsing;
|
||||||
this.search = search;
|
this.search = search;
|
||||||
|
this.metadataResolver = metadataResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -263,13 +270,15 @@ public class SearchServiceImpl
|
||||||
List<Artifact> artifacts = new ArrayList<Artifact>();
|
List<Artifact> artifacts = new ArrayList<Artifact>();
|
||||||
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
|
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
|
||||||
|
|
||||||
List<ArchivaProjectModel> dependees =
|
for ( String repoId : observableRepos )
|
||||||
repoBrowsing.getUsedBy( "", observableRepos, groupId, artifactId, version );
|
|
||||||
for ( ArchivaProjectModel model : dependees )
|
|
||||||
{
|
{
|
||||||
Artifact artifact = new Artifact( "", model.getGroupId(), model.getArtifactId(), model.getVersion(), "" );
|
Collection<ProjectVersionReference> refs =
|
||||||
//model.getWhenIndexed() );
|
metadataResolver.getProjectReferences( repoId, groupId, artifactId, version );
|
||||||
artifacts.add( artifact );
|
for ( ProjectVersionReference ref : refs )
|
||||||
|
{
|
||||||
|
artifacts.add(
|
||||||
|
new Artifact( repoId, ref.getNamespace(), ref.getProjectId(), ref.getProjectVersion(), "" ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return artifacts;
|
return artifacts;
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.apache.archiva.indexer.search.SearchResultHit;
|
||||||
import org.apache.archiva.indexer.search.SearchResultLimits;
|
import org.apache.archiva.indexer.search.SearchResultLimits;
|
||||||
import org.apache.archiva.indexer.search.SearchResults;
|
import org.apache.archiva.indexer.search.SearchResults;
|
||||||
import org.apache.archiva.indexer.util.SearchUtil;
|
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.SearchService;
|
||||||
import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
|
import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
|
||||||
import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
|
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 static final String ARCHIVA_TEST_GROUP_ID = "org.apache.archiva";
|
||||||
|
|
||||||
|
private MockControl metadataResolverControl;
|
||||||
|
|
||||||
|
private MetadataResolver metadataResolver;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp()
|
public void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -98,7 +104,10 @@ public class SearchServiceImplTest
|
||||||
searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
|
searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
|
||||||
search = (RepositorySearch) searchControl.getMock();
|
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 );
|
artifactDAOControl = MockControl.createControl( ArtifactDAO.class );
|
||||||
artifactDAO = (ArtifactDAO) artifactDAOControl.getMock();
|
artifactDAO = (ArtifactDAO) artifactDAOControl.getMock();
|
||||||
|
@ -624,41 +633,42 @@ public class SearchServiceImplTest
|
||||||
public void testGetDependees()
|
public void testGetDependees()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
Date date = new Date();
|
|
||||||
List<String> observableRepoIds = new ArrayList<String>();
|
List<String> observableRepoIds = new ArrayList<String>();
|
||||||
observableRepoIds.add( "repo1.mirror" );
|
String repoId = "repo1.mirror";
|
||||||
observableRepoIds.add( "public.releases" );
|
observableRepoIds.add( repoId );
|
||||||
|
|
||||||
List<ArchivaProjectModel> dependeeModels = new ArrayList<ArchivaProjectModel>();
|
List<ProjectVersionReference> dependeeModels = new ArrayList<ProjectVersionReference>();
|
||||||
ArchivaProjectModel dependeeModel = new ArchivaProjectModel();
|
ProjectVersionReference dependeeModel = new ProjectVersionReference();
|
||||||
dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
|
dependeeModel.setNamespace( ARCHIVA_TEST_GROUP_ID );
|
||||||
dependeeModel.setArtifactId( "archiva-dependee-one" );
|
dependeeModel.setProjectId( "archiva-dependee-one" );
|
||||||
dependeeModel.setVersion( "1.0" );
|
dependeeModel.setProjectVersion( "1.0" );
|
||||||
dependeeModel.setWhenIndexed( date );
|
|
||||||
dependeeModels.add( dependeeModel );
|
dependeeModels.add( dependeeModel );
|
||||||
|
|
||||||
dependeeModel = new ArchivaProjectModel();
|
dependeeModel = new ProjectVersionReference();
|
||||||
dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
|
dependeeModel.setNamespace( ARCHIVA_TEST_GROUP_ID );
|
||||||
dependeeModel.setArtifactId( "archiva-dependee-two" );
|
dependeeModel.setProjectId( "archiva-dependee-two" );
|
||||||
dependeeModel.setVersion( "1.0" );
|
dependeeModel.setProjectVersion( "1.0" );
|
||||||
dependeeModel.setWhenIndexed( date );
|
|
||||||
dependeeModels.add( dependeeModel );
|
dependeeModels.add( dependeeModel );
|
||||||
|
|
||||||
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
|
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
|
||||||
repoBrowsingControl.expectAndReturn(
|
metadataResolverControl.expectAndReturn(
|
||||||
repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
|
metadataResolver.getProjectReferences( repoId, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
|
||||||
dependeeModels );
|
dependeeModels );
|
||||||
|
|
||||||
repoBrowsingControl.replay();
|
metadataResolverControl.replay();
|
||||||
userReposControl.replay();
|
userReposControl.replay();
|
||||||
|
|
||||||
List<Artifact> dependees = searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
|
List<Artifact> dependees = searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
|
||||||
|
|
||||||
repoBrowsingControl.verify();
|
metadataResolverControl.verify();
|
||||||
userReposControl.verify();
|
userReposControl.verify();
|
||||||
|
|
||||||
assertNotNull( dependees );
|
assertNotNull( dependees );
|
||||||
assertEquals( 2, dependees.size() );
|
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()
|
public void testGetDependeesArtifactDoesNotExist()
|
||||||
|
@ -669,33 +679,20 @@ public class SearchServiceImplTest
|
||||||
observableRepoIds.add( "repo1.mirror" );
|
observableRepoIds.add( "repo1.mirror" );
|
||||||
observableRepoIds.add( "public.releases" );
|
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 );
|
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
|
||||||
repoBrowsingControl.expectAndReturn(
|
metadataResolverControl.expectAndReturn(
|
||||||
repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
|
metadataResolver.getProjectReferences( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
|
||||||
null );
|
"1.0" ), null );
|
||||||
|
metadataResolverControl.expectAndReturn(
|
||||||
|
metadataResolver.getProjectReferences( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
|
||||||
|
"1.0" ), null );
|
||||||
|
|
||||||
repoBrowsingControl.replay();
|
repoBrowsingControl.replay();
|
||||||
userReposControl.replay();
|
userReposControl.replay();
|
||||||
|
|
||||||
try
|
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." );
|
fail( "An exception should have been thrown." );
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
|
|
Loading…
Reference in New Issue