diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Dependency.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Dependency.java index 7e12d76f0..3ae198132 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Dependency.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Dependency.java @@ -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; 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 3f91f6849..abb40caef 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 @@ -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 getDependencies( String groupId, String artifactId, String version ) throws Exception { - List dependencies = new ArrayList(); List observableRepos = xmlRpcUserRepositories.getObservableRepositories(); - try + for ( String repoId : observableRepos ) { - ArchivaProjectModel model = repoBrowsing.selectVersion( "", observableRepos, groupId, artifactId, version ); - List 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 dependencies = new ArrayList(); + List 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 getDependencyTree( String groupId, String artifactId, String version ) 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 f915d5701..41efc9a35 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 @@ -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 observableRepoIds = new ArrayList(); - 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 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 observableRepoIds = new ArrayList(); - 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()