diff options
author | Olivier Lamy <olamy@apache.org> | 2011-06-26 20:54:21 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2011-06-26 20:54:21 +0000 |
commit | a20d601f8e605ba62ffc74c8de94cc5a892c9d5b (patch) | |
tree | 97db55cee7f438ffbf49acd7ddbd643cd7cfbcfd /archiva-modules/archiva-base | |
parent | 1eeba6ab686fc141341c8c481a7b9e456f2d5856 (diff) | |
download | archiva-a20d601f8e605ba62ffc74c8de94cc5a892c9d5b.tar.gz archiva-a20d601f8e605ba62ffc74c8de94cc5a892c9d5b.zip |
[MRM-1345] update use of Nexus indexer to use Maven indexer
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-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base')
7 files changed, 132 insertions, 62 deletions
diff --git a/archiva-modules/archiva-base/archiva-common/pom.xml b/archiva-modules/archiva-base/archiva-common/pom.xml index 32ea5a0f1..158e11984 100644 --- a/archiva-modules/archiva-base/archiva-common/pom.xml +++ b/archiva-modules/archiva-base/archiva-common/pom.xml @@ -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> diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/ArchivaNexusIndexerUtil.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/ArchivaNexusIndexerUtil.java index ebac81159..98be33efd 100644 --- a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/ArchivaNexusIndexerUtil.java +++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/ArchivaNexusIndexerUtil.java @@ -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 diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/pom.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/pom.xml index 1cf58da2c..059f715bc 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/pom.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/pom.xml @@ -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> diff --git a/archiva-modules/archiva-base/archiva-indexer/pom.xml b/archiva-modules/archiva-base/archiva-indexer/pom.xml index 4a421f63d..61f449ee3 100644 --- a/archiva-modules/archiva-base/archiva-indexer/pom.xml +++ b/archiva-modules/archiva-base/archiva-indexer/pom.xml @@ -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> 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 2c72edc82..641c635a1 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 @@ -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 ); } diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/plexus/components.xml b/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/plexus/components.xml index 8e03700cc..a6d123f83 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/plexus/components.xml +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/plexus/components.xml @@ -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> 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 3b1a83da3..88c1da5d1 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 @@ -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() ); } |