[MRM-1288] move getDependencies() method to new repository API

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@885328 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-11-30 03:50:51 +00:00
parent 711db6f5af
commit 2ca1b79844
3 changed files with 100 additions and 41 deletions

View File

@ -39,6 +39,68 @@ public class Dependency
private String scope; private String scope;
@Override
public String toString()
{
return "Dependency{" + "groupId='" + groupId + '\'' + ", artifactId='" + artifactId + '\'' + ", version='" +
version + '\'' + ", classifier='" + classifier + '\'' + ", type='" + type + '\'' + ", scope='" + scope +
'\'' + '}';
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
Dependency that = (Dependency) o;
if ( !artifactId.equals( that.artifactId ) )
{
return false;
}
if ( classifier != null ? !classifier.equals( that.classifier ) : that.classifier != null )
{
return false;
}
if ( !groupId.equals( that.groupId ) )
{
return false;
}
if ( scope != null ? !scope.equals( that.scope ) : that.scope != null )
{
return false;
}
if ( type != null ? !type.equals( that.type ) : that.type != null )
{
return false;
}
if ( !version.equals( that.version ) )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
int result = groupId.hashCode();
result = 31 * result + artifactId.hashCode();
result = 31 * result + version.hashCode();
result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 );
result = 31 * result + ( type != null ? type.hashCode() : 0 );
result = 31 * result + ( scope != null ? scope.hashCode() : 0 );
return result;
}
public Dependency( String groupId, String artifactId, String version, String classifier, String type, String scope ) public Dependency( String groupId, String artifactId, String version, String classifier, String type, String scope )
{ {
this.groupId = groupId; this.groupId = groupId;

View File

@ -28,6 +28,7 @@ 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.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.web.xmlrpc.api.SearchService; import org.apache.archiva.web.xmlrpc.api.SearchService;
@ -232,28 +233,27 @@ public class SearchServiceImpl
public List<Dependency> getDependencies( String groupId, String artifactId, String version ) public List<Dependency> getDependencies( String groupId, String artifactId, String version )
throws Exception throws Exception
{ {
List<Dependency> dependencies = new ArrayList<Dependency>();
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories(); List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
try for ( String repoId : observableRepos )
{ {
ArchivaProjectModel model = repoBrowsing.selectVersion( "", observableRepos, groupId, artifactId, version ); ProjectVersionMetadata model = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
List<org.apache.maven.archiva.model.Dependency> modelDeps = model.getDependencies(); if ( model != null )
for ( org.apache.maven.archiva.model.Dependency dep : modelDeps ) {
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 = Dependency dependency =
new Dependency( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier(), new Dependency( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier(),
dep.getType(), dep.getScope() ); dep.getType(), dep.getScope() );
dependencies.add( dependency ); dependencies.add( dependency );
} }
}
catch ( ObjectNotFoundException oe )
{
throw new Exception( "Artifact does not exist." );
}
return dependencies; return dependencies;
} }
}
throw new Exception( "Artifact does not exist." );
}
public List<Artifact> getDependencyTree( String groupId, String artifactId, String version ) public List<Artifact> getDependencyTree( String groupId, String artifactId, String version )
throws Exception throws Exception

View File

@ -30,6 +30,7 @@ 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.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.web.xmlrpc.api.SearchService; import org.apache.archiva.web.xmlrpc.api.SearchService;
@ -38,7 +39,6 @@ import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories; import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories;
import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.browsing.BrowsingResults; import org.apache.maven.archiva.database.browsing.BrowsingResults;
import org.apache.maven.archiva.database.browsing.RepositoryBrowsing; import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint; import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
@ -480,23 +480,19 @@ public class SearchServiceImplTest
public void testGetDependenciesArtifactExists() public void testGetDependenciesArtifactExists()
throws Exception throws Exception
{ {
List<String> observableRepoIds = new ArrayList<String>(); String repoId = "repo1.mirror";
observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" );
ArchivaProjectModel model = new ArchivaProjectModel(); ProjectVersionMetadata model = new ProjectVersionMetadata();
model.setGroupId( ARCHIVA_TEST_GROUP_ID ); model.setId( "1.0" );
model.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID );
model.setVersion( "1.0" );
org.apache.maven.archiva.model.Dependency dependency = new org.apache.maven.archiva.model.Dependency(); org.apache.archiva.metadata.model.Dependency dependency = new org.apache.archiva.metadata.model.Dependency();
dependency.setGroupId( "commons-logging" ); dependency.setGroupId( "org.apache.commons" );
dependency.setArtifactId( "commons-logging" ); dependency.setArtifactId( "commons-logging" );
dependency.setVersion( "2.0" ); dependency.setVersion( "2.0" );
model.addDependency( dependency ); model.addDependency( dependency );
dependency = new org.apache.maven.archiva.model.Dependency(); dependency = new org.apache.archiva.metadata.model.Dependency();
dependency.setGroupId( "junit" ); dependency.setGroupId( "junit" );
dependency.setArtifactId( "junit" ); dependency.setArtifactId( "junit" );
dependency.setVersion( "2.4" ); dependency.setVersion( "2.4" );
@ -504,38 +500,39 @@ public class SearchServiceImplTest
model.addDependency( dependency ); model.addDependency( dependency );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), Collections.singletonList( repoId ) );
repoBrowsingControl.expectAndReturn( metadataResolverControl.expectAndReturn(
repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), metadataResolver.getProjectVersion( repoId, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
model ); model );
repoBrowsingControl.replay(); metadataResolverControl.replay();
userReposControl.replay(); userReposControl.replay();
List<Dependency> dependencies = List<Dependency> dependencies =
searchService.getDependencies( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ); searchService.getDependencies( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
repoBrowsingControl.verify(); metadataResolverControl.verify();
userReposControl.verify(); userReposControl.verify();
assertNotNull( dependencies ); assertNotNull( dependencies );
assertEquals( 2, dependencies.size() ); assertEquals( 2, dependencies.size() );
assertEquals( new Dependency( "org.apache.commons", "commons-logging", "2.0", null, null, null ),
dependencies.get( 0 ) );
assertEquals( new Dependency( "junit", "junit", "2.4", null, null, "test" ), dependencies.get( 1 ) );
} }
public void testGetDependenciesArtifactDoesNotExist() public void testGetDependenciesArtifactDoesNotExist()
throws Exception throws Exception
{ {
List<String> observableRepoIds = new ArrayList<String>(); String repoId = "repo1.mirror";
observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), Collections.singletonList( repoId ) );
repoBrowsingControl.expectAndThrow( metadataResolverControl.expectAndReturn(
repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), metadataResolver.getProjectVersion( repoId, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
new ObjectNotFoundException( "Artifact does not exist." ) ); null );
userReposControl.replay(); userReposControl.replay();
repoBrowsingControl.replay(); metadataResolverControl.replay();
try try
{ {
@ -548,7 +545,7 @@ public class SearchServiceImplTest
} }
userReposControl.verify(); userReposControl.verify();
repoBrowsingControl.verify(); metadataResolverControl.verify();
} }
public void testGetDependencyTreeArtifactExists() public void testGetDependencyTreeArtifactExists()