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 a5872da32..075a16289 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 @@ -26,6 +26,8 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; +import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; import org.apache.archiva.scheduler.ArchivaTaskScheduler; import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -35,6 +37,7 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; 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.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; @@ -64,16 +67,20 @@ public class NexusIndexerConsumer private IndexingContext context; + private NexusIndexer nexusIndexer; + private List includes = new ArrayList(); private ManagedRepositoryConfiguration repository; public NexusIndexerConsumer( ArchivaTaskScheduler scheduler, - ArchivaConfiguration configuration, FileTypes filetypes ) + ArchivaConfiguration configuration, FileTypes filetypes, PlexusSisuBridge plexusSisuBridge ) + throws PlexusSisuBridgeException { this.configuration = configuration; this.filetypes = filetypes; this.scheduler = scheduler; + this.nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); } public String getDescription() @@ -100,7 +107,7 @@ public class NexusIndexerConsumer try { log.info( "Creating indexing context for repo : " + repository.getId() ); - context = ArtifactIndexingTask.createContext( repository ); + context = ArtifactIndexingTask.createContext( repository, nexusIndexer ); } catch ( IOException e ) { diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml index 93bc04af8..c9268894a 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml @@ -28,9 +28,10 @@ default-lazy-init="true"> - - - + + + + diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java index 6d4f73c61..838aaf7bd 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Set; import junit.framework.TestCase; +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.scheduler.ArchivaTaskScheduler; import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.commons.io.FileUtils; @@ -35,6 +36,7 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.FileTypes; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.maven.index.NexusIndexer; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.taskqueue.TaskQueueException; import org.junit.After; @@ -94,6 +96,9 @@ public class NexusIndexerConsumerTest @Inject private ApplicationContext applicationContext; + @Inject + private PlexusSisuBridge plexusSisuBridge; + @Override @Before @@ -108,7 +113,7 @@ public class NexusIndexerConsumerTest FileTypes filetypes = applicationContext.getBean( FileTypes.class ); - nexusIndexerConsumer = new NexusIndexerConsumer( scheduler, configuration, filetypes ); + nexusIndexerConsumer = new NexusIndexerConsumer( scheduler, configuration, filetypes, plexusSisuBridge ); // initialize to set the file types to be processed ( (Initializable) nexusIndexerConsumer ).initialize(); 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 ecd846237..978472c22 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 @@ -31,6 +31,7 @@ import org.apache.maven.index.ArtifactContextProducer; import org.apache.maven.index.ArtifactInfo; import org.apache.maven.index.DefaultArtifactContextProducer; 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.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; @@ -77,6 +78,8 @@ public class ArchivaIndexingTaskExecutor @Inject private PlexusSisuBridge plexusSisuBridge; + private NexusIndexer nexusIndexer; + @PostConstruct public void initialize() throws PlexusSisuBridgeException @@ -115,7 +118,7 @@ public class ArchivaIndexingTaskExecutor { log.debug( "Creating indexing context on resource: {}", indexingTask.getResourceFile().getPath() ); - context = ArtifactIndexingTask.createContext( repository ); + context = ArtifactIndexingTask.createContext( repository, nexusIndexer ); } 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 fff045c81..4b2276509 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,22 +19,25 @@ package org.apache.archiva.scheduler.indexing; * under the License. */ -import java.io.File; -import java.io.IOException; - import org.apache.maven.archiva.common.utils.ArchivaNexusIndexerUtil; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; -import org.apache.maven.index.context.DefaultIndexingContext; +import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.codehaus.plexus.taskqueue.Task; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; public class ArtifactIndexingTask implements Task { public enum Action { - ADD, DELETE, FINISH + ADD, + DELETE, + FINISH } private final ManagedRepositoryConfiguration repository; @@ -120,27 +123,41 @@ public class ArtifactIndexingTask public boolean equals( Object obj ) { if ( this == obj ) + { return true; + } if ( obj == null ) + { return false; + } if ( getClass() != obj.getClass() ) + { return false; + } ArtifactIndexingTask other = (ArtifactIndexingTask) obj; if ( !action.equals( other.action ) ) + { return false; + } if ( !repository.getId().equals( other.repository.getId() ) ) + { return false; + } if ( resourceFile == null ) { if ( other.resourceFile != null ) + { return false; + } } else if ( !resourceFile.equals( other.resourceFile ) ) + { return false; + } return true; } - public static IndexingContext createContext( ManagedRepositoryConfiguration repository ) + public static IndexingContext createContext( ManagedRepositoryConfiguration repository, NexusIndexer indexer ) throws IOException, UnsupportedExistingLuceneIndexException { String indexDir = repository.getIndexDir(); @@ -156,9 +173,20 @@ public class ArtifactIndexingTask indexDirectory = new File( managedRepository, ".indexer" ); } + if ( indexer.getIndexingContexts().containsKey( repository.getId() ) ) + { + LoggerFactory.getLogger( ArtifactIndexingTask.class ).warn( + "skip adding repository with id {} as already exists", repository.getId() ); + } + IndexingContext context = - new DefaultIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory, - null, null, ArchivaNexusIndexerUtil.FULL_INDEX, false ); + indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory, + managedRepository.toURI().toURL().toString(), + indexDirectory.toURI().toURL().toString(), ArchivaNexusIndexerUtil.FULL_INDEX ); + + //IndexingContext context = + // new DefaultIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory, + // null, null, ArchivaNexusIndexerUtil.FULL_INDEX, false ); 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 c0c5f5f85..c8cc90533 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 @@ -81,6 +81,8 @@ public class ArchivaIndexingTaskExecutorTest private IndexingContext context; + private NexusIndexer nexusIndexer; + @Inject PlexusSisuBridge plexusSisuBridge; @@ -113,7 +115,11 @@ public class ArchivaIndexingTaskExecutorTest indexingExecutor.setIndexerEngine( indexerEngine ); indexingExecutor.setIndexPacker( indexPacker ); - context = ArtifactIndexingTask.createContext( repositoryConfig ); + nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); + + context = ArtifactIndexingTask.createContext( repositoryConfig, nexusIndexer ); + + } @After @@ -245,7 +251,7 @@ public class ArchivaIndexingTaskExecutorTest searcher.close(); - context = ArtifactIndexingTask.createContext( repositoryConfig ); + context = ArtifactIndexingTask.createContext( repositoryConfig, nexusIndexer ); // remove added artifact from index task = new ArtifactIndexingTask( repositoryConfig, artifactFile, ArtifactIndexingTask.Action.DELETE, context );