mirror of
https://github.com/apache/archiva.git
synced 2025-02-07 02:29:23 +00:00
[MRM-1230] Type of artifact is allways "pom"
o for each search hit, get project model thru repositorybrowse#selectVersion(..) where complete project model is retrieved instead of just the bare artifact obj o added tests git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@823109 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8a116d5a94
commit
3390708c18
@ -31,13 +31,17 @@
|
||||
import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
|
||||
import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
|
||||
import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories;
|
||||
import org.apache.maven.archiva.common.utils.VersionUtil;
|
||||
import org.apache.maven.archiva.database.ArchivaDAO;
|
||||
import org.apache.maven.archiva.database.ArchivaDatabaseException;
|
||||
import org.apache.maven.archiva.database.ArtifactDAO;
|
||||
import org.apache.maven.archiva.database.ObjectNotFoundException;
|
||||
import org.apache.maven.archiva.database.ProjectModelDAO;
|
||||
import org.apache.maven.archiva.database.browsing.BrowsingResults;
|
||||
import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
|
||||
import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
|
||||
import org.apache.maven.archiva.database.constraints.ArtifactsRelatedConstraint;
|
||||
import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
|
||||
import org.apache.maven.archiva.model.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.model.ArchivaProjectModel;
|
||||
import org.slf4j.Logger;
|
||||
@ -46,6 +50,14 @@
|
||||
/**
|
||||
* 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
|
||||
@ -69,24 +81,11 @@ public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, Archiva
|
||||
this.repoBrowsing = repoBrowsing;
|
||||
this.search = search;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public List<Artifact> quickSearch( String queryString )
|
||||
throws Exception
|
||||
{
|
||||
// 1. check whether bytecode search or ordinary search
|
||||
// 2. get observable repos
|
||||
// 3. convert results to a list of Artifact objects
|
||||
|
||||
List<Artifact> artifacts = new ArrayList<Artifact>();
|
||||
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
|
||||
SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
|
||||
@ -94,48 +93,70 @@ public List<Artifact> quickSearch( String queryString )
|
||||
|
||||
results = search.search( "", observableRepos, queryString, limits, null );
|
||||
|
||||
List<SearchResultHit> hits = results.getHits();
|
||||
|
||||
for( SearchResultHit hit : hits )
|
||||
{
|
||||
ArtifactDAO artifactDAO = archivaDAO.getArtifactDAO();
|
||||
|
||||
List<String> versions = hit.getVersions();
|
||||
if( versions != null )
|
||||
for ( SearchResultHit resultHit : results.getHits() )
|
||||
{
|
||||
// double-check all versions as done in SearchAction
|
||||
final List<String> versions =
|
||||
(List<String>) archivaDAO.query( new UniqueVersionConstraint( observableRepos, resultHit.getGroupId(),
|
||||
resultHit.getArtifactId() ) );
|
||||
if ( versions != null && !versions.isEmpty() )
|
||||
{
|
||||
for( String version : versions )
|
||||
{
|
||||
for( String repo : observableRepos )
|
||||
resultHit.setVersion( null );
|
||||
resultHit.setVersions( filterTimestampedSnapshots( versions ) );
|
||||
}
|
||||
|
||||
List<String> resultHitVersions = resultHit.getVersions();
|
||||
if( resultHitVersions != null )
|
||||
{
|
||||
for( String version : resultHitVersions )
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
ArchivaProjectModel model = repoBrowsing.selectVersion( "", observableRepos, resultHit.getGroupId(), resultHit.getArtifactId(), version );
|
||||
|
||||
Artifact artifact = null;
|
||||
if( model == null )
|
||||
{
|
||||
ArchivaArtifact pomArtifact = artifactDAO.getArtifact(
|
||||
hit.getGroupId(), hit.getArtifactId(), version, null, "pom", repo );
|
||||
if( pomArtifact != null )
|
||||
{
|
||||
Artifact artifact = new Artifact( pomArtifact.getModel().getRepositoryId(), pomArtifact.getGroupId(), pomArtifact.getArtifactId(), pomArtifact.getVersion(),
|
||||
pomArtifact.getType() );
|
||||
//pomArtifact.getType(), pomArtifact.getModel().getWhenGathered() );
|
||||
artifacts.add( artifact );
|
||||
break;
|
||||
}
|
||||
artifact = new Artifact( resultHit.getRepositoryId(), resultHit.getGroupId(), resultHit.getArtifactId(), version, "jar" );
|
||||
}
|
||||
catch( ObjectNotFoundException e )
|
||||
{
|
||||
log.debug( "Unable to find pom artifact : " + e.getMessage() );
|
||||
else
|
||||
{
|
||||
artifact = new Artifact( resultHit.getRepositoryId(), model.getGroupId(), model.getArtifactId(), version, model.getPackaging() );
|
||||
}
|
||||
catch( ArchivaDatabaseException e )
|
||||
{
|
||||
log.debug( "Error occurred while getting pom artifact from database : " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
artifacts.add( artifact );
|
||||
}
|
||||
catch( ObjectNotFoundException e )
|
||||
{
|
||||
log.debug( "Unable to find pom artifact : " + e.getMessage() );
|
||||
}
|
||||
catch( ArchivaDatabaseException e )
|
||||
{
|
||||
log.debug( "Error occurred while getting pom artifact from database : " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return artifacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove timestamped snapshots from versions
|
||||
*/
|
||||
private static List<String> filterTimestampedSnapshots(List<String> versions)
|
||||
{
|
||||
final List<String> filtered = new ArrayList<String>();
|
||||
for (final String version : versions)
|
||||
{
|
||||
final String baseVersion = VersionUtil.getBaseVersion(version);
|
||||
if (!filtered.contains(baseVersion))
|
||||
{
|
||||
filtered.add(baseVersion);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public List<Artifact> getArtifactByChecksum( String checksum )
|
||||
throws Exception
|
||||
{
|
||||
|
@ -25,6 +25,10 @@
|
||||
import java.util.List;
|
||||
|
||||
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.indexer.util.SearchUtil;
|
||||
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.Dependency;
|
||||
@ -35,6 +39,7 @@
|
||||
import org.apache.maven.archiva.database.browsing.BrowsingResults;
|
||||
import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
|
||||
import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
|
||||
import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
|
||||
import org.apache.maven.archiva.model.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.model.ArchivaProjectModel;
|
||||
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
|
||||
@ -79,20 +84,136 @@ public void setUp()
|
||||
userRepos = ( XmlRpcUserRepositories ) userReposControl.getMock();
|
||||
|
||||
archivaDAOControl = MockControl.createControl( ArchivaDAO.class );
|
||||
archivaDAOControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
|
||||
archivaDAO = ( ArchivaDAO ) archivaDAOControl.getMock();
|
||||
|
||||
repoBrowsingControl = MockControl.createControl( RepositoryBrowsing.class );
|
||||
repoBrowsing = ( RepositoryBrowsing ) repoBrowsingControl.getMock();
|
||||
|
||||
searchControl = MockControl.createControl( RepositorySearch.class );
|
||||
searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
|
||||
search = ( RepositorySearch ) searchControl.getMock();
|
||||
|
||||
searchService = new SearchServiceImpl( userRepos, archivaDAO, repoBrowsing, search );
|
||||
|
||||
artifactDAOControl = MockControl.createControl( ArtifactDAO.class );
|
||||
artifactDAOControl = MockControl.createControl( ArtifactDAO.class );
|
||||
artifactDAO = ( ArtifactDAO ) artifactDAOControl.getMock();
|
||||
}
|
||||
|
||||
// MRM-1230
|
||||
public void testQuickSearchModelPackagingIsUsed()
|
||||
throws Exception
|
||||
{
|
||||
List<String> observableRepoIds = new ArrayList<String>();
|
||||
observableRepoIds.add( "repo1.mirror" );
|
||||
observableRepoIds.add( "public.releases" );
|
||||
|
||||
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
|
||||
|
||||
SearchResults results = new SearchResults();
|
||||
List<String> versions = new ArrayList<String>();
|
||||
versions.add( "1.0" );
|
||||
|
||||
SearchResultHit resultHit = new SearchResultHit();
|
||||
resultHit.setGroupId( "org.apache.archiva" );
|
||||
resultHit.setArtifactId( "archiva-webapp" );
|
||||
resultHit.setRepositoryId("repo1.mirror");
|
||||
resultHit.setVersions( versions );
|
||||
|
||||
results.addHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-webapp" ), resultHit );
|
||||
|
||||
SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
|
||||
|
||||
searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), results );
|
||||
|
||||
archivaDAOControl.expectAndReturn( archivaDAO.query( new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(),
|
||||
resultHit.getArtifactId() ) ), null );
|
||||
|
||||
ArchivaProjectModel model = new ArchivaProjectModel();
|
||||
model.setGroupId( "org.apache.archiva" );
|
||||
model.setArtifactId( "archiva-webapp" );
|
||||
model.setVersion( "1.0" );
|
||||
model.setPackaging( "war" );
|
||||
|
||||
repoBrowsingControl.expectAndReturn( repoBrowsing.selectVersion( "", observableRepoIds, "org.apache.archiva", "archiva-webapp", "1.0" ), model );
|
||||
|
||||
userReposControl.replay();
|
||||
searchControl.replay();
|
||||
repoBrowsingControl.replay();
|
||||
archivaDAOControl.replay();
|
||||
|
||||
List<Artifact> artifacts = searchService.quickSearch( "archiva" );
|
||||
|
||||
userReposControl.verify();
|
||||
searchControl.verify();
|
||||
repoBrowsingControl.verify();
|
||||
archivaDAOControl.verify();
|
||||
|
||||
assertNotNull( artifacts );
|
||||
assertEquals( 1, artifacts.size() );
|
||||
|
||||
Artifact hit = artifacts.get( 0 );
|
||||
assertEquals( "org.apache.archiva", hit.getGroupId() );
|
||||
assertEquals( "archiva-webapp", hit.getArtifactId() );
|
||||
assertEquals( "1.0", hit.getVersion() );
|
||||
assertEquals( "war", hit.getType() );
|
||||
assertEquals( "repo1.mirror", hit.getRepositoryId() );
|
||||
}
|
||||
|
||||
// returned model is null!
|
||||
public void testQuickSearchDefaultPackagingIsUsed()
|
||||
throws Exception
|
||||
{
|
||||
List<String> observableRepoIds = new ArrayList<String>();
|
||||
observableRepoIds.add( "repo1.mirror" );
|
||||
observableRepoIds.add( "public.releases" );
|
||||
|
||||
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
|
||||
|
||||
SearchResults results = new SearchResults();
|
||||
List<String> versions = new ArrayList<String>();
|
||||
versions.add( "1.0" );
|
||||
|
||||
SearchResultHit resultHit = new SearchResultHit();
|
||||
resultHit.setRepositoryId( "repo1.mirror" );
|
||||
resultHit.setGroupId( "org.apache.archiva" );
|
||||
resultHit.setArtifactId( "archiva-test" );
|
||||
resultHit.setVersions( versions );
|
||||
|
||||
results.addHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-test" ), resultHit );
|
||||
|
||||
SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
|
||||
|
||||
searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), results );
|
||||
|
||||
archivaDAOControl.expectAndReturn( archivaDAO.query( new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(),
|
||||
resultHit.getArtifactId() ) ), null );
|
||||
|
||||
repoBrowsingControl.expectAndReturn( repoBrowsing.selectVersion( "", observableRepoIds, "org.apache.archiva", "archiva-test", "1.0" ), null );
|
||||
|
||||
userReposControl.replay();
|
||||
searchControl.replay();
|
||||
repoBrowsingControl.replay();
|
||||
archivaDAOControl.replay();
|
||||
|
||||
List<Artifact> artifacts = searchService.quickSearch( "archiva" );
|
||||
|
||||
userReposControl.verify();
|
||||
searchControl.verify();
|
||||
repoBrowsingControl.verify();
|
||||
archivaDAOControl.verify();
|
||||
|
||||
assertNotNull( artifacts );
|
||||
assertEquals( 1, artifacts.size() );
|
||||
|
||||
Artifact hit = artifacts.get( 0 );
|
||||
assertEquals( "org.apache.archiva", hit.getGroupId() );
|
||||
assertEquals( "archiva-test", hit.getArtifactId() );
|
||||
assertEquals( "1.0", hit.getVersion() );
|
||||
assertEquals( "jar", hit.getType() );
|
||||
assertEquals( "repo1.mirror", hit.getRepositoryId() );
|
||||
}
|
||||
|
||||
/*
|
||||
* quick/general text search which returns a list of artifacts
|
||||
* query for an artifact based on a checksum
|
||||
|
Loading…
x
Reference in New Issue
Block a user