]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1097] for deployments/proxied artifacts, create and close indexing context when...
authorBrett Porter <brett@apache.org>
Fri, 3 Dec 2010 14:11:05 +0000 (14:11 +0000)
committerBrett Porter <brett@apache.org>
Fri, 3 Dec 2010 14:11:05 +0000 (14:11 +0000)
Updated unit tests with changes made
Did not update the indexer as it would impact the API more significantly
Merged from: r1039004

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@1041824 13f79535-47bb-0310-9956-ffa450edef68

31 files changed:
archiva-cli/src/main/java/org/apache/maven/archiva/cli/AbstractProgressConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/RepositoryContentConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRemoveConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRenameConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/MetadataUpdaterConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ValidateChecksumConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-dependency-tree-consumer/src/main/java/org/apache/archiva/consumers/dependencytree/DependencyTreeGeneratorConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/pom.xml
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-converter/src/main/java/org/apache/maven/archiva/converter/legacy/LegacyConverterArtifactConsumer.java
archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java
archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumers.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/ConsumerProcessFileClosure.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/TriggerBeginScanClosure.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/InvalidScanConsumer.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/KnownScanConsumer.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumersTest.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/SampleKnownConsumer.java
archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaIndexingTaskExecutor.java
archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/tasks/ArtifactIndexingTask.java
archiva-modules/archiva-scheduled/src/main/resources/META-INF/spring-context.xml [new file with mode: 0644]
archiva-modules/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/ArchivaIndexingTaskExecutorTest.java
archiva-modules/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml
pom.xml

index c464f70bb01ac99d1d1214a591701f9f73340d2a..14e7a87fd065f2bdf1a46c9d8b6a2f4f4f2b830b 100644 (file)
@@ -43,6 +43,12 @@ public abstract class AbstractProgressConsumer
         this.count = 0;
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void processFile( String path )
         throws ConsumerException
     {
@@ -54,9 +60,20 @@ public abstract class AbstractProgressConsumer
 
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        processFile( path );
+    }
+
     public void completeScan()
     {
         System.out.println( "Final Count of Artifacts processed by " + getId() + ": " + count );
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
 }
index 203e5bd76ee42f8ccfc47086a1acfac2081ed1e3..f7b5a2487324460de0c411e92011a716a0fc7725 100644 (file)
@@ -61,6 +61,22 @@ public interface RepositoryContentConsumer extends Consumer
      */
     public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered ) throws ConsumerException;
 
+    /**
+     * <p>
+     * Event that triggers at the beginning of a scan, where you can also indicate whether the consumers will be
+     * executed on an entire repository or on a specific resource.
+     * </p>
+     *
+     * @see RepositoryContentConsumer#beginScan(org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration, java.util.Date )
+     *
+     * @param repository the repository that this consumer is being used for.
+     * @param whenGathered the start of the repository scan
+     * @param executeOnEntireRepo flags whether the consumer will be executed on an entire repository or just on a specific resource
+     * @throws ConsumerException if there was a problem with using the provided repository with the consumer.
+     */
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException;
+
     /**
      * <p>
      * Event indicating a file is to be processed by this consumer.
@@ -76,6 +92,14 @@ public interface RepositoryContentConsumer extends Consumer
      * @throws ConsumerException if there was a problem processing this file.
      */
     public void processFile( String path ) throws ConsumerException;
+
+    /**
+     *
+     * @param path
+     * @param executeOnEntireRepo
+     * @throws Exception
+     */
+    public void processFile( String path, boolean executeOnEntireRepo ) throws Exception;
     
     /**
      * <p>
@@ -89,6 +113,13 @@ public interface RepositoryContentConsumer extends Consumer
      */
     public void completeScan();
 
