]> source.dussan.org Git - archiva.git/commitdiff
Indexer apparently works now. Yay
authorJames William Dumay <jdumay@apache.org>
Mon, 22 Dec 2008 04:53:12 +0000 (04:53 +0000)
committerJames William Dumay <jdumay@apache.org>
Mon, 22 Dec 2008 04:53:12 +0000 (04:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-nexus-indexer@728610 13f79535-47bb-0310-9956-ffa450edef68

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-lucene-consumers/src/main/java/org/apache/maven/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-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/TriggerScanCompletedClosure.java [new file with mode: 0644]
pom.xml

index 595da491ed99dd58dc75b208bcd4b6cefe317a08..203e5bd76ee42f8ccfc47086a1acfac2081ed1e3 100644 (file)
@@ -86,8 +86,6 @@ public interface RepositoryContentConsumer extends Consumer
      * NOTE: If the consumer opted to batch up processing requests in the {@link #processFile(String)} event
      * this would be the last opportunity to drain any processing queue's.
      * </p>
-     *
-     * @todo! this is never called by the RepositoryScannerInstance
      */
     public void completeScan();
 
index 6a2be7617f757e8cd309638f3881cc07e78c9d8c..6664ee43cc6139e1e90731d7803015be46a397a3 100644 (file)
@@ -25,7 +25,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
-import org.apache.maven.archiva.configuration.FileTypes;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
 import org.apache.maven.archiva.consumers.ConsumerException;
@@ -39,6 +38,8 @@ import org.sonatype.nexus.index.ArtifactContextProducer;
 import org.sonatype.nexus.index.DefaultArtifactContextProducer;
 import org.sonatype.nexus.index.NexusIndexer;
 import org.sonatype.nexus.index.context.IndexingContext;
+import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException;
+import org.sonatype.nexus.index.packer.IndexPacker;
 
 public class NexusIndexerConsumer 
     extends AbstractMonitoredConsumer
@@ -50,15 +51,20 @@ public class NexusIndexerConsumer
 
     private final ArtifactContextProducer artifactContextProducer;
 
+    private final IndexPacker indexPacker;
+
     private ManagedRepositoryConfiguration repository;
 
     private ManagedDefaultRepositoryContent repositoryContent;
 
     private IndexingContext context;
 
-    public NexusIndexerConsumer(NexusIndexer indexer)
+    private File managedRepository;
+
+    public NexusIndexerConsumer(NexusIndexer indexer, IndexPacker indexPacker)
     {
         this.indexer = indexer;
+        this.indexPacker = indexPacker;
         this.artifactContextProducer = new DefaultArtifactContextProducer();
     }
 
@@ -81,7 +87,7 @@ public class NexusIndexerConsumer
         throws ConsumerException
     {
         this.repository = repository;
-        File managedRepository = new File(repository.getLocation());
+        managedRepository = new File(repository.getLocation());
         File indexDirectory = new File(managedRepository, ".indexer");
 
         repositoryContent = new ManagedDefaultRepositoryContent();
@@ -91,19 +97,31 @@ public class NexusIndexerConsumer
         {
             try
             {
-                context = indexer.addIndexingContextForced(repository.getId(), repository.getId(), managedRepository, indexDirectory, "repourl", "updateurl", NexusIndexer.FULL_INDEX);
+                context = indexer.addIndexingContext(repository.getId(), repository.getId(), managedRepository, indexDirectory, null, null, NexusIndexer.FULL_INDEX);
                 context.setSearchable(repository.isScanned());
             }
+            catch (UnsupportedExistingLuceneIndexException e)
+            {
+                log.error("Could not create index at " + indexDirectory.getAbsoluteFile(), e);
+            }
             catch (IOException e)
             {
-                log.error("Could not create FSDirectory for index at " + indexDirectory.getAbsoluteFile(), e);
+                log.error("Could not create index at " + indexDirectory.getAbsoluteFile(), e);
             }
         }
     }
 
     public void completeScan()
     {
-        /** do nothing **/
+        final File indexLocation = new File(managedRepository, ".index");
+        try
+        {
+            indexPacker.packIndex(context, indexLocation);
+        }
+        catch (IOException e)
+        {
+            log.error("Could not pack index" + indexLocation.getAbsolutePath(), e );
+        }
     }
 
     public List<String> getExcludes()
@@ -119,26 +137,19 @@ public class NexusIndexerConsumer
     public void processFile(String path) 
         throws ConsumerException
     {
-        File artifactFile = new File(path);
-
-        try
-        {
-            repositoryContent.toArtifactReference(path);
-        }
-        catch (LayoutException e)
-        {
-            /** do nothing **/
-            return;
-        }
+        File artifactFile = new File(managedRepository, path);
 
         ArtifactContext artifactContext = artifactContextProducer.getArtifactContext(context, artifactFile);
-        try
-        {
-            indexer.artifactDiscovered(artifactContext, context);
-        }
-        catch (IOException e)
+        if (artifactContext != null)
         {
-            throw new ConsumerException(e.getMessage(), e);
+            try
+            {
+                indexer.artifactDiscovered(artifactContext, context);
+            }
+            catch (IOException e)
+            {
+                throw new ConsumerException(e.getMessage(), e);
+            }
         }
     }
 }
index 747cc768dbfcb991ef0263fc3ae42d7cad41d227..66905fa0437a6fdc080cf35031ed5e11b3cf0631 100644 (file)
@@ -5,5 +5,6 @@
 
     <bean id="indexerConsumer" class="org.apache.maven.archiva.consumers.lucene.NexusIndexerConsumer">
         <constructor-arg ref="nexusIndexer"/>
+        <constructor-arg ref="indexPacker"/>
     </bean>
 </beans>
\ No newline at end of file
index 83042e2874974ab2ec21270254966b426fa8372b..e81148620813240f51aeff32c9def6022611c1cb 100644 (file)
@@ -38,6 +38,7 @@ import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
 import org.apache.maven.archiva.repository.scanner.functors.ConsumerProcessFileClosure;
 import org.apache.maven.archiva.repository.scanner.functors.ConsumerWantsFilePredicate;
 import org.apache.maven.archiva.repository.scanner.functors.TriggerBeginScanClosure;
+import org.apache.maven.archiva.repository.scanner.functors.TriggerScanCompletedClosure;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
@@ -256,6 +257,11 @@ public class RepositoryContentConsumers implements ApplicationContextAware
                 // Nothing known processed this file.  It is invalid!
                 CollectionUtils.forAllDo( selectedInvalidConsumers, closure );
             }
