From 1776b31a4b47e2a9a8b7d83425de2c786d35e52c Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 15 Aug 2011 22:17:08 +0000 Subject: [PATCH] cleanup creation of IndexCreator with using the container rather than using default constructors git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1158035 13f79535-47bb-0310-9956-ffa450edef68 --- .../common/utils/ArchivaNexusIndexerUtil.java | 42 ------------------- .../lucene/NexusIndexerConsumer.java | 6 ++- .../indexer/search/NexusRepositorySearch.java | 14 ++++++- .../search/AbstractNexusRepositorySearch.java | 6 +-- .../search/NexusRepositorySearchTest.java | 15 ------- .../indexing/ArchivaIndexingTaskExecutor.java | 8 +++- .../indexing/ArtifactIndexingTask.java | 8 ++-- .../ArchivaIndexingTaskExecutorTest.java | 8 ++-- 8 files changed, 35 insertions(+), 72 deletions(-) delete mode 100644 archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/ArchivaNexusIndexerUtil.java 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 deleted file mode 100644 index cd01c37e9..000000000 --- a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/ArchivaNexusIndexerUtil.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.apache.maven.archiva.common.utils; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -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; -import org.apache.maven.index.creator.OSGIArtifactIndexCreator; - -import java.util.Arrays; -import java.util.List; - -/** - * ArchivaNexusIndexerUtil - */ -public class ArchivaNexusIndexerUtil -{ - // FIXME olamy use lookup mechanism from plexus/sisu as here some possible injections can fail ! - - public static final List FULL_INDEX = - Arrays.asList( new MinimalArtifactInfoIndexCreator(), new JarFileContentsIndexCreator(), - new MavenPluginArtifactInfoIndexCreator(), new OSGIArtifactIndexCreator() ); - -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java index 075a16289..ccdb2c493 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java @@ -38,6 +38,7 @@ import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; import org.apache.maven.archiva.consumers.ConsumerException; import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.maven.index.NexusIndexer; +import org.apache.maven.index.context.IndexCreator; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; @@ -73,6 +74,8 @@ public class NexusIndexerConsumer private ManagedRepositoryConfiguration repository; + private List allIndexCreators; + public NexusIndexerConsumer( ArchivaTaskScheduler scheduler, ArchivaConfiguration configuration, FileTypes filetypes, PlexusSisuBridge plexusSisuBridge ) throws PlexusSisuBridgeException @@ -81,6 +84,7 @@ public class NexusIndexerConsumer this.filetypes = filetypes; this.scheduler = scheduler; this.nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); + this.allIndexCreators = plexusSisuBridge.lookupList( IndexCreator.class ); } public String getDescription() @@ -107,7 +111,7 @@ public class NexusIndexerConsumer try { log.info( "Creating indexing context for repo : " + repository.getId() ); - context = ArtifactIndexingTask.createContext( repository, nexusIndexer ); + context = ArtifactIndexingTask.createContext( repository, nexusIndexer, allIndexCreators ); } catch ( IOException e ) { 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 a189384dd..a22b599e9 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 @@ -25,7 +25,6 @@ import org.apache.archiva.indexer.util.SearchUtil; import org.apache.commons.lang.StringUtils; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; -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; @@ -35,6 +34,7 @@ import org.apache.maven.index.FlatSearchResponse; import org.apache.maven.index.MAVEN; import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.OSGI; +import org.apache.maven.index.context.IndexCreator; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.apache.maven.index.expr.StringSearchExpression; @@ -62,12 +62,15 @@ public class NexusRepositorySearch private ArchivaConfiguration archivaConfig; + private List allIndexCreators; + @Inject public NexusRepositorySearch( PlexusSisuBridge plexusSisuBridge, ArchivaConfiguration archivaConfig ) throws PlexusSisuBridgeException { this.indexer = plexusSisuBridge.lookup( NexusIndexer.class ); this.archivaConfig = archivaConfig; + allIndexCreators = plexusSisuBridge.lookupList( IndexCreator.class ); } /** @@ -274,7 +277,7 @@ public class NexusRepositorySearch IndexingContext context = indexer.addIndexingContext( repoConfig.getId(), repoConfig.getId(), new File( repoConfig.getLocation() ), indexDirectory, null, null, - ArchivaNexusIndexerUtil.FULL_INDEX ); + getAllIndexCreators() ); context.setSearchable( repoConfig.isScanned() ); } else @@ -295,6 +298,13 @@ public class NexusRepositorySearch } } + + protected List getAllIndexCreators() + { + return allIndexCreators; + } + + private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits ) { SearchResults results = new SearchResults(); 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 ea2a1a0e1..ef493bdab 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 @@ -22,7 +22,6 @@ package org.apache.archiva.indexer.search; import junit.framework.TestCase; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.commons.io.FileUtils; -import org.apache.maven.archiva.common.utils.ArchivaNexusIndexerUtil; import org.apache.maven.archiva.common.utils.FileUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; @@ -30,7 +29,6 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.index.ArtifactContext; import org.apache.maven.index.ArtifactContextProducer; import org.apache.maven.index.NexusIndexer; -import org.apache.maven.index.artifact.IllegalArtifactCoordinateException; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.easymock.MockControl; @@ -59,7 +57,7 @@ public abstract class AbstractNexusRepositorySearch public static String TEST_REPO_2 = "nexus-search-test-repo-2"; - RepositorySearch search; + NexusRepositorySearch search; ArchivaConfiguration archivaConfig; @@ -166,7 +164,7 @@ public abstract class AbstractNexusRepositorySearch IndexingContext context = nexusIndexer.addIndexingContext( repository, repository, repo, indexDirectory, repo.toURI().toURL().toExternalForm(), indexDirectory.toURI().toURL().toString(), - ArchivaNexusIndexerUtil.FULL_INDEX ); + search.getAllIndexCreators() ); List artifactContexts = new ArrayList( filesToBeIndexed.size() ); for ( File artifactFile : filesToBeIndexed ) 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 da2a5d396..e2ded80ee 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 @@ -19,23 +19,9 @@ package org.apache.archiva.indexer.search; * under the License. */ -import junit.framework.TestCase; -import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; -import org.apache.commons.io.FileUtils; -import org.apache.maven.archiva.common.utils.ArchivaNexusIndexerUtil; 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.NexusIndexer; import org.apache.maven.index.artifact.IllegalArtifactCoordinateException; -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.springframework.test.context.ContextConfiguration; @@ -46,7 +32,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import javax.inject.Inject; @RunWith( SpringJUnit4ClassRunner.class ) diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java index f0643df8b..ba1988a7b 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java @@ -32,6 +32,7 @@ import org.apache.maven.index.FlatSearchResponse; import org.apache.maven.index.MAVEN; import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.artifact.IllegalArtifactCoordinateException; +import org.apache.maven.index.context.IndexCreator; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.apache.maven.index.expr.SourcedSearchExpression; @@ -48,6 +49,7 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; import java.io.File; import java.io.IOException; +import java.util.List; /** * ArchivaIndexingTaskExecutor Executes all indexing tasks. Adding, updating and removing artifacts from the index are @@ -75,6 +77,8 @@ public class ArchivaIndexingTaskExecutor private NexusIndexer nexusIndexer; + private List allIndexCreators; + @PostConstruct public void initialize() throws PlexusSisuBridgeException @@ -86,6 +90,8 @@ public class ArchivaIndexingTaskExecutor indexPacker = plexusSisuBridge.lookup( IndexPacker.class, "default" ); nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); + + allIndexCreators = plexusSisuBridge.lookupList( IndexCreator.class ); } public void executeTask( Task task ) @@ -113,7 +119,7 @@ public class ArchivaIndexingTaskExecutor { log.debug( "Creating indexing context on resource: {}", indexingTask.getResourceFile().getPath() ); - context = ArtifactIndexingTask.createContext( repository, nexusIndexer ); + context = ArtifactIndexingTask.createContext( repository, nexusIndexer, allIndexCreators ); } catch ( IOException e ) { diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java index 15a07752e..7d07560a1 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java @@ -19,9 +19,9 @@ package org.apache.archiva.scheduler.indexing; * under the License. */ -import org.apache.maven.archiva.common.utils.ArchivaNexusIndexerUtil; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.index.NexusIndexer; +import org.apache.maven.index.context.IndexCreator; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.codehaus.plexus.taskqueue.Task; @@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; +import java.util.List; public class ArtifactIndexingTask implements Task @@ -157,7 +158,8 @@ public class ArtifactIndexingTask return true; } - public static IndexingContext createContext( ManagedRepositoryConfiguration repository, NexusIndexer indexer ) + public static IndexingContext createContext( ManagedRepositoryConfiguration repository, NexusIndexer indexer, + List indexCreators ) throws IOException, UnsupportedExistingLuceneIndexException { String indexDir = repository.getIndexDir(); @@ -182,7 +184,7 @@ public class ArtifactIndexingTask IndexingContext context = indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory, managedRepository.toURI().toURL().toString(), - indexDirectory.toURI().toURL().toString(), ArchivaNexusIndexerUtil.FULL_INDEX ); + indexDirectory.toURI().toURL().toString(), indexCreators ); context.setSearchable( repository.isScanned() ); return context; diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java index 0ad3c678b..4c312da0c 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java @@ -26,7 +26,6 @@ import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.TopDocs; -import org.apache.maven.archiva.common.utils.ArchivaNexusIndexerUtil; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.index.ArtifactInfo; @@ -34,6 +33,7 @@ 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.IndexCreator; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.expr.SourcedSearchExpression; import org.apache.maven.index.expr.StringSearchExpression; @@ -96,7 +96,8 @@ public class ArchivaIndexingTaskExecutorTest indexer = plexusSisuBridge.lookup( NexusIndexer.class ); - ArtifactIndexingTask.createContext( repositoryConfig, indexer ); + ArtifactIndexingTask.createContext( repositoryConfig, indexer, + plexusSisuBridge.lookupList( IndexCreator.class ) ); } @After @@ -152,7 +153,7 @@ public class ArchivaIndexingTaskExecutorTest new File( repositoryConfig.getLocation() ), new File( repositoryConfig.getLocation(), ".indexer" ), null, null, - ArchivaNexusIndexerUtil.FULL_INDEX ); + plexusSisuBridge.lookupList( IndexCreator.class ) ); context.setSearchable( true ); } @@ -297,7 +298,6 @@ public class ArchivaIndexingTaskExecutorTest indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ), Occur.SHOULD ); - FlatSearchRequest request = new FlatSearchRequest( q, getIndexingContext() ); FlatSearchResponse response = indexer.searchFlat( request );