]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1097]
authorMaria Odea B. Ching <oching@apache.org>
Thu, 25 Nov 2010 11:20:47 +0000 (11:20 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Thu, 25 Nov 2010 11:20:47 +0000 (11:20 +0000)
o upgrade nexus indexer to 3.0.1 + added logger bean which is needed by NexusIndexer
o for deployments/proxied artifacts, create and close indexing context when indexing task is executed as compared to the original behavior where the indexing context is created
before it is queued (so as the indexing task queue builds up, more indexing contexts are being opened/created which might be causing the too many open files problem)
o updated unit tests with changes made

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1039004 13f79535-47bb-0310-9956-ffa450edef68

30 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-dependency-tree-consumer/src/main/java/org/apache/archiva/consumers/dependencytree/DependencyTreeGeneratorConsumer.java
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-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
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/resources/META-INF/spring-context.xml
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/ConsumerProcessFileClosure.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/resources/META-INF/spring-context.xml [new file with mode: 0644]
archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestConsumer.java
archiva-modules/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml
archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java
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..c8d0ddc0a9d91fbfafd29eff9676a5756721bcac 100644 (file)
@@ -142,11 +142,24 @@ public class MetadataUpdaterConsumer
         }
     }
 
+    @Override
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void completeScan()
     {
         /* do nothing here */
     }
 
+    @Override
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return getDefaultArtifactExclusions();
@@ -176,6 +189,13 @@ public class MetadataUpdaterConsumer
         }
     }
 
+    @Override
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     private void updateProjectMetadata( ArtifactReference artifact, String path )
     {
         ProjectReference projectRef = new ProjectReference();
index e7ac887995d83ce91b5c745fa463285dfbb74cfc..051f8e51472b9b6f06d8a250f2b3787cc1bd5471 100644 (file)
@@ -102,11 +102,24 @@ public class ValidateChecksumConsumer
         this.repositoryDir = new File( repository.getLocation() );
     }
 
+    @Override
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void completeScan()
     {
         /* nothing to do */
     }
 
+    @Override
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return null;
@@ -143,6 +156,13 @@ public class ValidateChecksumConsumer
         }
     }
 
+    @Override
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     public void initialize()
         throws InitializationException
     {
index bcdc5c5fa6bcd42696c74a11a416ebe1c3b03a1d..a77507cf72a46b1033af5962696dc2d5af6ad814 100644 (file)
@@ -157,6 +157,13 @@ public class RepositoryPurgeConsumer
         }
     }
 
+    @Override
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void processFile( String path )
         throws ConsumerException
     {
@@ -175,11 +182,24 @@ public class RepositoryPurgeConsumer
         }
     }
 
+    @Override
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     public void completeScan()
     {
         /* do nothing */
     }
 
+    @Override
+    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 836fa6a8e64ad75534974aff503e80bdd667999f..5e1f1ee9c91de99198226bb0a27e43d50ee91598 100644 (file)
@@ -99,6 +99,7 @@ public class NexusIndexerConsumer
 
         try
         {
+            log.info( "Creating indexing context for repo : " + repository.getId() );
             context = ArtifactIndexingTask.createContext( repository );
         }
         catch ( IOException e )
@@ -111,6 +112,21 @@ public class NexusIndexerConsumer
         }
     }
 
+    @Override
+    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
     {
@@ -129,6 +145,33 @@ public class NexusIndexerConsumer
         }
     }
 
+    @Override
+    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.queueTask( task );
+            }
+            catch ( TaskQueueException e )
+            {
+                throw new ConsumerException( e.getMessage(), e );
+            }
+        }
+    }
+
     public void completeScan()
     {
         ArtifactIndexingTask task =
@@ -145,6 +188,17 @@ public class NexusIndexerConsumer
         context = null;
     }
 
+    @Override
+    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 542215ff2a6c1e07b396d3319c395f40d270fd72..8282c6cb25fefc12d2db1adae92090e8c6ad4a12 100644 (file)
@@ -8,4 +8,8 @@
         <constructor-arg ref="archivaConfiguration"/>
         <constructor-arg ref="fileTypes"/>
     </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 762f79d55d7670299ac5c97dff4d7f4ccc346699..61e496f6a3d9d196eef6a58a99b2d55fd27045ea 100644 (file)
@@ -127,6 +127,12 @@ public class ArchivaMetadataCreationConsumer
         this.whenGathered = whenGathered;
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void processFile( String path )
         throws ConsumerException
     {
@@ -174,11 +180,22 @@ public class ArchivaMetadataCreationConsumer
         metadataRepository.updateProject( repoId, project );
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        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 0cd5bc3b29d5b8f08652784ddc868e45fbd8cea8..df75dde2fe520e3250f64b84df39da1b7359ee2a 100644 (file)
@@ -88,11 +88,24 @@ public class LegacyConverterArtifactConsumer
         this.managedRepository.setRepository( repository );
     }
 
+    @Override
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void completeScan()
     {
 
     }
 
+    @Override
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return excludes;
@@ -124,6 +137,13 @@ public class LegacyConverterArtifactConsumer
         }
     }
 
+    @Override
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     public String getDescription()
     {
         return "Legacy Artifact to Default Artifact Converter";
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 6f22edebe1111995a88a5bbdf50279e606239e59..5b1e30a5dceee0f10f8f96d56cfeb73f071768a3 100644 (file)
@@ -237,7 +237,7 @@ public class RepositoryContentConsumers implements ApplicationContextAware
         // Run the repository consumers
         try
         {   
-            Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime() );
+            Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime(), false );
 
             List<KnownRepositoryContentConsumer> selectedKnownConsumers = getSelectedKnownConsumers();
 