+
+            TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure(repository);
+
+            CollectionUtils.forAllDo(selectedKnownConsumers, scanCompletedClosure);
+            CollectionUtils.forAllDo(selectedKnownConsumers, scanCompletedClosure);
         }
         finally
         {
index d0fd38ad1131536cbc37fac9037c9dd8d2c5508d..1ae3e796061e61a28a8edc3ef20deccce0d5b174 100644 (file)
@@ -34,6 +34,7 @@ import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
 import org.apache.maven.archiva.repository.scanner.functors.ConsumerProcessFileClosure;
 import org.apache.maven.archiva.repository.scanner.functors.ConsumerWantsFilePredicate;
 import org.apache.maven.archiva.repository.scanner.functors.TriggerBeginScanClosure;
+import org.apache.maven.archiva.repository.scanner.functors.TriggerScanCompletedClosure;
 import org.codehaus.plexus.util.DirectoryWalkListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -90,6 +91,11 @@ public class RepositoryScannerInstance
         {
             consumerWantsFile.setCaseSensitive( false );
         }
+
+        TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure(repository);
+
+        CollectionUtils.forAllDo(knownConsumers, scanCompletedClosure);
+        CollectionUtils.forAllDo(invalidConsumerList, scanCompletedClosure);
     }
 
     public RepositoryScannerInstance( ManagedRepositoryConfiguration repository,
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java
new file mode 100644 (file)
index 0000000..85548b5
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *  Copyright 2008 jdumay.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  under the License.
+ */
+
+package org.apache.maven.archiva.repository.scanner.functors;
+
+import org.apache.commons.collections.Closure;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TriggerScanCompletedClosure implements Closure
+{
+    private Logger log = LoggerFactory.getLogger( TriggerScanCompletedClosure.class );
+
+    private final ManagedRepositoryConfiguration repository;
+
+    public TriggerScanCompletedClosure(ManagedRepositoryConfiguration repository)
+    {
+        this.repository = repository;
+    }
+
+    public void execute(Object input)
+    {
+        if ( input instanceof RepositoryContentConsumer )
+        {
+            RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
+            consumer.completeScan();
+            log.info( "Consumer [" + consumer.getId() + "] completed for repository [" + repository.getId() + "]");
+        }
+    }
+}
diff --git a/pom.xml b/pom.xml
index bfac4b362f93c2137cb3ca0e0d253ed33f23decb..aa3cecb0ed5bd350e93612846fb671fa9752f4a9 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <dependency>
         <groupId>org.sonatype.nexus</groupId>
         <artifactId>nexus-indexer</artifactId>
-        <version>1.1.2.3</version>
+        <version>1.1.1</version>
         <exclusions>
           <exclusion>
             <groupId>org.codehaus.plexus</groupId>