]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1259] only index content that is listed in indexable-content configuration
authorBrett Porter <brett@apache.org>
Thu, 15 Oct 2009 03:41:57 +0000 (03:41 +0000)
committerBrett Porter <brett@apache.org>
Thu, 15 Oct 2009 03:41:57 +0000 (03:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@825382 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java

index 00378c706472a99244bf9d599e442553fb3d9545..e2dcf08e13fe9948282f7acc0377f8f193eb2e22 100644 (file)
@@ -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<String> includes = new ArrayList<String>();
+
+    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<String> getExcludes()
     {
-        return new ArrayList<String>();
+        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<String> getIncludes()
     {
-        return Arrays.asList( "**/*" );
+        return includes;
     }
 }
index 00902d2371de63b87130b87601b5241a1bc522a5..4e16b7f7df2fb4526f0d6cd8a2223a79b82b83d3 100644 (file)
@@ -5,6 +5,8 @@
 
     <bean id="indexerConsumer" class="org.apache.archiva.consumers.lucene.NexusIndexerConsumer" lazy-init="true">      
         <constructor-arg ref="archivaTaskScheduler"/>
+        <constructor-arg ref="archivaConfiguration"/>
+        <constructor-arg ref="fileTypes"/>
     </bean>
     
     <bean id="indexCleanupConsumer" class="org.apache.archiva.consumers.lucene.LuceneCleanupRemoveIndexedConsumer" lazy-init="true">
index 1a5955327009b936e5ded2399dd2c94e5c94a3d5..0da5b2bf1d765596c7ad11ea239a9b6c552c70c4 100644 (file)
@@ -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" );