+    /**
+     * 
+     * @param executeOnEntireRepo
+     * @throws Exception
+     */
+    public void completeScan( boolean executeOnEntireRepo );
+
     /**
      * Whether the consumer should process files that have not been modified since the time passed in to the scan
      * method.
index fa2e2898745a59242f1ae8b3215c5c84f02acdab..e01510882a2455eda561e0fc61a1bc93542ae834 100644 (file)
@@ -99,11 +99,22 @@ public class ArtifactMissingChecksumsConsumer
         this.repositoryDir = new File( repo.getLocation() );
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repo, whenGathered );
+    }
+
     public void completeScan()
     {
         /* do nothing */
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return getDefaultArtifactExclusions();
@@ -120,6 +131,12 @@ public class ArtifactMissingChecksumsConsumer
         createFixChecksum( path, new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1 } );
         createFixChecksum( path, new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5 } );        
     }
+
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        processFile( path );   
+    }
     
     private void createFixChecksum( String path, ChecksumAlgorithm checksumAlgorithm[] )
     {
index 9d39e8c2b01ffc256e3886317b079d52a1f6ddea..f510b81df29c3b29a8ed40831812c202f3efe596 100644 (file)
@@ -95,11 +95,22 @@ public class AutoRemoveConsumer
         this.repositoryDir = new File( repository.getLocation() );
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void completeScan()
     {
         /* do nothing */
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return null;
@@ -121,6 +132,12 @@ public class AutoRemoveConsumer
         }
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        processFile( path );    
+    }
+
     public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
     {                
         if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
index 2df8820db06c35154a2535a0eafb58f7f03bdc55..3fb70b961cb22e57442af7f5e6436110db50a2b2 100644 (file)
@@ -96,11 +96,22 @@ public class AutoRenameConsumer
         this.repositoryDir = new File( repository.getLocation() );
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void completeScan()
     {
         /* do nothing */
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return null;
@@ -143,4 +154,10 @@ public class AutoRenameConsumer
             file.delete();
         }
     }
+
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        processFile( path );        
+    }
 }
