From: Brett Porter Date: Fri, 4 Dec 2009 03:00:22 +0000 (+0000) Subject: Merged /archiva/trunk:r885006-887039 X-Git-Tag: archiva-1.4-M1~1017^2~102 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=521bb63ade1539afa83b564a3ce3fd91ce14115f;p=archiva.git Merged /archiva/trunk:r885006-887039 git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@887043 13f79535-47bb-0310-9956-ffa450edef68 --- 521bb63ade1539afa83b564a3ce3fd91ce14115f diff --cc archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java index 0b8e63b7d,9734674d7..c1e81e388 --- 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 @@@ -45,45 -44,33 +45,32 @@@ import org.apache.maven.archiva.model.A import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** - * SearchServiceImpl - * - * quick/general text search which returns a list of artifacts - * query for an artifact based on a checksum - * query for all available versions of an artifact, sorted in version significance order - * query for all available versions of an artifact since a given date - * query for an artifact's direct dependencies - * query for an artifact's dependency tree (as with mvn dependency:tree - no duplicates should be included) - * query for all artifacts that depend on a given artifact - * - * @version $Id: SearchServiceImpl.java - */ public class SearchServiceImpl implements SearchService -{ +{ private Logger log = LoggerFactory.getLogger( SearchServiceImpl.class ); - + private RepositorySearch search; - + private XmlRpcUserRepositories xmlRpcUserRepositories; - + private ArchivaDAO archivaDAO; - - private RepositoryBrowsing repoBrowsing; - + + private MetadataResolver metadataResolver; + public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO, - RepositoryBrowsing repoBrowsing, RepositorySearch search ) + MetadataResolver metadataResolver, RepositorySearch search ) { this.xmlRpcUserRepositories = xmlRpcUserRepositories; - this.archivaDAO = archivaDAO; - this.repoBrowsing = repoBrowsing; + this.archivaDAO = archivaDAO; this.search = search; + this.metadataResolver = metadataResolver; } - - @SuppressWarnings( "unchecked" ) + + @SuppressWarnings("unchecked") public List quickSearch( String queryString ) throws Exception - { + { List artifacts = new ArrayList(); List observableRepos = xmlRpcUserRepositories.getObservableRepositories(); SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES ); @@@ -212,46 -196,50 +199,49 @@@ throws Exception { List artifacts = new ArrayList(); - + // 1. get observable repositories - // 2. use metadata repository to query uniqueVersions? (but with date) + // 2. use RepositoryBrowsing method to query uniqueVersions? (but with date) + + throw new UnsupportedOperationException( "getArtifactVersionsByDate not yet implemented" ); - return artifacts; + // return artifacts; } - - public List getDependencies( String groupId, String artifactId, String version ) + + 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 ) + + public List getDependencyTree( String groupId, String artifactId, String version ) throws Exception { List a = new ArrayList(); - - return a; + + throw new UnsupportedOperationException( "getDependencyTree not yet implemented" ); + // return a; } - - //get artifacts that depend on a given artifact + public List getDependees( String groupId, String artifactId, String version ) throws Exception { diff --cc archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java index 34b18b483,654e8237a..751312536 --- 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 @@@ -231,9 -222,68 +231,9 @@@ public class SearchServiceImplTes assertEquals( ARCHIVA_TEST_ARTIFACT_ID, artifact.getArtifactId() ); assertEquals( "1.0", artifact.getVersion() ); assertEquals( "jar", artifact.getType() ); - assertEquals( "public.releases", artifact.getRepositoryId() ); + assertNull( "Repository should be null since the model was not found in the database!", artifact.getRepositoryId() ); } - - /* - * quick/general text search which returns a list of artifacts - * query for an artifact based on a checksum - * query for all available versions of an artifact, sorted in version significance order - * query for all available versions of an artifact since a given date - * query for an artifact's direct dependencies - * query for an artifact's dependency tree (as with mvn dependency:tree - no duplicates should be included) - * query for all artifacts that depend on a given artifact - */ - - /* quick search */ - -// public void testQuickSearchArtifactBytecodeSearch() -// throws Exception -// { -// // 1. check whether bytecode search or ordinary search -// // 2. get observable repos -// // 3. convert results to a list of Artifact objects -// -// List observableRepoIds = new ArrayList(); -// observableRepoIds.add( "repo1.mirror" ); -// observableRepoIds.add( "public.releases" ); -// -// userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); -// -// Date whenGathered = new Date(); -// SearchResults results = new SearchResults(); -// ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "archiva-test", "1.0", "", "jar", "public.releases" ); -// artifact.getModel().setWhenGathered( whenGathered ); -// -// SearchResultHit resultHit = new SearchResultHit(); -// resultHit.setArtifact(artifact); -// resultHit.setRepositoryId("repo1.mirror"); -// -// results.addHit(SearchUtil.getHitId(artifact.getGroupId(), artifact.getArtifactId()), resultHit); -// -// SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES ); -// -// searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "MyClassName", limits, null ), results ); -// -// archivaDAOControl.expectAndReturn( archivaDAO.getArtifactDAO(), artifactDAO ); -// artifactDAOControl.expectAndReturn( artifactDAO.getArtifact( "org.apache.archiva", "archiva-test", "1.0", "", "pom", "public.releases" ), artifact ); -// -// userReposControl.replay(); -// searchControl.replay(); -// archivaDAOControl.replay(); -// artifactDAOControl.replay(); -// -// List artifacts = searchService.quickSearch( "bytecode:MyClassName" ); -// -// userReposControl.verify(); -// searchControl.verify(); -// archivaDAOControl.verify(); -// artifactDAOControl.verify(); -// -// assertNotNull( artifacts ); -// assertEquals( 1, artifacts.size() ); -// } - + public void testQuickSearchArtifactRegularSearch() throws Exception {