@@ -267,9 +267,12 @@ public class RepositoryContentConsumers implements ApplicationContextAware
             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 );
@@ -280,7 +283,7 @@ public class RepositoryContentConsumers implements ApplicationContextAware
                 CollectionUtils.forAllDo( selectedInvalidConsumers, closure );
             }
 
-            TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository );
+            TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository, false );
 
             CollectionUtils.forAllDo( selectedKnownConsumers, scanCompletedClosure );
         }
index a2a1df75d269a8029471906f6614e79086465ba6..1ec74939111f4ba3db399fdb7a58ed863da7caee 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 5fadde292de4a64eb1cd2fe50dcf5a6fc8785087..61846357520e067d26018cbbe58c0455c4fe2c91 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 067ab1641e8177f5e259d7736a0ae7344672475e..2976637b850764b1ff4c04772d2a047b0023d5e1 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 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 6e39db51a3542c9eb6bcd48a61150b611447fb1e..ab5879ae6d0972d4bca30170b58b393e49529df0 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 8498b4dd8dc55c0288abd38ab2a6c3be077c6201..6be497eb1b383204b889b816b9db25168201e5ba 100644 (file)
@@ -76,17 +76,37 @@ public class KnownScanConsumer
         /* do nothing */
     }
 
+    @Override
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void processFile( String path )
         throws ConsumerException
     {
         this.processCount++;
     }
 
+    @Override
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     public void completeScan()
     {
         /* do nothing */
     }
 
+    @Override
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+       completeScan();
+    }
+
     public int getProcessCount()
     {
         return processCount;
index e6a5cc39193224bfc746dc3e456512cc30baa688..53e5433a6e3b51cfa8aad22373bad1e615874175 100644 (file)
@@ -270,16 +270,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();
 
@@ -293,7 +293,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();
@@ -301,8 +301,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();
@@ -318,14 +318,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 340be8b2bca2486de5f8696dffb24715aca269e3..0465d5e70f8ad0c8ea8641784349b3ab8afa4d6f 100644 (file)
@@ -50,11 +50,24 @@ public class SampleKnownConsumer
         /* nothing to do */
     }
 
+    @Override
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void completeScan()
     {
         /* nothing to do */
     }
 
+    @Override
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public List<String> getExcludes()
     {
         return null;
@@ -71,6 +84,13 @@ public class SampleKnownConsumer
         /* nothing to do */
     }
 
+    @Override
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     public String getDescription()
     {
         return "Sample Known Consumer";
index 831c86e6c359d2ac2f10d06007fa5573d9151165..f6c77ba30371374cfaa3d991d1e44b648534b8a6 100644 (file)
@@ -39,6 +39,7 @@ import org.sonatype.nexus.index.ArtifactInfo;
 import org.sonatype.nexus.index.DefaultArtifactContextProducer;
 import org.sonatype.nexus.index.IndexerEngine;
 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;
 
@@ -77,44 +78,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 = ArtifactIndexingTask.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" );
                 }
@@ -156,6 +148,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
                         {
@@ -180,6 +179,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 9b600334dd2dee85d77e95ff4b837c723af5573d..4d6c361ed674413364447d36025315adf3c93dd4 100644 (file)
@@ -45,6 +45,8 @@ public class ArtifactIndexingTask
 
     private final IndexingContext context;
 
+    private boolean executeOnEntireRepo = true;
+
     public ArtifactIndexingTask( ManagedRepositoryConfiguration repository, File resourceFile, Action action,
                                  IndexingContext context )
     {
@@ -54,6 +56,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-scheduler/archiva-scheduler-indexing/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/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 7c168d239b17a19347cf52d0ba6cfc229ddbdcfb..328450c95279c65647c12859210436dc5b986b06 100644 (file)
@@ -87,6 +87,13 @@ public class TestConsumer
         }
     }
 
+    @Override
+    public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repository, whenGathered );
+    }
+
     public void processFile( String path )
         throws ConsumerException
     {
@@ -103,10 +110,23 @@ public class TestConsumer
         }
     }
 
+    @Override
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        processFile( path );
+    }
+
     public void completeScan()
     {
     }
 
+    @Override
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public Collection<ArtifactReference> getConsumed()
     {
         return consumed;
index 353318e0482f11c594a5f3dcabf1cb53cb77fde4..f8203dff002c0f997cd935db377c35bb41e0a8fb 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.
     -->
index 9c3135a9222cc5f395ae7170cee69f29a9d6b34d..95572ec64e6abd4ea6d3a28b48df57f2ea38f886 100644 (file)
@@ -132,6 +132,12 @@ public class DuplicateArtifactsConsumer
         this.repositoryDir = new File( repo.getLocation() );
     }
 
+    public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        beginScan( repo, whenGathered );   
+    }
+
     public void processFile( String path )
         throws ConsumerException
     {
@@ -202,11 +208,22 @@ public class DuplicateArtifactsConsumer
         }
     }
 
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        processFile( path );     
+    }
+
     public void completeScan()
     {
         // nothing to do
     }
 
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        completeScan();
+    }
+
     public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
     {
         if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
diff --git a/pom.xml b/pom.xml
index 95af5ffeb24b04f9b3f35653e920215b983bec7d..4547a9e49eaecf0ed653b2b4af66cd7a4751997c 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <dependency>
         <groupId>org.sonatype.nexus</groupId>
         <artifactId>nexus-indexer</artifactId>
-        <version>2.0.6</version>
+        <version>3.0.1</version>
         <exclusions>
           <exclusion>
             <groupId>org.codehaus.plexus</groupId>
       <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>