index e40bb8d27a9358cbb4f24504a7a3052bfd0d5f3e..0025b0354a9e123a90d0d8bfaac6b5d1263986dd 100644 (file)
@@ -142,11 +142,22 @@ public class MetadataUpdaterConsumer
         }
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void completeScan()
     {
         /* do nothing here */
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return getDefaultArtifactExclusions();
@@ -176,6 +187,12 @@ public class MetadataUpdaterConsumer
         }
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     private void updateProjectMetadata( ArtifactReference artifact, String path )
     {
         ProjectReference projectRef = new ProjectReference();
index e7ac887995d83ce91b5c745fa463285dfbb74cfc..7b4b773fdd4ef84913fb9b4b4b09834e1fbd2621 100644 (file)
@@ -102,11 +102,22 @@ public class ValidateChecksumConsumer
         this.repositoryDir = new File( repository.getLocation() );
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void completeScan()
     {
         /* nothing to do */
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return null;
@@ -143,6 +154,12 @@ public class ValidateChecksumConsumer
         }
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     public void initialize()
         throws InitializationException
     {
index c71de5ca22b722dd177d7555861e38f39681a26c..01650d66b894632b04ffdff29012a7369511a866 100644 (file)
@@ -157,6 +157,12 @@ public class RepositoryPurgeConsumer
         }
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void processFile( String path )
         throws ConsumerException
     {
@@ -175,11 +181,22 @@ public class RepositoryPurgeConsumer
         }
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     public void completeScan()
     {
         /* do nothing */
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
     {
         if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
index db22000062e234febc850e258dd8bc12b6acd74e..5e6fd80a9c1972bb15def53c35a91a0f2634848a 100644 (file)
@@ -152,6 +152,12 @@ public class ArtifactUpdateDatabaseConsumer
         }
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void processFile( String path )
         throws ConsumerException
     {
@@ -210,6 +216,12 @@ public class ArtifactUpdateDatabaseConsumer
         }
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     /**
      * Get a Live Artifact from a Path.
      * <p/>
@@ -248,6 +260,11 @@ public class ArtifactUpdateDatabaseConsumer
         /* do nothing */
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
     {
         if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
index 75772566ea055c6ade6d0fd85b267d7dd84224fa..973e71f678b18f0c770dfefbf24adacaa14c2589 100644 (file)
@@ -155,10 +155,21 @@ public class DependencyTreeGeneratorConsumer
         }
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );    
+    }
+
     public void completeScan()
     {
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return null;
@@ -246,6 +257,12 @@ public class DependencyTreeGeneratorConsumer
         }
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        processFile( path );    
+    }
+
     private void flushProjectCache( MavenProjectBuilder projectBuilder )
     {
         try
index 0c412344963aa2f5aa190c95f3058dd1ddf6e38c..b1dd18558e66a86a97bd3826e943eb366653475c 100644 (file)
       <artifactId>bcel</artifactId>
       <version>5.2</version>
     </dependency>   
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
index 2567d13baf7c464b71b3393a9cf05ae5d4852865..446de8b66399e87603a93f800b7aba3f47a5e62b 100644 (file)
@@ -70,6 +70,8 @@ public class NexusIndexerConsumer
 
     private List<String> includes = new ArrayList<String>();
 
+    private ManagedRepositoryConfiguration repository;
+
     public NexusIndexerConsumer( ArchivaTaskScheduler scheduler, ArchivaConfiguration configuration, FileTypes filetypes )
     {
         this.configuration = configuration;
@@ -102,6 +104,7 @@ public class NexusIndexerConsumer
 
         try
         {
+            log.info( "Creating indexing context for repo : " + repository.getId() );
             context = TaskCreator.createContext( repository );
         }
         catch ( IOException e )
@@ -114,6 +117,20 @@ public class NexusIndexerConsumer
         }
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        if( executeOnEntireRepo )
+        {
+            beginScan( repository, whenGathered );
+        }
+        else
+        {
+            this.repository = repository;
+            managedRepository = new File( repository.getLocation() );       
+        }
+    }
+
     public void processFile( String path )
         throws ConsumerException
     {
@@ -133,6 +150,32 @@ public class NexusIndexerConsumer
         }
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        if( executeOnEntireRepo )
+        {
+            processFile( path );
+        }
+        else
+        {
+            File artifactFile = new File( managedRepository, path );
+
+            // specify in indexing task that this is not a repo scan request!
+            ArtifactIndexingTask task =
+                new ArtifactIndexingTask( repository, artifactFile, ArtifactIndexingTask.Action.ADD, context, false );
+            try
+            {
+                log.debug( "Queueing indexing task + '" + task + "' to add or update the artifact in the index." );
+                scheduler.queueIndexingTask( task );
+            }
+            catch ( TaskQueueException e )
+            {
+                throw new ConsumerException( e.getMessage(), e );
+            }
+        }
+    }
+
     public void completeScan()
     {
         ArtifactIndexingTask task =
@@ -150,6 +193,16 @@ public class NexusIndexerConsumer
         context = null;
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        if( executeOnEntireRepo )
+        {
+            completeScan();
+        }
+
+        // else, do nothing as the context will be closed when indexing task is executed if not a repo scan request!
+    }
+
     public List<String> getExcludes()
     {
         return Collections.emptyList();
index 4e16b7f7df2fb4526f0d6cd8a2223a79b82b83d3..6c4dd5694cdd629970e3d6332b5ab9930f426257 100644 (file)
@@ -13,4 +13,8 @@
         <constructor-arg ref="repositoryContentFactory"/>
         <constructor-arg ref="archivaTaskScheduler"/>
     </bean>
+
+    <bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger">
+      <constructor-arg type="java.lang.Class"><value>org.sonatype.nexus.index.DefaultNexusIndexer</value></constructor-arg>
+    </bean>
 </beans>
\ No newline at end of file
index 0cd5bc3b29d5b8f08652784ddc868e45fbd8cea8..dd03c4a3459c9dec6cf7b4aa0597ac484ae92f5b 100644 (file)
@@ -88,11 +88,22 @@ public class LegacyConverterArtifactConsumer
         this.managedRepository.setRepository( repository );
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void completeScan()
     {
 
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return excludes;
@@ -124,6 +135,12 @@ public class LegacyConverterArtifactConsumer
         }
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     public String getDescription()
     {
         return "Legacy Artifact to Default Artifact Converter";
index 3c8f5a577cbc51b7390ef86dae653c6515970c86..e04ffb7285c242066131f97e31acee6e1373e80e 100644 (file)
@@ -37,6 +37,7 @@ import org.sonatype.nexus.index.ArtifactInfo;
 import org.sonatype.nexus.index.FlatSearchRequest;
 import org.sonatype.nexus.index.FlatSearchResponse;
 import org.sonatype.nexus.index.NexusIndexer;
+import org.sonatype.nexus.index.context.IndexCreator;
 import org.sonatype.nexus.index.context.IndexingContext;
 import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException;
 
index 019b9b78e6d3e6ea22ce51cd7b221513b43ade0d..7401aec3f121b8d6b353abf7aa1b188058f00146 100644 (file)
@@ -7,6 +7,10 @@
         <constructor-arg ref="nexusIndexer"/>
         <constructor-arg ref="archivaConfiguration"/>
     </bean>
-    
+
+    <bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger">
+      <constructor-arg type="java.lang.Class"><value>org.sonatype.nexus.index.DefaultNexusIndexer</value></constructor-arg>
+    </bean>
+  
    <!--  <bean id="indexingContextMap" class="org.apache.archiva.indexer.IndexingContextMap"/>  -->
 </beans>
\ No newline at end of file
index 82875a6ab31deaab2feca88cabad14c1145b1991..973230e93c7b24fd3e320f34e15be4a8df807897 100644 (file)
@@ -35,17 +35,25 @@ public class TriggerScanCompletedClosure
 
     private final ManagedRepositoryConfiguration repository;
 
+    private boolean executeOnEntireRepo = true;
+
     public TriggerScanCompletedClosure( ManagedRepositoryConfiguration repository )
     {
         this.repository = repository;
     }
 
+    public TriggerScanCompletedClosure( ManagedRepositoryConfiguration repository, boolean executeOnEntireRepo )
+    {
+        this( repository );
+        this.executeOnEntireRepo = executeOnEntireRepo;
+    }
+
     public void execute( Object input )
     {
         if ( input instanceof RepositoryContentConsumer )
         {
             RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
-            consumer.completeScan();
+            consumer.completeScan( executeOnEntireRepo );
             log.debug( "Consumer [" + consumer.getId() + "] completed for repository [" + repository.getId() + "]" );
         }
     }
index ec54b041edf2309dff668370593c3dec12d8ba40..f5c06f812478ff6c290e7569d4916e5146ba77cf 100644 (file)
@@ -236,7 +236,7 @@ public class RepositoryContentConsumers
         // Run the repository consumers
         try
         {
-            Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime() );
+            Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime(), false );
 
             List<KnownRepositoryContentConsumer> selectedKnownConsumers = getSelectedKnownConsumers();
             
@@ -266,9 +266,12 @@ public class RepositoryContentConsumers
             BaseFile baseFile = new BaseFile( repository.getLocation(), localFile );
             ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
             predicate.setBasefile( baseFile );
+            predicate.setCaseSensitive( false );
+
             ConsumerProcessFileClosure closure = new ConsumerProcessFileClosure();
             closure.setBasefile( baseFile );
-            predicate.setCaseSensitive( false );
+            closure.setExecuteOnEntireRepo( false );
+            
             Closure processIfWanted = IfClosure.getInstance( predicate, closure );
 
             CollectionUtils.forAllDo( selectedKnownConsumers, processIfWanted );
@@ -279,7 +282,7 @@ public class RepositoryContentConsumers
                 CollectionUtils.forAllDo( selectedInvalidConsumers, closure );
             }
 
