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
This commit is contained in:
Olivier Lamy 2011-08-15 22:17:08 +00:00
parent 7a354f09ed
commit 1776b31a4b
8 changed files with 35 additions and 72 deletions

View File

@ -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<? extends IndexCreator> FULL_INDEX =
Arrays.<IndexCreator>asList( new MinimalArtifactInfoIndexCreator(), new JarFileContentsIndexCreator(),
new MavenPluginArtifactInfoIndexCreator(), new OSGIArtifactIndexCreator() );
}

View File

@ -38,6 +38,7 @@ import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
import org.apache.maven.archiva.consumers.ConsumerException; import org.apache.maven.archiva.consumers.ConsumerException;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.maven.index.NexusIndexer; 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.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
@ -73,6 +74,8 @@ public class NexusIndexerConsumer
private ManagedRepositoryConfiguration repository; private ManagedRepositoryConfiguration repository;
private List<IndexCreator> allIndexCreators;
public NexusIndexerConsumer( ArchivaTaskScheduler<ArtifactIndexingTask> scheduler, public NexusIndexerConsumer( ArchivaTaskScheduler<ArtifactIndexingTask> scheduler,
ArchivaConfiguration configuration, FileTypes filetypes, PlexusSisuBridge plexusSisuBridge ) ArchivaConfiguration configuration, FileTypes filetypes, PlexusSisuBridge plexusSisuBridge )
throws PlexusSisuBridgeException throws PlexusSisuBridgeException
@ -81,6 +84,7 @@ public class NexusIndexerConsumer
this.filetypes = filetypes; this.filetypes = filetypes;
this.scheduler = scheduler; this.scheduler = scheduler;
this.nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); this.nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
this.allIndexCreators = plexusSisuBridge.lookupList( IndexCreator.class );
} }
public String getDescription() public String getDescription()
@ -107,7 +111,7 @@ public class NexusIndexerConsumer
try try
{ {
log.info( "Creating indexing context for repo : " + repository.getId() ); log.info( "Creating indexing context for repo : " + repository.getId() );
context = ArtifactIndexingTask.createContext( repository, nexusIndexer ); context = ArtifactIndexingTask.createContext( repository, nexusIndexer, allIndexCreators );
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -25,7 +25,6 @@ import org.apache.archiva.indexer.util.SearchUtil;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery; 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.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;
@ -35,6 +34,7 @@ import org.apache.maven.index.FlatSearchResponse;
import org.apache.maven.index.MAVEN; import org.apache.maven.index.MAVEN;
import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.OSGI; 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.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.apache.maven.index.expr.StringSearchExpression; import org.apache.maven.index.expr.StringSearchExpression;
@ -62,12 +62,15 @@ public class NexusRepositorySearch
private ArchivaConfiguration archivaConfig; private ArchivaConfiguration archivaConfig;
private List<? extends IndexCreator> allIndexCreators;
@Inject @Inject
public NexusRepositorySearch( PlexusSisuBridge plexusSisuBridge, ArchivaConfiguration archivaConfig ) public NexusRepositorySearch( PlexusSisuBridge plexusSisuBridge, ArchivaConfiguration archivaConfig )
throws PlexusSisuBridgeException throws PlexusSisuBridgeException
{ {
this.indexer = plexusSisuBridge.lookup( NexusIndexer.class ); this.indexer = plexusSisuBridge.lookup( NexusIndexer.class );
this.archivaConfig = archivaConfig; this.archivaConfig = archivaConfig;
allIndexCreators = plexusSisuBridge.lookupList( IndexCreator.class );
} }
/** /**
@ -274,7 +277,7 @@ public class NexusRepositorySearch
IndexingContext context = indexer.addIndexingContext( repoConfig.getId(), repoConfig.getId(), IndexingContext context = indexer.addIndexingContext( repoConfig.getId(), repoConfig.getId(),
new File( repoConfig.getLocation() ), new File( repoConfig.getLocation() ),
indexDirectory, null, null, indexDirectory, null, null,
ArchivaNexusIndexerUtil.FULL_INDEX ); getAllIndexCreators() );
context.setSearchable( repoConfig.isScanned() ); context.setSearchable( repoConfig.isScanned() );
} }
else else
@ -295,6 +298,13 @@ public class NexusRepositorySearch
} }
} }
protected List<? extends IndexCreator> getAllIndexCreators()
{
return allIndexCreators;
}
private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits ) private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits )
{ {
SearchResults results = new SearchResults(); SearchResults results = new SearchResults();

View File

@ -22,7 +22,6 @@ package org.apache.archiva.indexer.search;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.io.FileUtils; 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.common.utils.FileUtil;
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;
@ -30,7 +29,6 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.index.ArtifactContext; import org.apache.maven.index.ArtifactContext;
import org.apache.maven.index.ArtifactContextProducer; import org.apache.maven.index.ArtifactContextProducer;
import org.apache.maven.index.NexusIndexer; 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.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.easymock.MockControl; import org.easymock.MockControl;
@ -59,7 +57,7 @@ public abstract class AbstractNexusRepositorySearch
public static String TEST_REPO_2 = "nexus-search-test-repo-2"; public static String TEST_REPO_2 = "nexus-search-test-repo-2";
RepositorySearch search; NexusRepositorySearch search;
ArchivaConfiguration archivaConfig; ArchivaConfiguration archivaConfig;
@ -166,7 +164,7 @@ public abstract class AbstractNexusRepositorySearch
IndexingContext context = nexusIndexer.addIndexingContext( repository, repository, repo, indexDirectory, IndexingContext context = nexusIndexer.addIndexingContext( repository, repository, repo, indexDirectory,
repo.toURI().toURL().toExternalForm(), repo.toURI().toURL().toExternalForm(),
indexDirectory.toURI().toURL().toString(), indexDirectory.toURI().toURL().toString(),
ArchivaNexusIndexerUtil.FULL_INDEX ); search.getAllIndexCreators() );
List<ArtifactContext> artifactContexts = new ArrayList<ArtifactContext>( filesToBeIndexed.size() ); List<ArtifactContext> artifactContexts = new ArrayList<ArtifactContext>( filesToBeIndexed.size() );
for ( File artifactFile : filesToBeIndexed ) for ( File artifactFile : filesToBeIndexed )

View File

@ -19,23 +19,9 @@ package org.apache.archiva.indexer.search;
* under the License. * 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.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.artifact.IllegalArtifactCoordinateException;
import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; 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.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
@ -46,7 +32,6 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.inject.Inject;
@RunWith( SpringJUnit4ClassRunner.class ) @RunWith( SpringJUnit4ClassRunner.class )

View File

@ -32,6 +32,7 @@ import org.apache.maven.index.FlatSearchResponse;
import org.apache.maven.index.MAVEN; import org.apache.maven.index.MAVEN;
import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.artifact.IllegalArtifactCoordinateException; 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.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.apache.maven.index.expr.SourcedSearchExpression; import org.apache.maven.index.expr.SourcedSearchExpression;
@ -48,6 +49,7 @@ import javax.annotation.PostConstruct;
import javax.inject.Inject; import javax.inject.Inject;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List;
/** /**
* ArchivaIndexingTaskExecutor Executes all indexing tasks. Adding, updating and removing artifacts from the index are * 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 NexusIndexer nexusIndexer;
private List<IndexCreator> allIndexCreators;
@PostConstruct @PostConstruct
public void initialize() public void initialize()
throws PlexusSisuBridgeException throws PlexusSisuBridgeException
@ -86,6 +90,8 @@ public class ArchivaIndexingTaskExecutor
indexPacker = plexusSisuBridge.lookup( IndexPacker.class, "default" ); indexPacker = plexusSisuBridge.lookup( IndexPacker.class, "default" );
nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
allIndexCreators = plexusSisuBridge.lookupList( IndexCreator.class );
} }
public void executeTask( Task task ) public void executeTask( Task task )
@ -113,7 +119,7 @@ public class ArchivaIndexingTaskExecutor
{ {
log.debug( "Creating indexing context on resource: {}", log.debug( "Creating indexing context on resource: {}",
indexingTask.getResourceFile().getPath() ); indexingTask.getResourceFile().getPath() );
context = ArtifactIndexingTask.createContext( repository, nexusIndexer ); context = ArtifactIndexingTask.createContext( repository, nexusIndexer, allIndexCreators );
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -19,9 +19,9 @@ package org.apache.archiva.scheduler.indexing;
* under the License. * under the License.
*/ */
import org.apache.maven.archiva.common.utils.ArchivaNexusIndexerUtil;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.index.NexusIndexer; 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.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.codehaus.plexus.taskqueue.Task; import org.codehaus.plexus.taskqueue.Task;
@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List;
public class ArtifactIndexingTask public class ArtifactIndexingTask
implements Task implements Task
@ -157,7 +158,8 @@ public class ArtifactIndexingTask
return true; return true;
} }
public static IndexingContext createContext( ManagedRepositoryConfiguration repository, NexusIndexer indexer ) public static IndexingContext createContext( ManagedRepositoryConfiguration repository, NexusIndexer indexer,
List<IndexCreator> indexCreators )
throws IOException, UnsupportedExistingLuceneIndexException throws IOException, UnsupportedExistingLuceneIndexException
{ {
String indexDir = repository.getIndexDir(); String indexDir = repository.getIndexDir();
@ -182,7 +184,7 @@ public class ArtifactIndexingTask
IndexingContext context = IndexingContext context =
indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory, indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
managedRepository.toURI().toURL().toString(), managedRepository.toURI().toURL().toString(),
indexDirectory.toURI().toURL().toString(), ArchivaNexusIndexerUtil.FULL_INDEX ); indexDirectory.toURI().toURL().toString(), indexCreators );
context.setSearchable( repository.isScanned() ); context.setSearchable( repository.isScanned() );
return context; return context;

