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
<scope>compile</scope> | <scope>compile</scope> | ||||
</dependency> | </dependency> | ||||
<dependency> | <dependency> | ||||
<groupId>org.sonatype.nexus</groupId> | |||||
<artifactId>nexus-indexer</artifactId> | |||||
<groupId>org.apache.maven.indexer</groupId> | |||||
<artifactId>indexer-core</artifactId> | |||||
</dependency> | </dependency> | ||||
<dependency> | <dependency> | ||||
<groupId>javax.inject</groupId> | <groupId>javax.inject</groupId> |
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.List; | 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 | * ArchivaNexusIndexerUtil |
<artifactId>commons-io</artifactId> | <artifactId>commons-io</artifactId> | ||||
</dependency> | </dependency> | ||||
<dependency> | <dependency> | ||||
<groupId>org.sonatype.nexus</groupId> | |||||
<artifactId>nexus-indexer</artifactId> | |||||
<groupId>org.apache.maven.indexer</groupId> | |||||
<artifactId>indexer-core</artifactId> | |||||
</dependency> | </dependency> | ||||
<dependency> | <dependency> | ||||
<groupId>javax.inject</groupId> | <groupId>javax.inject</groupId> |
<artifactId>commons-io</artifactId> | <artifactId>commons-io</artifactId> | ||||
</dependency> | </dependency> | ||||
<dependency> | <dependency> | ||||
<groupId>org.sonatype.nexus</groupId> | |||||
<artifactId>nexus-indexer</artifactId> | |||||
<groupId>org.apache.maven.indexer</groupId> | |||||
<artifactId>indexer-core</artifactId> | |||||
</dependency> | </dependency> | ||||
<dependency> | <dependency> | ||||
<groupId>org.sonatype.sisu</groupId> | <groupId>org.sonatype.sisu</groupId> |
import org.apache.maven.archiva.configuration.ArchivaConfiguration; | import org.apache.maven.archiva.configuration.ArchivaConfiguration; | ||||
import org.apache.maven.archiva.configuration.Configuration; | import org.apache.maven.archiva.configuration.Configuration; | ||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; | 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.Logger; | ||||
import org.slf4j.LoggerFactory; | 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.context.annotation.Scope; | ||||
import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
BooleanQuery q = new BooleanQuery(); | BooleanQuery q = new BooleanQuery(); | ||||
if ( searchFields.getGroupId() != null && !"".equals( searchFields.getGroupId() ) ) | 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() ) ) | 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() ) ) | 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() ) ) | 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() ) ) | 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 ) | if ( q.getClauses() == null || q.getClauses().length <= 0 ) | ||||
private void constructQuery( String term, BooleanQuery q ) | 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 ); | |||||
} | } | ||||
~ specific language governing permissions and limitations | ~ specific language governing permissions and limitations | ||||
~ under the License. | ~ under the License. | ||||
--> | --> | ||||
<component-set> | <component-set> | ||||
<!-- | |||||
<components> | <components> | ||||
<component> | <component> | ||||
<role>org.sonatype.nexus.index.NexusIndexer</role> | |||||
<role>org.apache.maven.index.NexusIndexer</role> | |||||
<role-hint>archiva</role-hint> | <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> | <description>The default nexus indexer implementation.</description> | ||||
<instantiation-strategy>per-lookup</instantiation-strategy> | |||||
<isolated-realm>false</isolated-realm> | |||||
<requirements> | <requirements> | ||||
<requirement> | <requirement> | ||||
<role>org.sonatype.nexus.index.scan.Scanner</role> | |||||
<role>org.apache.maven.index.scan.Scanner</role> | |||||
<role-hint>default</role-hint> | <role-hint>default</role-hint> | ||||
<field-name>scanner</field-name> | <field-name>scanner</field-name> | ||||
</requirement> | </requirement> | ||||
<requirement> | <requirement> | ||||
<role>org.sonatype.nexus.index.search.SearchEngine</role> | |||||
<role>org.apache.maven.index.SearchEngine</role> | |||||
<role-hint>default</role-hint> | <role-hint>default</role-hint> | ||||
<field-name>searcher</field-name> | <field-name>searcher</field-name> | ||||
</requirement> | </requirement> | ||||
<requirement> | <requirement> | ||||
<role>org.sonatype.nexus.index.creator.IndexerEngine</role> | |||||
<role>org.apache.maven.index.IndexerEngine</role> | |||||
<role-hint>default</role-hint> | <role-hint>default</role-hint> | ||||
<field-name>indexerEngine</field-name> | <field-name>indexerEngine</field-name> | ||||
</requirement> | </requirement> | ||||
<requirement> | <requirement> | ||||
<role>org.sonatype.nexus.index.QueryCreator</role> | |||||
<role>org.apache.maven.index.QueryCreator</role> | |||||
<role-hint>default</role-hint> | <role-hint>default</role-hint> | ||||
<field-name>queryCreator</field-name> | <field-name>queryCreator</field-name> | ||||
</requirement> | </requirement> | ||||
</requirements> | </requirements> | ||||
</component> | </component> | ||||
</components> | </components> | ||||
--> | |||||
</component-set> | </component-set> |
import org.apache.maven.archiva.configuration.ArchivaConfiguration; | import org.apache.maven.archiva.configuration.ArchivaConfiguration; | ||||
import org.apache.maven.archiva.configuration.Configuration; | import org.apache.maven.archiva.configuration.Configuration; | ||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; | 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.easymock.MockControl; | ||||
import org.junit.After; | import org.junit.After; | ||||
import org.junit.Before; | import org.junit.Before; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.junit.runner.RunWith; | 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.ContextConfiguration; | ||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||||
private ArchivaConfiguration archivaConfig; | private ArchivaConfiguration archivaConfig; | ||||
private NexusIndexer indexer; | |||||
//private DefaultIndexingContext context; | |||||
private IndexingContext context; | |||||
private IndexerEngine indexerEngine; | |||||
//private IndexerEngine indexerEngine; | |||||
private ArtifactContextProducer artifactContextProducer; | private ArtifactContextProducer artifactContextProducer; | ||||
private Configuration config; | 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 | @Inject | ||||
PlexusSisuBridge plexusSisuBridge; | PlexusSisuBridge plexusSisuBridge; | ||||
NexusIndexer nexusIndexer; | |||||
@Before | @Before | ||||
public void setUp() | public void setUp() | ||||
throws Exception | throws Exception | ||||
{ | { | ||||
super.setUp(); | 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 ); | archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class ); | ||||
search = new NexusRepositorySearch( plexusSisuBridge, archivaConfig ); | 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 ); | artifactContextProducer = plexusSisuBridge.lookup( ArtifactContextProducer.class ); | ||||
public void tearDown() | public void tearDown() | ||||
throws Exception | 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() ); | 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() ); | assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() ); | ||||
super.tearDown(); | super.tearDown(); | ||||
private void createIndex( String repository, List<File> filesToBeIndexed ) | private void createIndex( String repository, List<File> filesToBeIndexed ) | ||||
throws IOException, UnsupportedExistingLuceneIndexException, IllegalArtifactCoordinateException | 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, | context = new DefaultIndexingContext( repository, repository, | ||||
new File( FileUtil.getBasedir(), "/target/test-classes/" + repository ), | new File( FileUtil.getBasedir(), "/target/test-classes/" + repository ), | ||||
new File( FileUtil.getBasedir(), | new File( FileUtil.getBasedir(), | ||||
"/target/test-classes/" + repository + "/.indexer" ), null, | "/target/test-classes/" + repository + "/.indexer" ), null, | ||||
null, ArchivaNexusIndexerUtil.FULL_INDEX, false ); | 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 ); | 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 ) | for ( File artifactFile : filesToBeIndexed ) | ||||
{ | { | ||||
ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile ); | 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() ); | assertTrue( new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" ).exists() ); | ||||
} | } | ||||
<artifactId>archiva-configuration</artifactId> | <artifactId>archiva-configuration</artifactId> | ||||
</dependency> | </dependency> | ||||
<dependency> | <dependency> | ||||
<groupId>org.sonatype.nexus</groupId> | |||||
<artifactId>nexus-indexer</artifactId> | |||||
<groupId>org.apache.maven.indexer</groupId> | |||||
<artifactId>indexer-core</artifactId> | |||||
</dependency> | </dependency> | ||||
<dependency> | <dependency> | ||||
<groupId>javax.inject</groupId> | <groupId>javax.inject</groupId> |
<jackrabbit.version>2.2.5</jackrabbit.version> | <jackrabbit.version>2.2.5</jackrabbit.version> | ||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||||
<surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile> | <surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile> | ||||
<lucene.version>2.4.1</lucene.version> | |||||
<lucene.version>3.0.3</lucene.version> | |||||
</properties> | </properties> | ||||
<dependencyManagement> | <dependencyManagement> | ||||
<version>1.4-SNAPSHOT</version> | <version>1.4-SNAPSHOT</version> | ||||
</dependency> | </dependency> | ||||
<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> | <exclusions> | ||||
<exclusion> | <exclusion> | ||||
<groupId>org.codehaus.plexus</groupId> | <groupId>org.codehaus.plexus</groupId> |