-            TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository );
+            TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository, false );
 
             CollectionUtils.forAllDo( selectedKnownConsumers, scanCompletedClosure );
         }
index e8d86d90c6870dfc1bb96f899094bb71368f6e5e..63229aa9797122174c172db39aa185d1ca21a507 100644 (file)
@@ -82,7 +82,7 @@ public class RepositoryScannerInstance
         stats = new RepositoryScanStatistics();
         stats.setRepositoryId( repository.getId() );
 
-        Closure triggerBeginScan = new TriggerBeginScanClosure( repository, new Date( System.currentTimeMillis() ) );
+        Closure triggerBeginScan = new TriggerBeginScanClosure( repository, new Date( System.currentTimeMillis() ), true );
 
         CollectionUtils.forAllDo( knownConsumerList, triggerBeginScan );
         CollectionUtils.forAllDo( invalidConsumerList, triggerBeginScan );
@@ -131,6 +131,7 @@ public class RepositoryScannerInstance
         }
         
         consumerProcessFile.setBasefile( basefile );
+        consumerProcessFile.setExecuteOnEntireRepo( true );
         consumerWantsFile.setBasefile( basefile );
         
         Closure processIfWanted = IfClosure.getInstance( consumerWantsFile, consumerProcessFile );
@@ -145,7 +146,7 @@ public class RepositoryScannerInstance
 
     public void directoryWalkFinished()
     {
-        TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure(repository);
+        TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository, true );
         
         CollectionUtils.forAllDo( knownConsumers, scanCompletedClosure );
         CollectionUtils.forAllDo( invalidConsumers, scanCompletedClosure );
