[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

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

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