View File

@ -26,7 +26,6 @@ import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.TopDocs; 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.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.ArtifactInfo;
@ -34,6 +33,7 @@ import org.apache.maven.index.FlatSearchRequest;
import org.apache.maven.index.FlatSearchResponse; import org.apache.maven.index.FlatSearchResponse;
import org.apache.maven.index.MAVEN; import org.apache.maven.index.MAVEN;
import org.apache.maven.index.NexusIndexer; 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.IndexingContext;
import org.apache.maven.index.expr.SourcedSearchExpression; import org.apache.maven.index.expr.SourcedSearchExpression;
import org.apache.maven.index.expr.StringSearchExpression; import org.apache.maven.index.expr.StringSearchExpression;
@ -96,7 +96,8 @@ public class ArchivaIndexingTaskExecutorTest
indexer = plexusSisuBridge.lookup( NexusIndexer.class ); indexer = plexusSisuBridge.lookup( NexusIndexer.class );
ArtifactIndexingTask.createContext( repositoryConfig, indexer ); ArtifactIndexingTask.createContext( repositoryConfig, indexer,
plexusSisuBridge.lookupList( IndexCreator.class ) );
} }
@After @After
@ -152,7 +153,7 @@ public class ArchivaIndexingTaskExecutorTest
new File( repositoryConfig.getLocation() ), new File( repositoryConfig.getLocation() ),
new File( repositoryConfig.getLocation(), new File( repositoryConfig.getLocation(),
".indexer" ), null, null, ".indexer" ), null, null,
ArchivaNexusIndexerUtil.FULL_INDEX ); plexusSisuBridge.lookupList( IndexCreator.class ) );
context.setSearchable( true ); context.setSearchable( true );
} }
@ -297,7 +298,6 @@ public class ArchivaIndexingTaskExecutorTest
indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ), indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( "archiva-index-methods-jar-test" ) ),
Occur.SHOULD ); Occur.SHOULD );
FlatSearchRequest request = new FlatSearchRequest( q, getIndexingContext() ); FlatSearchRequest request = new FlatSearchRequest( q, getIndexingContext() );
FlatSearchResponse response = indexer.searchFlat( request ); FlatSearchResponse response = indexer.searchFlat( request );