index f8fe3ff702952ffd9496b88de43218543391ac6f..e1a49392606fcda352fe85df1567d3d8ec6827f1 100644 (file)
@@ -37,6 +37,8 @@ public class ConsumerProcessFileClosure
     
     private BaseFile basefile;
 
+    private boolean executeOnEntireRepo;
+
     public void execute( Object input )
     {
         if ( input instanceof RepositoryContentConsumer )
@@ -47,7 +49,7 @@ public class ConsumerProcessFileClosure
             {
                 log.debug( "Sending to consumer: " + consumer.getId() );
 
-                consumer.processFile( basefile.getRelativePath() );
+                consumer.processFile( basefile.getRelativePath(), executeOnEntireRepo );
             }
             catch ( Exception e )
             {
@@ -70,6 +72,16 @@ public class ConsumerProcessFileClosure
         this.basefile = basefile;
     }
 
+    public boolean isExecuteOnEntireRepo()
+    {
+        return executeOnEntireRepo;
+    }
+
+    public void setExecuteOnEntireRepo( boolean executeOnEntireRepo )
+    {
+        this.executeOnEntireRepo = executeOnEntireRepo;
+    }
+
     public Logger getLogger()
     {
         return log;
index d0a05cbc596d5b10202eb51f53969f89e5b1b579..acacc72b1752805b5e832abc1b9c29eab30a6df3 100644 (file)
@@ -42,6 +42,8 @@ public class TriggerBeginScanClosure
     
     private Date whenGathered;
 
+    private boolean executeOnEntireRepo = true;
+
     public TriggerBeginScanClosure( ManagedRepositoryConfiguration repository )
     {
         this.repository = repository;
@@ -53,6 +55,12 @@ public class TriggerBeginScanClosure
         this.whenGathered = whenGathered;
     }
 
+    public TriggerBeginScanClosure( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+    {
+        this( repository, whenGathered );
+        this.executeOnEntireRepo = executeOnEntireRepo;
+    }
+
     public void execute( Object input )
     {
         if ( input instanceof RepositoryContentConsumer )
@@ -61,7 +69,7 @@ public class TriggerBeginScanClosure
                 
             try
             {
-                consumer.beginScan( repository, whenGathered );
+                consumer.beginScan( repository, whenGathered, executeOnEntireRepo );
             }
             catch ( ConsumerException e )
             {
index 29e50a58937a8f2510a820088b4c64179d02c073..15bd8298d2de320a106ee7527547f2dd77f0110c 100644 (file)
@@ -49,11 +49,22 @@ public class InvalidScanConsumer
         /* do nothing */
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void completeScan()
     {
         /* do nothing */
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return null;
@@ -70,6 +81,12 @@ public class InvalidScanConsumer
         processCount++;
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        processFile( path );
+    }
+
     public String getDescription()
     {
         return "Bad Content Scan Consumer (for testing)";
index 0ab62fe4609dd5bf57cd3a04d45140cc6cb0d75c..ce45cc55ea2e8b60e07486348976a1e3da822bfc 100644 (file)
@@ -76,17 +76,34 @@ public class KnownScanConsumer
         /* do nothing */
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void processFile( String path )
         throws ConsumerException
     {
         this.processCount++;
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     public void completeScan()
     {
         /* do nothing */
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+       completeScan();
+    }
+
     public int getProcessCount()
     {
         return processCount;
index 86c4b53701f03c62de0381118d8e327ed9f04b1e..0b9653d497991d679d4e304d37898f60a464b3fb 100644 (file)
@@ -241,16 +241,16 @@ public class RepositoryContentConsumersTest
         Date startTime = new Date( System.currentTimeMillis() );
         startTime.setTime( 12345678 );
 
-        selectedKnownConsumer.beginScan( repo, startTime );
+        selectedKnownConsumer.beginScan( repo, startTime, false );
         selectedKnownConsumer.getExcludes();
         knownControl.setReturnValue( Collections.EMPTY_LIST );
         selectedKnownConsumer.getIncludes();
         knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) );
-        selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ) );
+        selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
         //        knownConsumer.completeScan();
         knownControl.replay();
 
-        selectedInvalidConsumer.beginScan( repo, startTime );
+        selectedInvalidConsumer.beginScan( repo, startTime, false );
         //        invalidConsumer.completeScan();
         invalidControl.replay();
 
@@ -264,7 +264,7 @@ public class RepositoryContentConsumersTest
 
         File notIncludedTestFile = getTestFile( "target/test-repo/path/to/test-file.xml" );
 
-        selectedKnownConsumer.beginScan( repo, startTime );
+        selectedKnownConsumer.beginScan( repo, startTime, false );
         selectedKnownConsumer.getExcludes();
         knownControl.setReturnValue( Collections.EMPTY_LIST );
         selectedKnownConsumer.getIncludes();
@@ -272,8 +272,8 @@ public class RepositoryContentConsumersTest
         //        knownConsumer.completeScan();
         knownControl.replay();
 
-        selectedInvalidConsumer.beginScan( repo, startTime );
-        selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ) );
+        selectedInvalidConsumer.beginScan( repo, startTime, false );
+        selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ), false );
         selectedInvalidConsumer.getId();
         invalidControl.setReturnValue( "invalid" );
         //        invalidConsumer.completeScan();
