From e5c3dc20fb255146b7c9b43c0fe9f381fea2eb49 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 15 Oct 2009 03:41:57 +0000 Subject: [PATCH] [MRM-1259] only index content that is listed in indexable-content configuration git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@825382 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/NexusIndexerConsumer.java | 53 +++++++++++++++++-- .../resources/META-INF/spring-context.xml | 2 + .../lucene/NexusIndexerConsumerTest.java | 8 ++- 3 files changed, 57 insertions(+), 6 deletions(-) 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 00378c706..e2dcf08e1 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 @@ -22,10 +22,13 @@ package org.apache.archiva.consumers.lucene; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.ConfigurationNames; +import org.apache.maven.archiva.configuration.FileTypes; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; import org.apache.maven.archiva.consumers.ConsumerException; @@ -34,6 +37,10 @@ import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryConte import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler; import org.apache.maven.archiva.scheduled.tasks.ArtifactIndexingTask; import org.apache.maven.archiva.scheduled.tasks.TaskCreator; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import org.codehaus.plexus.registry.Registry; +import org.codehaus.plexus.registry.RegistryListener; import org.codehaus.plexus.taskqueue.TaskQueueException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,10 +52,14 @@ import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException; */ public class NexusIndexerConsumer extends AbstractMonitoredConsumer - implements KnownRepositoryContentConsumer + implements KnownRepositoryContentConsumer, RegistryListener, Initializable { private static final Logger log = LoggerFactory.getLogger( NexusIndexerConsumer.class ); + private ArchivaConfiguration configuration; + + private FileTypes filetypes; + private ManagedDefaultRepositoryContent repositoryContent; private File managedRepository; @@ -57,8 +68,12 @@ public class NexusIndexerConsumer private IndexingContext context; - public NexusIndexerConsumer( ArchivaTaskScheduler scheduler ) + private List includes = new ArrayList(); + + public NexusIndexerConsumer( ArchivaTaskScheduler scheduler, ArchivaConfiguration configuration, FileTypes filetypes ) { + this.configuration = configuration; + this.filetypes = filetypes; this.scheduler = scheduler; } @@ -136,11 +151,39 @@ public class NexusIndexerConsumer public List getExcludes() { - return new ArrayList(); + return Collections.emptyList(); + } + + public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) + { + initIncludes(); + } + } + + public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + /* do nothing */ + } + + private void initIncludes() + { + includes.clear(); + + includes.addAll( filetypes.getFileTypePatterns( FileTypes.INDEXABLE_CONTENT ) ); + } + + public void initialize() + throws InitializationException + { + configuration.addChangeListener( this ); + + initIncludes(); } public List getIncludes() { - return Arrays.asList( "**/*" ); + return includes; } } 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 00902d237..4e16b7f7d 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 @@ -5,6 +5,8 @@ + + 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 1a5955327..0da5b2bf1 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,8 @@ import java.util.Set; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.common.ArchivaException; +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.archiva.scheduled.ArchivaTaskScheduler; @@ -118,7 +120,11 @@ public class NexusIndexerConsumerTest scheduler = new ArchivaTaskSchedulerStub(); - nexusIndexerConsumer = new NexusIndexerConsumer( scheduler ); + ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class ); + + FileTypes filetypes = (FileTypes) lookup( FileTypes.class ); + + nexusIndexerConsumer = new NexusIndexerConsumer( scheduler, configuration, filetypes ); repositoryConfig = new ManagedRepositoryConfiguration(); repositoryConfig.setId( "test-repo" ); -- 2.39.5