From 352b1d8a65e2a61023ca6b96f6e15108986c06dd Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Thu, 22 Jan 2009 11:03:38 +0000 Subject: [PATCH] [MRM-749] o re-packaged TriggerScanCompleteClosure o invoke TriggerScanCompleteClosure at the end of the scan git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-nexus-indexer@736609 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/NexusIndexerConsumer.java | 13 ++--- .../lucene/NexusIndexerConsumerTest.java | 8 ++- .../functors/TriggerScanCompletedClosure.java | 52 +++++++++++++++++++ .../scanner/RepositoryContentConsumers.java | 2 +- .../scanner/RepositoryScannerInstance.java | 12 ++--- .../functors/TriggerScanCompletedClosure.java | 46 ---------------- 6 files changed, 73 insertions(+), 60 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java delete mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java index ce8f6b1c5..7176878a4 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java @@ -91,7 +91,7 @@ public class NexusIndexerConsumer public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered ) throws ConsumerException - { + { this.repository = repository; managedRepository = new File( repository.getLocation() ); File indexDirectory = new File( managedRepository, ".indexer" ); @@ -125,14 +125,14 @@ public class NexusIndexerConsumer throws ConsumerException { File artifactFile = new File( managedRepository, path ); - + ArtifactContext artifactContext = artifactContextProducer.getArtifactContext( context, artifactFile ); if ( artifactContext != null ) { try { - indexer.artifactDiscovered( artifactContext, context ); - + //indexer.artifactDiscovered( artifactContext, context ); + indexerEngine.index( context, artifactContext ); } catch ( IOException e ) @@ -143,12 +143,13 @@ public class NexusIndexerConsumer } public void completeScan() - { + { final File indexLocation = new File( managedRepository, ".index" ); try { - indexPacker.packIndex( context, indexLocation ); indexerEngine.endIndexing( context ); + + indexPacker.packIndex( context, indexLocation ); } catch ( IOException e ) { diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java index 4adb402f6..94f43f682 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java @@ -120,7 +120,13 @@ public class NexusIndexerConsumerTest ArtifactInfo artifactInfo = (ArtifactInfo) results.iterator().next(); assertEquals( "org.apache.archiva", artifactInfo.groupId ); assertEquals( "archiva-index-methods-jar-test", artifactInfo.artifactId ); - assertEquals( "test-repo", artifactInfo.repository ); + assertEquals( "test-repo", artifactInfo.repository ); + } + + public void testIndexerArtifactAlreadyIndexed() + throws Exception + { + } /*public void testIndexerIndexPom() diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java new file mode 100644 index 000000000..52a9ca18a --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java @@ -0,0 +1,52 @@ +package org.apache.archiva.repository.scanner.functors; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +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; + +/** + * TriggerScanCompletedClosure + */ +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/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumers.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumers.java index e81148620..6f35e81f3 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumers.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumers.java @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure; import org.apache.commons.collections.Closure; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.functors.IfClosure; @@ -38,7 +39,6 @@ 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; diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java index 1ae3e7960..e8d86d90c 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java @@ -23,6 +23,7 @@ import java.io.File; import java.util.Date; import java.util.List; +import org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure; import org.apache.commons.collections.Closure; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.functors.IfClosure; @@ -34,7 +35,6 @@ 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; @@ -91,11 +91,6 @@ public class RepositoryScannerInstance { consumerWantsFile.setCaseSensitive( false ); } - - TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure(repository); - - CollectionUtils.forAllDo(knownConsumers, scanCompletedClosure); - CollectionUtils.forAllDo(invalidConsumerList, scanCompletedClosure); } public RepositoryScannerInstance( ManagedRepositoryConfiguration repository, @@ -150,6 +145,11 @@ public class RepositoryScannerInstance public void directoryWalkFinished() { + TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure(repository); + + CollectionUtils.forAllDo( knownConsumers, scanCompletedClosure ); + CollectionUtils.forAllDo( invalidConsumers, scanCompletedClosure ); + log.info( "Walk Finished: [" + this.repository.getId() + "] " + this.repository.getLocation() ); stats.triggerFinished(); } 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 deleted file mode 100644 index 85548b588..000000000 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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() + "]"); - } - } -} -- 2.39.5