@@ -289,14 +289,14 @@ public class RepositoryContentConsumersTest
 
         File excludedTestFile = getTestFile( "target/test-repo/path/to/test-file.txt" );
 
-        selectedKnownConsumer.beginScan( repo, startTime );
+        selectedKnownConsumer.beginScan( repo, startTime, false );
         selectedKnownConsumer.getExcludes();
         knownControl.setReturnValue( Collections.singletonList( "**/test-file.txt" ) );
         //        knownConsumer.completeScan();
         knownControl.replay();
 
-        selectedInvalidConsumer.beginScan( repo, startTime );
-        selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ) );
+        selectedInvalidConsumer.beginScan( repo, startTime, false );
+        selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
         selectedInvalidConsumer.getId();
         invalidControl.setReturnValue( "invalid" );
         //        invalidConsumer.completeScan();
index c2358d702c63795d1961ce8081aa92951d79eb9e..1cba145ed2b263981ac0fdf56644a5c4c5862d29 100644 (file)
@@ -50,11 +50,22 @@ public class SampleKnownConsumer
         /* nothing to do */
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void completeScan()
     {
         /* nothing to do */
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return null;
@@ -71,6 +82,12 @@ public class SampleKnownConsumer
         /* nothing to do */
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     public String getDescription()
     {
         return "Sample Known Consumer";
index 61a3f34603ff714a511b7c2fad09488944baf690..3233a870e4c5aec0ca8f15f446445c6bd3217722 100644 (file)
@@ -21,11 +21,13 @@ package org.apache.maven.archiva.scheduled.executors;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.List;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.IndexReader;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 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.taskqueue.Task;
@@ -38,7 +40,9 @@ import org.sonatype.nexus.index.ArtifactContextProducer;
 import org.sonatype.nexus.index.ArtifactInfo;
 import org.sonatype.nexus.index.DefaultArtifactContextProducer;
 import org.sonatype.nexus.index.IndexerEngine;
+import org.sonatype.nexus.index.context.IndexCreator;
 import org.sonatype.nexus.index.context.IndexingContext;
+import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException;
 import org.sonatype.nexus.index.packer.IndexPacker;
 import org.sonatype.nexus.index.packer.IndexPackingRequest;
 
@@ -78,44 +82,35 @@ public class ArchivaIndexingTaskExecutor
             ManagedRepositoryConfiguration repository = indexingTask.getRepository();
             IndexingContext context = indexingTask.getContext();
 
-            if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction() ) )
+            if ( ArtifactIndexingTask.Action.FINISH.equals( indexingTask.getAction() )
+                && indexingTask.isExecuteOnEntireRepo() )
             {
-                try
-                {
-                    context.optimize();
-
-                    File managedRepository = new File( repository.getLocation() );
-                    final File indexLocation = new File( managedRepository, ".index" );
-                    IndexPackingRequest request = new IndexPackingRequest( context, indexLocation );
-                    indexPacker.packIndex( request );
-
-                    log.debug( "Index file packaged at '" + indexLocation.getPath() + "'." );
-                }
-                catch ( IOException e )
-                {
-                    log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage() );
-                    throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask
-                        + "'", e );
-                }
-                finally
+                log.debug( "Finishing indexing task on repo: " + repository.getId() );
+                finishIndexingTask( indexingTask, repository, context );
+            }
+            else
+            {
+                // create context if not a repo scan request
+                if( !indexingTask.isExecuteOnEntireRepo() )
                 {
-                    if ( context != null )
+                    try
                     {
-                        try
-                        {
-                            context.close( false );
-                        }
-                        catch ( IOException e )
-                        {
-                            log.error( "Error occurred while closing context: " + e.getMessage() );
-                            throw new TaskExecutionException( "Error occurred while closing context: " + e.getMessage() );
-                        }
+                        log.debug( "Creating indexing context on resource: " + indexingTask.getResourceFile().getPath() );
+                        context = TaskCreator.createContext( repository );
+                    }
+                    catch( IOException e )
+                    {
+                        log.error( "Error occurred while creating context: " + e.getMessage() );
+                        throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage() );
+                    }
+                    catch( UnsupportedExistingLuceneIndexException e )
+                    {
+                        log.error( "Error occurred while creating context: " + e.getMessage() );
+                        throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage() );    
                     }
                 }
