From ae4ff95a87f5ff91859b214c819715b4bf4d29c4 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 14 Sep 2011 22:52:22 +0000 Subject: [PATCH] more tests on search rest services prevent copying files for test in archiva-indexer : with scan activated some results were false git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1170883 13f79535-47bb-0310-9956-ffa450edef68 --- .../indexer/search/NexusRepositorySearch.java | 6 + .../archiva/indexer/search/SearchFields.java | 32 ++++- .../indexer/search/SearchResultHit.java | 12 ++ .../search/AbstractNexusRepositorySearch.java | 111 +++++++++++++----- .../search/NexusRepositorySearchTest.java | 106 +++++++++++------ .../archiva-search/1.0/archiva-search-1.0.jar | Bin .../archiva-search/1.0/archiva-search-1.0.pom | 0 .../archiva-search/1.1/archiva-search-1.1.jar | Bin .../archiva-search/1.1/archiva-search-1.1.pom | 0 .../1.0/artifactid-numeric-1.0.jar | 0 .../1.0/artifactid-numeric-1.0.pom | 0 .../1.0/artifactid-numeric123-1.0.jar | 0 .../1.0/artifactid-numeric123-1.0.pom | 0 .../1.0/classname-search-1.0.jar | Bin .../1.0/classname-search-1.0.pom | 0 .../1.0/archiva-search-1.0-patch1.jar} | Bin .../1.0/archiva-search-1.0-sources.jar} | Bin .../archiva-search/1.0/archiva-search-1.0.jar | Bin 0 -> 2518 bytes .../archiva-search/1.0/archiva-search-1.0.pom | 0 .../archiva-test/1.0/archiva-test-1.0.jar | Bin .../archiva-test/1.0/archiva-test-1.0.pom | 0 .../archiva-test/2.0/archiva-test-2.0.jar | Bin .../archiva-test/2.0/archiva-test-2.0.pom | 0 .../archiva-webapp/1.0/archiva-webapp-1.0.pom | 0 .../archiva-webapp/1.0/archiva-webapp-1.0.war | 0 ...rg.apache.felix.bundlerepository-1.6.6.jar | Bin ...rg.apache.felix.bundlerepository-1.6.6.pom | 0 .../archiva/rest/api/model/Artifact.java | 13 ++ .../archiva/rest/api/model/SearchRequest.java | 35 +++++- .../rest/api/services/SearchService.java | 12 +- .../rest/services/DefaultSearchService.java | 21 ++++ .../rest/services/SearchServiceTest.java | 31 +++++ 32 files changed, 301 insertions(+), 78 deletions(-) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.pom (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.pom (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/com/artifactid-numeric/1.0/artifactid-numeric-1.0.pom (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.pom (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/com/classname-search/1.0/classname-search-1.0.jar (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/com/classname-search/1.0/classname-search-1.0.pom (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar => nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-patch1.jar} (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar => nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar} (100%) create mode 100644 archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.pom (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.pom (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.pom (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/org/apache/felix/org.apache.felix.bundlerepository/1.6.6/org.apache.felix.bundlerepository-1.6.6.jar (100%) rename archiva-modules/archiva-base/archiva-indexer/src/test/{resources => }/nexus-search-test-repo/org/apache/felix/org.apache.felix.bundlerepository/1.6.6/org.apache.felix.bundlerepository-1.6.6.pom (100%) diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java index 9734179d6..b374b9a9e 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java @@ -187,6 +187,12 @@ public class NexusRepositorySearch Occur.MUST ); } + if ( StringUtils.isNotBlank( searchFields.getClassifier() ) ) + { + q.add( indexer.constructQuery( MAVEN.CLASSIFIER, new StringSearchExpression( searchFields.getClassifier() ) ), + Occur.MUST ); + } + if ( q.getClauses() == null || q.getClauses().length <= 0 ) { throw new RepositorySearchException( "No search fields set." ); diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchFields.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchFields.java index 808a19cbd..74c5e38ce 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchFields.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchFields.java @@ -83,6 +83,8 @@ public class SearchFields */ private String bundleExportService; + private String classifier; + public SearchFields() { // no op @@ -200,13 +202,33 @@ public class SearchFields this.bundleExportService = bundleExportService; } + public String getClassifier() + { + return classifier; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + @Override public String toString() { - return "SearchFields{" + "groupId='" + groupId + '\'' + ", artifactId='" + artifactId + '\'' + ", version='" - + version + '\'' + ", packaging='" + packaging + '\'' + ", className='" + className + '\'' - + ", repositories=" + repositories + ", bundleVersion='" + bundleVersion + '\'' + ", bundleSymbolicName='" - + bundleSymbolicName + '\'' + ", bundleExportPackage='" + bundleExportPackage + '\'' - + ", bundleExportService='" + bundleExportService + '\'' + '}'; + final StringBuilder sb = new StringBuilder(); + sb.append( "SearchFields" ); + sb.append( "{groupId='" ).append( groupId ).append( '\'' ); + sb.append( ", artifactId='" ).append( artifactId ).append( '\'' ); + sb.append( ", version='" ).append( version ).append( '\'' ); + sb.append( ", packaging='" ).append( packaging ).append( '\'' ); + sb.append( ", className='" ).append( className ).append( '\'' ); + sb.append( ", repositories=" ).append( repositories ); + sb.append( ", bundleVersion='" ).append( bundleVersion ).append( '\'' ); + sb.append( ", bundleSymbolicName='" ).append( bundleSymbolicName ).append( '\'' ); + sb.append( ", bundleExportPackage='" ).append( bundleExportPackage ).append( '\'' ); + sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' ); + sb.append( ", classifier='" ).append( classifier ).append( '\'' ); + sb.append( '}' ); + return sb.toString(); } } diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java index f397db864..30119b3c1 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java @@ -127,6 +127,7 @@ public class SearchResultHit */ private String bundleRequireBundle; + private String classifier; public String getContext() { @@ -333,6 +334,16 @@ public class SearchResultHit return getPackaging(); } + public String getClassifier() + { + return classifier; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + @Override public String toString() { @@ -357,6 +368,7 @@ public class SearchResultHit sb.append( ", bundleDocUrl='" ).append( bundleDocUrl ).append( '\'' ); sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' ); sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' ); + sb.append( ", classifier='" ).append( classifier ).append( '\'' ); sb.append( '}' ); return sb.toString(); } diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractNexusRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractNexusRepositorySearch.java index 435414c54..a10cc5f40 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractNexusRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractNexusRepositorySearch.java @@ -24,25 +24,28 @@ import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin import org.apache.archiva.common.plexusbridge.MavenIndexerUtils; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.SystemUtils; import org.apache.maven.archiva.common.utils.FileUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.index.ArtifactContext; import org.apache.maven.index.ArtifactContextProducer; +import org.apache.maven.index.ArtifactScanningListener; import org.apache.maven.index.NexusIndexer; +import org.apache.maven.index.ScanningResult; import org.apache.maven.index.context.IndexingContext; -import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.easymock.MockControl; import org.junit.After; import org.junit.Before; import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.inject.Inject; import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -55,6 +58,8 @@ public abstract class AbstractNexusRepositorySearch extends TestCase { + protected Logger log = LoggerFactory.getLogger( getClass() ); + public static String TEST_REPO_1 = "nexus-search-test-repo"; public static String TEST_REPO_2 = "nexus-search-test-repo-2"; @@ -83,13 +88,11 @@ public abstract class AbstractNexusRepositorySearch { super.setUp(); - FileUtils.deleteDirectory( - new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) ); - assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ).exists() ); + FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_1 + "/.indexer" ) ); + assertFalse( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_1 + "/.indexer" ).exists() ); - FileUtils.deleteDirectory( - new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) ); - assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() ); + FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ) ); + assertFalse( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ).exists() ); archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class ); @@ -119,14 +122,6 @@ public abstract class AbstractNexusRepositorySearch nexusIndexer.removeIndexingContext( indexingContext, true ); } - FileUtils.deleteDirectory( - new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) ); - assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ).exists() ); - - FileUtils.deleteDirectory( - new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) ); - assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() ); - super.tearDown(); } @@ -134,7 +129,12 @@ public abstract class AbstractNexusRepositorySearch { ManagedRepositoryConfiguration repositoryConfig = new ManagedRepositoryConfiguration(); repositoryConfig.setId( repository ); - repositoryConfig.setLocation( FileUtil.getBasedir() + "/target/test-classes/" + repository ); + repositoryConfig.setLocation( FileUtil.getBasedir() + "/target/repos/" + repository ); + File f = new File( repositoryConfig.getLocation() ); + if ( !f.exists() ) + { + f.mkdirs(); + } repositoryConfig.setLayout( "default" ); repositoryConfig.setName( repository ); repositoryConfig.setScanned( true ); @@ -145,10 +145,17 @@ public abstract class AbstractNexusRepositorySearch } protected void createIndex( String repository, List filesToBeIndexed, boolean scan ) - throws IOException, UnsupportedExistingLuceneIndexException + throws Exception { - File indexerDirectory = new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" ); + IndexingContext context = nexusIndexer.getIndexingContexts().get( repository ); + + if ( context != null ) + { + nexusIndexer.removeIndexingContext( context, true ); + } + + File indexerDirectory = new File( FileUtil.getBasedir(), "/target/repos/" + repository + "/.indexer" ); if ( indexerDirectory.exists() ) { @@ -157,8 +164,7 @@ public abstract class AbstractNexusRepositorySearch assertFalse( indexerDirectory.exists() ); - File lockFile = - new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer/write.lock" ); + File lockFile = new File( FileUtil.getBasedir(), "/target/repos/" + repository + "/.indexer/write.lock" ); if ( lockFile.exists() ) { lockFile.delete(); @@ -166,13 +172,13 @@ public abstract class AbstractNexusRepositorySearch assertFalse( lockFile.exists() ); - File repo = new File( FileUtil.getBasedir(), "/target/test-classes/" + repository ); - File indexDirectory = new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" ); + File repo = new File( FileUtil.getBasedir(), "/target/repos/" + repository ); + File indexDirectory = new File( FileUtil.getBasedir(), "/target/repos/" + repository + "/.indexer" ); - IndexingContext context = nexusIndexer.addIndexingContext( repository, repository, repo, indexDirectory, - repo.toURI().toURL().toExternalForm(), - indexDirectory.toURI().toURL().toString(), - search.getAllIndexCreators() ); + context = nexusIndexer.addIndexingContext( repository, repository, repo, indexDirectory, + repo.toURI().toURL().toExternalForm(), + indexDirectory.toURI().toURL().toString(), + search.getAllIndexCreators() ); List artifactContexts = new ArrayList( filesToBeIndexed.size() ); for ( File artifactFile : filesToBeIndexed ) @@ -181,16 +187,59 @@ public abstract class AbstractNexusRepositorySearch artifactContexts.add( ac ); } - context.setSearchable( true ); - if ( filesToBeIndexed != null && !filesToBeIndexed.isEmpty() ) { nexusIndexer.addArtifactsToIndex( artifactContexts, context ); + + while ( context.isReceivingUpdates() ) + { + Thread.sleep( 10 ); + } } if ( scan ) { - nexusIndexer.scan( context, false ); + nexusIndexer.scan( context, new ArtifactScanListener(), false ); } - assertTrue( new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" ).exists() ); + + context.setSearchable( true ); + + assertTrue( new File( FileUtil.getBasedir(), "/target/repos/" + repository + "/.indexer" ).exists() ); + } + + static class ArtifactScanListener + implements ArtifactScanningListener + { + protected Logger log = LoggerFactory.getLogger( getClass() ); + + public void scanningStarted( IndexingContext ctx ) + { + + } + + public void scanningFinished( IndexingContext ctx, ScanningResult result ) + { + + } + + public void artifactError( ArtifactContext ac, Exception e ) + { + log.debug( "artifactError " + ac.getArtifact().getPath(), e ); + } + + public void artifactDiscovered( ArtifactContext ac ) + { + log.debug( "artifactDiscovered " + ac.getArtifact().getPath() + ":" + ac.getArtifactInfo() ); + } + } + + public String niceDisplay( SearchResults searchResults ) + throws Exception + { + StringBuilder sb = new StringBuilder(); + for ( SearchResultHit hit : searchResults.getHits() ) + { + sb.append( hit.toString() ).append( SystemUtils.LINE_SEPARATOR ); + } + return sb.toString(); } } diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java index e2ded80ee..90e2a5ec6 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java @@ -42,12 +42,12 @@ public class NexusRepositorySearchTest private void createSimpleIndex( boolean scan ) - throws IOException, UnsupportedExistingLuceneIndexException, IllegalArtifactCoordinateException + throws Exception { List files = new ArrayList(); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + files.add( new File( FileUtil.getBasedir(), "src/test" + TEST_REPO_1 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) ); files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) ); @@ -56,37 +56,37 @@ public class NexusRepositorySearchTest } private void createIndexContainingMoreArtifacts( boolean scan ) - throws IOException, UnsupportedExistingLuceneIndexException, IllegalArtifactCoordinateException + throws Exception { List files = new ArrayList(); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + "/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) ); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + "/com/classname-search/1.0/classname-search-1.0.jar" ) ); createIndex( TEST_REPO_1, files, scan ); } - + private void createIndexContainingMultipleArtifactsSameVersion( boolean scan ) - throws IOException, UnsupportedExistingLuceneIndexException, IllegalArtifactCoordinateException + throws Exception { List files = new ArrayList(); - - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + - "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + - "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar" ) ); - + + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) ); + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar" ) ); + createIndex( TEST_REPO_1, files, scan ); } @@ -131,13 +131,13 @@ public class NexusRepositorySearchTest //TODO: search for class & package names } - + @Test - public void testQuickSearchMultipleArtifactsSameVersion() + public void testQuickSearchMultipleArtifactsSameVersion() throws Exception { createIndexContainingMultipleArtifactsSameVersion( false ); - + List selectedRepos = new ArrayList(); selectedRepos.add( TEST_REPO_1 ); @@ -157,7 +157,43 @@ public class NexusRepositorySearchTest assertEquals( "org.apache.archiva", hit.getGroupId() ); assertEquals( "archiva-search", hit.getArtifactId() ); assertEquals( "1.0", hit.getVersions().get( 0 ) ); - + + //only 1 version of 1.0 is retrieved + assertEquals( 1, hit.getVersions().size() ); + } + + @Test + public void testMultipleArtifactsSameVersionWithClassifier() + throws Exception + { + createIndexContainingMultipleArtifactsSameVersion( false ); + + List selectedRepos = new ArrayList(); + selectedRepos.add( TEST_REPO_1 ); + + // search artifactId + archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); + + archivaConfigControl.replay(); + + SearchFields searchFields = new SearchFields(); + searchFields.setGroupId( "org.apache.archiva" ); + searchFields.setArtifactId( "archiva-search" ); + searchFields.setClassifier( "sources" ); + searchFields.setRepositories( selectedRepos ); + + SearchResults results = search.search( "user", searchFields, null ); + + archivaConfigControl.verify(); + + assertNotNull( results ); + assertEquals( 1, results.getTotalHits() ); + + SearchResultHit hit = results.getHits().get( 0 ); + assertEquals( "org.apache.archiva", hit.getGroupId() ); + assertEquals( "archiva-search", hit.getArtifactId() ); + assertEquals( "1.0", hit.getVersions().get( 0 ) ); + //only 1 version of 1.0 is retrieved assertEquals( 1, hit.getVersions().size() ); } @@ -206,7 +242,7 @@ public class NexusRepositorySearchTest assertNotNull( results ); assertEquals( 1, results.getHits().size() ); - assertEquals( "total hits not 6 for page1 " + results, 6, results.getTotalHits() ); + assertEquals( "total hits not 7 for page1 " + results, 7, results.getTotalHits() ); assertEquals( "returned hits not 1 for page1 " + results, 1, results.getReturnedHitsCount() ); assertEquals( limits, results.getLimits() ); @@ -227,7 +263,7 @@ public class NexusRepositorySearchTest assertNotNull( results ); assertEquals( "hits not 1", 1, results.getHits().size() ); - assertEquals( "total hits not 6 for page 2 " + results, 6, results.getTotalHits() ); + assertEquals( "total hits not 7 for page 2 " + results, 7, results.getTotalHits() ); assertEquals( "returned hits not 1 for page2 " + results, 1, results.getReturnedHitsCount() ); assertEquals( limits, results.getLimits() ); } @@ -239,11 +275,11 @@ public class NexusRepositorySearchTest createSimpleIndex( true ); List files = new ArrayList(); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2 + "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) ); - createIndex( TEST_REPO_2, files, true ); + createIndex( TEST_REPO_2, files, false ); List selectedRepos = new ArrayList(); selectedRepos.add( TEST_REPO_1 ); @@ -265,7 +301,7 @@ public class NexusRepositorySearchTest SearchResultHit hit = results.getHits().get( 0 ); assertEquals( "org.apache.archiva", hit.getGroupId() ); assertEquals( "archiva-search", hit.getArtifactId() ); - assertEquals( 2, hit.getVersions().size() ); + assertEquals("not 2 version for hit " + hit, 2, hit.getVersions().size() ); assertTrue( hit.getVersions().contains( "1.0" ) ); assertTrue( hit.getVersions().contains( "1.1" ) ); @@ -357,7 +393,7 @@ public class NexusRepositorySearchTest SearchResultHit hit = results.getHits().get( 0 ); assertEquals( "org.apache.archiva", hit.getGroupId() ); assertEquals( "archiva-test", hit.getArtifactId() ); - assertEquals("versions not 1", 1, hit.getVersions().size() ); + assertEquals( "versions not 1", 1, hit.getVersions().size() ); assertEquals( "1.0", hit.getVersions().get( 0 ) ); } @@ -367,9 +403,9 @@ public class NexusRepositorySearchTest throws Exception { List files = new ArrayList(); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2 + "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) ); createIndex( TEST_REPO_2, files, false ); @@ -453,9 +489,9 @@ public class NexusRepositorySearchTest throws Exception { List files = new ArrayList(); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) ); createIndex( TEST_REPO_1, files, true ); @@ -616,7 +652,7 @@ public class NexusRepositorySearchTest archivaConfigControl.verify(); assertNotNull( results ); - assertEquals( 7, results.getTotalHits() ); + assertEquals( "not 8 but " + results.getTotalHits() + ":" + niceDisplay( results ), 8, results.getTotalHits() ); } @Test diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.pom b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.pom similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.pom rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.pom diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.pom b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.pom similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.pom rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo-2/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.pom diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/com/artifactid-numeric/1.0/artifactid-numeric-1.0.pom b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/com/artifactid-numeric/1.0/artifactid-numeric-1.0.pom similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/com/artifactid-numeric/1.0/artifactid-numeric-1.0.pom rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/com/artifactid-numeric/1.0/artifactid-numeric-1.0.pom diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.pom b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.pom similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.pom rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.pom diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/com/classname-search/1.0/classname-search-1.0.jar b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/com/classname-search/1.0/classname-search-1.0.jar similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/com/classname-search/1.0/classname-search-1.0.jar rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/com/classname-search/1.0/classname-search-1.0.jar diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/com/classname-search/1.0/classname-search-1.0.pom b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/com/classname-search/1.0/classname-search-1.0.pom similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/com/classname-search/1.0/classname-search-1.0.pom rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/com/classname-search/1.0/classname-search-1.0.pom diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-patch1.jar similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-patch1.jar diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..9c16c3ced6b7754ecdbeee212a80ea136794efbc GIT binary patch literal 2518 zcmWIWW@h1H0D+b{)>dE!l;8x?zOEsTx}JV+`TwB2$6V)j%wQtjyQZ z&(qB{I7H9a?X&Nh(>~t1dKY=Ub+yi&Ilno`;EM5sr$stm=T7K&>pF3;KUoqsMNIpE zO2y7O-9f_MLBS<+wbqKra0^W~4ic>qJ{|NKDC1>Z>~-Lg=E};K0(D*M!oAE+6a?Eg zS2#Pz>BZ?Wz?{XvP>bez7NE28i_+l^$5g=$RgqYbn4FP{N1-sP!o;HFjLfn`JQ}31 zYbZ_yX@%?K0K1vzZc|S@BLjme69a=XUVV-Q1$xOjiN(dWfhWC~9R+H0r$x&6`uM~o z3;73Lu&nCfQ0i!RZ1u3Ic;z$8v;F1^9~OIWelEE`4EA1YX0kL1ym8*UE}Uf+~pd+qB0hqz3`*lsO{6D`*#y`?mXeYT0K)mX~Fi+Wg;uiwoRT`>pxl5Wc~xj zv*EE$#ucsq7<81eNBg04cHUypAtGr*pfYb4*)l^*dP2{QwO1v$nQ zjkO(xD||P*_2bi?_UsAGHnLN1cc3)T^Ta>o?zg_tEtBq((agH=rIP2H-nHL8_zC6A5Gh~dT^C%T@cR1kKQo%U z*9E17Pl*ZJQoGbEy8H>Rm&L(3E5bhAu?;()P1jcTDrZ-wqy8?p_(on0HD8;xoo_UZLT=xFT4qmANRg_&U}s1UFpi3W*q+?DDk#b?NG&SKOf3#B^FQmY>!suA8|bkr48yJNfY}sODw%N!anBxOSpn;LWh9_FkV%ii~N_**_(%1dqv+=CH*L80l z51(@$SG^(S_7g81t&=|9K6;F&oLWn|gB^81g)k$N2s7?V1n3(e5MX%g2%_N`2%!yo zr2=+~$D_M1*C literal 0 HcmV?d00001 diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.pom b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.pom similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.pom rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.pom diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.pom b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.pom similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.pom rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.pom diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.pom b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.pom similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.pom rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.pom diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/felix/org.apache.felix.bundlerepository/1.6.6/org.apache.felix.bundlerepository-1.6.6.jar b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/felix/org.apache.felix.bundlerepository/1.6.6/org.apache.felix.bundlerepository-1.6.6.jar similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/felix/org.apache.felix.bundlerepository/1.6.6/org.apache.felix.bundlerepository-1.6.6.jar rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/felix/org.apache.felix.bundlerepository/1.6.6/org.apache.felix.bundlerepository-1.6.6.jar diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/felix/org.apache.felix.bundlerepository/1.6.6/org.apache.felix.bundlerepository-1.6.6.pom b/archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/felix/org.apache.felix.bundlerepository/1.6.6/org.apache.felix.bundlerepository-1.6.6.pom similarity index 100% rename from archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/felix/org.apache.felix.bundlerepository/1.6.6/org.apache.felix.bundlerepository-1.6.6.pom rename to archiva-modules/archiva-base/archiva-indexer/src/test/nexus-search-test-repo/org/apache/felix/org.apache.felix.bundlerepository/1.6.6/org.apache.felix.bundlerepository-1.6.6.pom diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java index 001f5d7ea..999728bec 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java @@ -123,6 +123,8 @@ public class Artifact */ private String bundleRequireBundle; + private String classifier; + public Artifact() { @@ -309,6 +311,16 @@ public class Artifact this.bundleRequireBundle = bundleRequireBundle; } + public String getClassifier() + { + return classifier; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + @Override public String toString() { @@ -332,6 +344,7 @@ public class Artifact sb.append( ", bundleDocUrl='" ).append( bundleDocUrl ).append( '\'' ); sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' ); sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' ); + sb.append( ", classifier='" ).append( classifier ).append( '\'' ); sb.append( '}' ); return sb.toString(); } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/SearchRequest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/SearchRequest.java index 7ab8f37c4..e2edc4178 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/SearchRequest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/SearchRequest.java @@ -1,5 +1,6 @@ package org.apache.archiva.rest.api.model; +import javax.xml.bind.annotation.XmlRootElement; import java.util.ArrayList; import java.util.List; @@ -21,7 +22,7 @@ import java.util.List; * specific language governing permissions and limitations * under the License. */ - +@XmlRootElement( name = "searchRequest" ) public class SearchRequest { /** @@ -83,6 +84,8 @@ public class SearchRequest */ private String bundleExportService; + private String classifier; + public SearchRequest() { // no op @@ -200,13 +203,33 @@ public class SearchRequest this.bundleExportService = bundleExportService; } + public String getClassifier() + { + return classifier; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + @Override public String toString() { - return "SearchFields{" + "groupId='" + groupId + '\'' + ", artifactId='" + artifactId + '\'' + ", version='" - + version + '\'' + ", packaging='" + packaging + '\'' + ", className='" + className + '\'' - + ", repositories=" + repositories + ", bundleVersion='" + bundleVersion + '\'' + ", bundleSymbolicName='" - + bundleSymbolicName + '\'' + ", bundleExportPackage='" + bundleExportPackage + '\'' - + ", bundleExportService='" + bundleExportService + '\'' + '}'; + final StringBuilder sb = new StringBuilder(); + sb.append( "SearchRequest" ); + sb.append( "{groupId='" ).append( groupId ).append( '\'' ); + sb.append( ", artifactId='" ).append( artifactId ).append( '\'' ); + sb.append( ", version='" ).append( version ).append( '\'' ); + sb.append( ", packaging='" ).append( packaging ).append( '\'' ); + sb.append( ", className='" ).append( className ).append( '\'' ); + sb.append( ", repositories=" ).append( repositories ); + sb.append( ", bundleVersion='" ).append( bundleVersion ).append( '\'' ); + sb.append( ", bundleSymbolicName='" ).append( bundleSymbolicName ).append( '\'' ); + sb.append( ", bundleExportPackage='" ).append( bundleExportPackage ).append( '\'' ); + sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' ); + sb.append( ", classifier='" ).append( classifier ).append( '\'' ); + sb.append( '}' ); + return sb.toString(); } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java index a1542a851..0575d7bb4 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java @@ -22,9 +22,11 @@ package org.apache.archiva.rest.api.services; import org.apache.archiva.rest.api.model.Artifact; import org.apache.archiva.rest.api.model.Dependency; +import org.apache.archiva.rest.api.model.SearchRequest; import org.codehaus.plexus.redback.authorization.RedbackAuthorization; import javax.ws.rs.GET; +import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; @@ -58,6 +60,13 @@ public interface SearchService @QueryParam( "artifactId" ) String artifactId ) throws ArchivaRestServiceException; + @Path( "searchArtifacts" ) + @POST + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( noPermission = true, noRestriction = true ) + List searchArtifacts( SearchRequest searchRequest ) + throws ArchivaRestServiceException; + @Path( "getDependencies" ) @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) @@ -67,11 +76,12 @@ public interface SearchService @QueryParam( "version" ) String version ) throws ArchivaRestServiceException; + @Path( "getArtifactByChecksum" ) @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) @RedbackAuthorization( noPermission = true, noRestriction = true ) List getArtifactByChecksum( @QueryParam( "checksum" ) String checksum ) - throws ArchivaRestServiceException; + throws ArchivaRestServiceException; } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java index 7d49c83dd..79ce2fa7e 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java @@ -27,6 +27,7 @@ import org.apache.archiva.indexer.search.SearchResultLimits; import org.apache.archiva.indexer.search.SearchResults; import org.apache.archiva.rest.api.model.Artifact; import org.apache.archiva.rest.api.model.Dependency; +import org.apache.archiva.rest.api.model.SearchRequest; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.SearchService; import org.apache.archiva.security.AccessDeniedException; @@ -108,8 +109,28 @@ public class DefaultSearchService log.error( e.getMessage(), e ); throw new ArchivaRestServiceException( e.getMessage() ); } + } + public List searchArtifacts( SearchRequest searchRequest ) + throws ArchivaRestServiceException + { + if ( searchRequest == null ) + { + return Collections.emptyList(); + } + SearchFields searchField = new BeanReplicator().replicateBean( searchRequest, SearchFields.class ); + SearchResultLimits limits = new SearchResultLimits( 0 ); + try + { + SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, limits ); + return getArtifacts( searchResults ); + } + catch ( RepositorySearchException e ) + { + log.error( e.getMessage(), e ); + throw new ArchivaRestServiceException( e.getMessage() ); + } } public List getDependencies( String groupId, String artifactId, String version ) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java index 38630a698..4878ff3f1 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java @@ -20,6 +20,7 @@ package org.apache.archiva.rest.services; import org.apache.archiva.rest.api.model.Artifact; import org.apache.archiva.rest.api.model.ManagedRepository; +import org.apache.archiva.rest.api.model.SearchRequest; import org.apache.archiva.rest.api.services.ManagedRepositoriesService; import org.apache.archiva.rest.api.services.SearchService; import org.apache.commons.io.FileUtils; @@ -86,6 +87,36 @@ public class SearchServiceTest deleteTestRepo( testRepoId, targetRepo ); } + @Test + public void searchWithSearchRequestGroupIdAndArtifactId() + throws Exception + { + + String testRepoId = "test-repo"; + // force guest user creation if not exists + if ( getUserService( authorizationHeader ).getGuestUser() == null ) + { + assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); + } + + File targetRepo = createAndIndexRepo( testRepoId ); + + SearchService searchService = getSearchService( authorizationHeader ); + + SearchRequest searchRequest = new SearchRequest( ); + searchRequest.setGroupId( "commons-logging" ); + searchRequest.setArtifactId( "commons-logging" ); + searchRequest.setClassifier( "sources" ); + + List artifacts = searchService.searchArtifacts( searchRequest ); + + assertNotNull( artifacts ); + assertTrue( " empty results for commons-logging search", artifacts.size() == 6 ); + log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts ); + + deleteTestRepo( testRepoId, targetRepo ); + } + private File createAndIndexRepo( String testRepoId ) throws Exception {