remove the per-lookup component refactor test to use only NexusIndexer facade git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1139940 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.4-M1
@@ -57,8 +57,8 @@ | |||
<scope>compile</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.sonatype.nexus</groupId> | |||
<artifactId>nexus-indexer</artifactId> | |||
<groupId>org.apache.maven.indexer</groupId> | |||
<artifactId>indexer-core</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>javax.inject</groupId> |
@@ -22,10 +22,10 @@ package org.apache.maven.archiva.common.utils; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import org.sonatype.nexus.index.context.IndexCreator; | |||
import org.sonatype.nexus.index.creator.JarFileContentsIndexCreator; | |||
import org.sonatype.nexus.index.creator.MavenPluginArtifactInfoIndexCreator; | |||
import org.sonatype.nexus.index.creator.MinimalArtifactInfoIndexCreator; | |||
import org.apache.maven.index.context.IndexCreator; | |||
import org.apache.maven.index.creator.JarFileContentsIndexCreator; | |||
import org.apache.maven.index.creator.MavenPluginArtifactInfoIndexCreator; | |||
import org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator; | |||
/** | |||
* ArchivaNexusIndexerUtil |
@@ -63,8 +63,8 @@ | |||
<artifactId>commons-io</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.sonatype.nexus</groupId> | |||
<artifactId>nexus-indexer</artifactId> | |||
<groupId>org.apache.maven.indexer</groupId> | |||
<artifactId>indexer-core</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>javax.inject</groupId> |
@@ -63,8 +63,8 @@ | |||
<artifactId>commons-io</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.sonatype.nexus</groupId> | |||
<artifactId>nexus-indexer</artifactId> | |||
<groupId>org.apache.maven.indexer</groupId> | |||
<artifactId>indexer-core</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.sonatype.sisu</groupId> |
@@ -28,14 +28,17 @@ import org.apache.maven.archiva.common.utils.ArchivaNexusIndexerUtil; | |||
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.ArtifactInfo; | |||
import org.apache.maven.index.Field; | |||
import org.apache.maven.index.FlatSearchRequest; | |||
import org.apache.maven.index.FlatSearchResponse; | |||
import org.apache.maven.index.MAVEN; | |||
import org.apache.maven.index.NexusIndexer; | |||
import org.apache.maven.index.context.IndexingContext; | |||
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; | |||
import org.apache.maven.index.expr.StringSearchExpression; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonatype.nexus.index.ArtifactInfo; | |||
import org.sonatype.nexus.index.FlatSearchRequest; | |||
import org.sonatype.nexus.index.FlatSearchResponse; | |||
import org.sonatype.nexus.index.NexusIndexer; | |||
import org.sonatype.nexus.index.context.IndexingContext; | |||
import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException; | |||
import org.springframework.context.annotation.Scope; | |||
import org.springframework.stereotype.Service; | |||
@@ -120,27 +123,27 @@ public class NexusRepositorySearch | |||
BooleanQuery q = new BooleanQuery(); | |||
if ( searchFields.getGroupId() != null && !"".equals( searchFields.getGroupId() ) ) | |||
{ | |||
q.add( indexer.constructQuery( ArtifactInfo.GROUP_ID, searchFields.getGroupId() ), Occur.MUST ); | |||
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( searchFields.getGroupId() ) ), Occur.MUST ); | |||
} | |||
if ( searchFields.getArtifactId() != null && !"".equals( searchFields.getArtifactId() ) ) | |||
{ | |||
q.add( indexer.constructQuery( ArtifactInfo.ARTIFACT_ID, searchFields.getArtifactId() ), Occur.MUST ); | |||
q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( searchFields.getArtifactId() ) ), Occur.MUST ); | |||
} | |||
if ( searchFields.getVersion() != null && !"".equals( searchFields.getVersion() ) ) | |||
{ | |||
q.add( indexer.constructQuery( ArtifactInfo.VERSION, searchFields.getVersion() ), Occur.MUST ); | |||
q.add( indexer.constructQuery( MAVEN.VERSION, new StringSearchExpression( searchFields.getVersion() ) ), Occur.MUST ); | |||
} | |||
if ( searchFields.getPackaging() != null && !"".equals( searchFields.getPackaging() ) ) | |||
{ | |||
q.add( indexer.constructQuery( ArtifactInfo.PACKAGING, searchFields.getPackaging() ), Occur.MUST ); | |||
q.add( indexer.constructQuery( MAVEN.PACKAGING, new StringSearchExpression( searchFields.getPackaging() ) ), Occur.MUST ); | |||
} | |||
if ( searchFields.getClassName() != null && !"".equals( searchFields.getClassName() ) ) | |||
{ | |||
q.add( indexer.constructQuery( ArtifactInfo.NAMES, searchFields.getClassName() ), Occur.MUST ); | |||
q.add( indexer.constructQuery( MAVEN.CLASSNAMES, new StringSearchExpression( searchFields.getClassName( ) ) ), Occur.MUST ); | |||
} | |||
if ( q.getClauses() == null || q.getClauses().length <= 0 ) | |||
@@ -194,11 +197,11 @@ public class NexusRepositorySearch | |||
private void constructQuery( String term, BooleanQuery q ) | |||
{ | |||
q.add( indexer.constructQuery( ArtifactInfo.GROUP_ID, term ), Occur.SHOULD ); | |||
q.add( indexer.constructQuery( ArtifactInfo.ARTIFACT_ID, term ), Occur.SHOULD ); | |||
q.add( indexer.constructQuery( ArtifactInfo.VERSION, term ), Occur.SHOULD ); | |||
q.add( indexer.constructQuery( ArtifactInfo.PACKAGING, term ), Occur.SHOULD ); | |||
q.add( indexer.constructQuery( ArtifactInfo.NAMES, term ), Occur.SHOULD ); | |||
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( term ) ), Occur.SHOULD ); | |||
q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( term ) ), Occur.SHOULD ); | |||
q.add( indexer.constructQuery( MAVEN.VERSION, new StringSearchExpression( term ) ), Occur.SHOULD ); | |||
q.add( indexer.constructQuery( MAVEN.PACKAGING, new StringSearchExpression( term ) ), Occur.SHOULD ); | |||
q.add( indexer.constructQuery( MAVEN.CLASSNAMES, new StringSearchExpression( term ) ), Occur.SHOULD ); | |||
} | |||
@@ -17,39 +17,37 @@ | |||
~ specific language governing permissions and limitations | |||
~ under the License. | |||
--> | |||
<component-set> | |||
<!-- | |||
<components> | |||
<component> | |||
<role>org.sonatype.nexus.index.NexusIndexer</role> | |||
<role>org.apache.maven.index.NexusIndexer</role> | |||
<role-hint>archiva</role-hint> | |||
<implementation>org.sonatype.nexus.index.DefaultNexusIndexer</implementation> | |||
<implementation>org.apache.maven.index.DefaultNexusIndexer</implementation> | |||
<description>The default nexus indexer implementation.</description> | |||
<instantiation-strategy>per-lookup</instantiation-strategy> | |||
<isolated-realm>false</isolated-realm> | |||
<requirements> | |||
<requirement> | |||
<role>org.sonatype.nexus.index.scan.Scanner</role> | |||
<role>org.apache.maven.index.scan.Scanner</role> | |||
<role-hint>default</role-hint> | |||
<field-name>scanner</field-name> | |||
</requirement> | |||
<requirement> | |||
<role>org.sonatype.nexus.index.search.SearchEngine</role> | |||
<role>org.apache.maven.index.SearchEngine</role> | |||
<role-hint>default</role-hint> | |||
<field-name>searcher</field-name> | |||
</requirement> | |||
<requirement> | |||
<role>org.sonatype.nexus.index.creator.IndexerEngine</role> | |||
<role>org.apache.maven.index.IndexerEngine</role> | |||
<role-hint>default</role-hint> | |||
<field-name>indexerEngine</field-name> | |||
</requirement> | |||
<requirement> | |||
<role>org.sonatype.nexus.index.QueryCreator</role> | |||
<role>org.apache.maven.index.QueryCreator</role> | |||
<role-hint>default</role-hint> | |||
<field-name>queryCreator</field-name> | |||
</requirement> | |||
</requirements> | |||
</component> | |||
</components> | |||
--> | |||
</component-set> |
@@ -27,19 +27,19 @@ 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.IndexerEngine; | |||
import org.apache.maven.index.NexusIndexer; | |||
import org.apache.maven.index.artifact.IllegalArtifactCoordinateException; | |||
import org.apache.maven.index.context.DefaultIndexingContext; | |||
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.Test; | |||
import org.junit.runner.RunWith; | |||
import org.sonatype.nexus.artifact.IllegalArtifactCoordinateException; | |||
import org.sonatype.nexus.index.ArtifactContext; | |||
import org.sonatype.nexus.index.ArtifactContextProducer; | |||
import org.sonatype.nexus.index.IndexerEngine; | |||
import org.sonatype.nexus.index.NexusIndexer; | |||
import org.sonatype.nexus.index.context.DefaultIndexingContext; | |||
import org.sonatype.nexus.index.context.IndexingContext; | |||
import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException; | |||
import org.springframework.test.context.ContextConfiguration; | |||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |||
@@ -59,11 +59,9 @@ public class NexusRepositorySearchTest | |||
private ArchivaConfiguration archivaConfig; | |||
private NexusIndexer indexer; | |||
//private DefaultIndexingContext context; | |||
private IndexingContext context; | |||
private IndexerEngine indexerEngine; | |||
//private IndexerEngine indexerEngine; | |||
private ArtifactContextProducer artifactContextProducer; | |||
@@ -71,20 +69,40 @@ public class NexusRepositorySearchTest | |||
private Configuration config; | |||
private final static String TEST_REPO_1 = "nexus-search-test-repo"; | |||
private static String TEST_REPO_1 = "nexus-search-test-repo"; | |||
private static String TEST_REPO_2 = "nexus-search-test-repo-2"; | |||
private final static String TEST_REPO_2 = "nexus-search-test-repo-2"; | |||
private static int TEST_NUMBER = 0; | |||
@Inject | |||
PlexusSisuBridge plexusSisuBridge; | |||
NexusIndexer nexusIndexer; | |||
@Before | |||
public void setUp() | |||
throws Exception | |||
{ | |||
super.setUp(); | |||
indexer = plexusSisuBridge.lookup( NexusIndexer.class ); | |||
//to prevent failure during obtain lock change name | |||
System.gc(); | |||
TEST_NUMBER++; | |||
//TEST_REPO_1 = TEST_REPO_1 + TEST_NUMBER; | |||
//TEST_REPO_2 = TEST_REPO_2 + TEST_NUMBER; | |||
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() ); | |||
archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class ); | |||
@@ -92,7 +110,9 @@ public class NexusRepositorySearchTest | |||
search = new NexusRepositorySearch( plexusSisuBridge, archivaConfig ); | |||
indexerEngine = plexusSisuBridge.lookup( IndexerEngine.class ); | |||
//indexerEngine = plexusSisuBridge.lookup( IndexerEngine.class ); | |||
nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); | |||
artifactContextProducer = plexusSisuBridge.lookup( ArtifactContextProducer.class ); | |||
@@ -155,10 +175,30 @@ public class NexusRepositorySearchTest | |||
public void tearDown() | |||
throws Exception | |||
{ | |||
FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) ); | |||
/* | |||
if ( context != null ) | |||
{ | |||
context.unlock(); | |||
context.unlockExclusively(); | |||
context.close( true ); | |||
} | |||
*/ | |||
for (IndexingContext indexingContext : nexusIndexer.getIndexingContexts().values()) | |||
{ | |||
//indexingContext.close( true ); | |||
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" ) ); | |||
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(); | |||
@@ -167,28 +207,57 @@ public class NexusRepositorySearchTest | |||
private void createIndex( String repository, List<File> filesToBeIndexed ) | |||
throws IOException, UnsupportedExistingLuceneIndexException, IllegalArtifactCoordinateException | |||
{ | |||
File indexerDirectory = new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" ); | |||
if ( indexerDirectory.exists() ) | |||
{ | |||
FileUtils.deleteDirectory( indexerDirectory ); | |||
} | |||
assertFalse( indexerDirectory.exists() ); | |||
File lockFile = | |||
new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer/write.lock" ); | |||
if ( lockFile.exists() ) | |||
{ | |||
lockFile.delete(); | |||
} | |||
//IndexWriter.unlock( FSDirectory.open( lockFile.getParentFile()) ); | |||
assertFalse( lockFile.exists() ); | |||
/* | |||
context = new DefaultIndexingContext( repository, repository, | |||
new File( FileUtil.getBasedir(), "/target/test-classes/" + repository ), | |||
new File( FileUtil.getBasedir(), | |||
"/target/test-classes/" + repository + "/.indexer" ), null, | |||
null, ArchivaNexusIndexerUtil.FULL_INDEX, false ); | |||
//indexer.addIndexingContext( repository, repository, new File( getBasedir(), "/target/test-classes/" + | |||
// repository ), new File( getBasedir(), "/target/test-classes/" + repository + "/.indexer" ), null, null, | |||
// NexusIndexer.FULL_INDEX ); | |||
context.setSearchable( true ); | |||
*/ | |||
File repo = new File( FileUtil.getBasedir(), "/target/test-classes/" + repository ); | |||
File indexDirectory = new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" ); | |||
//indexerEngine.beginIndexing( context ); | |||
//String id, String repositoryId, File repository, File indexDirectory, | |||
// String repositoryUrl, String indexUpdateUrl, | |||
// List<? extends IndexCreator > indexers | |||
IndexingContext context = nexusIndexer.addIndexingContext( repository, repository, repo, indexDirectory, | |||
repo.toURI().toURL().toExternalForm(), | |||
indexDirectory.toURI().toURL().toString(), ArchivaNexusIndexerUtil.FULL_INDEX ); | |||
List<ArtifactContext> artifactContexts = new ArrayList<ArtifactContext>( filesToBeIndexed.size() ); | |||
for ( File artifactFile : filesToBeIndexed ) | |||
{ | |||
ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile ); | |||
indexerEngine.index( context, ac ); | |||
artifactContexts.add( ac ); | |||
} | |||
context.close( false ); | |||
//indexerEngine.endIndexing( context ); | |||
//indexer.removeIndexingContext( context, false ); | |||
nexusIndexer.addArtifactsToIndex( artifactContexts, context ); | |||
nexusIndexer.scan( context ); | |||
//context.close( false ); | |||
assertTrue( new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" ).exists() ); | |||
} | |||
@@ -19,8 +19,8 @@ | |||
<artifactId>archiva-configuration</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.sonatype.nexus</groupId> | |||
<artifactId>nexus-indexer</artifactId> | |||
<groupId>org.apache.maven.indexer</groupId> | |||
<artifactId>indexer-core</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>javax.inject</groupId> |
@@ -74,7 +74,7 @@ | |||
<jackrabbit.version>2.2.5</jackrabbit.version> | |||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |||
<surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile> | |||
<lucene.version>2.4.1</lucene.version> | |||
<lucene.version>3.0.3</lucene.version> | |||
</properties> | |||
<dependencyManagement> | |||
@@ -235,9 +235,9 @@ | |||
<version>1.4-SNAPSHOT</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.sonatype.nexus</groupId> | |||
<artifactId>nexus-indexer</artifactId> | |||
<version>3.0.1</version> | |||
<groupId>org.apache.maven.indexer</groupId> | |||
<artifactId>indexer-core</artifactId> | |||
<version>4.1.1</version> | |||
<exclusions> | |||
<exclusion> | |||
<groupId>org.codehaus.plexus</groupId> |