-            }
-            else
-            {
-                if ( context.getIndexDirectory() == null )
+
+                if ( context == null || context.getIndexDirectory() == null )
                 {
                     throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" );
                 }
@@ -157,6 +152,13 @@ public class ArchivaIndexingTaskExecutor
                                 indexerEngine.update( context, ac );
                                 context.getIndexWriter().commit();
                             }
+
+                            // close the context if not a repo scan request
+                            if( !indexingTask.isExecuteOnEntireRepo() )
+                            {
+                                log.debug( "Finishing indexing task on resource file : " + indexingTask.getResourceFile().getPath() );
+                                finishIndexingTask( indexingTask, repository, context );   
+                            }
                         }
                         else
                         {
@@ -176,6 +178,44 @@ public class ArchivaIndexingTaskExecutor
         }
     }
 
+    private void finishIndexingTask( ArtifactIndexingTask indexingTask, ManagedRepositoryConfiguration repository,
+                                     IndexingContext context )
+        throws TaskExecutionException
+    {
+        try
+        {
+            context.optimize();
+
+            File managedRepository = new File( repository.getLocation() );
+            final File indexLocation = new File( managedRepository, ".index" );
+            IndexPackingRequest request = new IndexPackingRequest( context, indexLocation );
+            indexPacker.packIndex( request );
+
+            log.debug( "Index file packaged at '" + indexLocation.getPath() + "'." );
+        }
+        catch ( IOException e )
+        {
+            log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage() );
+            throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask
+                + "'", e );
+        }
+        finally
+        {
+            if ( context != null )
+            {
+                try
+                {
+                    context.close( false );
+                }
+                catch ( IOException e )
+                {
+                    log.error( "Error occurred while closing context: " + e.getMessage() );
+                    throw new TaskExecutionException( "Error occurred while closing context: " + e.getMessage() );
+                }
+            }
+        }
+    }
+
     public void initialize()
         throws InitializationException
     {
index a9c0ac465a42a2ed0ed31d05866edfe392cbc132..5d875a13a00db0c14470ccbd450ee50bd86965d0 100644 (file)
@@ -41,6 +41,8 @@ public class ArtifactIndexingTask
 
     private final IndexingContext context;
 
+    private boolean executeOnEntireRepo = true;
+
     public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File resourceFile, Action action,
                                  IndexingContext context )
     {
@@ -50,6 +52,23 @@ public class ArtifactIndexingTask
         this.context = context;
     }
 
+    public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File resourceFile, Action action,
+                                 IndexingContext context, boolean executeOnEntireRepo )
+    {
+        this( repository, resourceFile, action, context );
+        this.executeOnEntireRepo = executeOnEntireRepo;
+    }
+
+    public boolean isExecuteOnEntireRepo()
+    {
+        return executeOnEntireRepo;
+    }
+
+    public void setExecuteOnEntireRepo( boolean executeOnEntireRepo )
+    {
+        this.executeOnEntireRepo = executeOnEntireRepo;
+    }
+
     public long getMaxExecutionTime()
     {
         return 0;
diff --git a/archiva-modules/archiva-scheduled/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-scheduled/src/main/resources/META-INF/spring-context.xml
new file mode 100644 (file)
index 0000000..b3f04a1
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+    <bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger">
+      <constructor-arg type="java.lang.Class"><value>org.sonatype.nexus.index.DefaultNexusIndexer</value></constructor-arg>
+    </bean>
+</beans>
\ No newline at end of file
index a0e90b64781085fc90c6a45677bc8e98603020e2..2c6ef3f95b7a572219b37f1d9820624fa8ce6970 100644 (file)
@@ -26,6 +26,8 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
 import java.util.Set;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
@@ -45,6 +47,7 @@ import org.sonatype.nexus.index.FlatSearchRequest;
 import org.sonatype.nexus.index.FlatSearchResponse;
 import org.sonatype.nexus.index.IndexerEngine;
 import org.sonatype.nexus.index.NexusIndexer;
+import org.sonatype.nexus.index.context.IndexCreator;
 import org.sonatype.nexus.index.context.IndexingContext;
 import org.sonatype.nexus.index.packer.IndexPacker;
 
index c7823255afe4ccc9b1214977af25aac87685a304..af15d0c6febd5e8e057f178675f76c0a35b4397f 100644 (file)
       <lifecycle-handler>basic</lifecycle-handler>
     </component>
 
+    <component>
+      <role>org.codehaus.plexus.logging.Logger</role>
+      <implementation>org.apache.maven.archiva.common.utils.Slf4JPlexusLogger</implementation>
+      <role-hint>logger</role-hint>
+    </component>
+
     <!-- 
    PLXREDBACK-81 bad role hint, redefining here until redback alpha-2 is released.
     -->
diff --git a/pom.xml b/pom.xml
index 912b22397f5ddb32dc90d8c8159a715a07f91b11..85225852e64de8a95c497b7f112cf3cb8e8c7c86 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <dependency>
         <groupId>org.apache.lucene</groupId>
         <artifactId>lucene-core</artifactId>
-        <version>2.4.0</version>
+        <version>2.4.1</version>
       </dependency>
       <dependency>
         <groupId>org.apache.lucene</groupId>
         <artifactId>lucene-queries</artifactId>
-        <version>2.4.0</version>
+        <version>2.4.1</version>
       </dependency>
       <dependency>
         <groupId>javax.mail</groupId>