From: Olivier Lamy Date: Wed, 30 Apr 2014 07:22:41 +0000 (+1000) Subject: [MRM-1837] cleanup registry listeners from Archiva Configuration X-Git-Tag: archiva-2.1.0~49 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7808ee5fafdb02b7d9e0b104fc4a8642bce4f8ac;p=archiva.git [MRM-1837] cleanup registry listeners from Archiva Configuration --- diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java index 3a259da85..4f6798c10 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java @@ -70,13 +70,15 @@ public interface ArchivaConfiguration void removeListener( ConfigurationListener listener ); /** - * Add a registry listener to notify of events in plexus-registry. + * Add a registry listener to notify of events in spring-registry. * * @param listener the listener * TODO: Remove in future. */ void addChangeListener( RegistryListener listener ); + void removeChangeListener( RegistryListener listener ); + /** * reload configuration from file included registry * diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java index 6373a503b..9b403d1d2 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java @@ -650,6 +650,8 @@ public class DefaultArchivaConfiguration listeners.remove( listener ); } + + @Override public void addChangeListener( RegistryListener listener ) { @@ -673,6 +675,13 @@ public class DefaultArchivaConfiguration } } + @Override + public void removeChangeListener( RegistryListener listener ) + { + boolean removed = registryListeners.remove( listener ); + log.debug( "RegistryListener: '{}' removed {}", listener, removed ); + } + @PostConstruct public void initialize() { diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/KnownRepositoryContentConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/KnownRepositoryContentConsumer.java index 41c4bca22..4a884a63a 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/KnownRepositoryContentConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/KnownRepositoryContentConsumer.java @@ -21,8 +21,6 @@ package org.apache.archiva.consumers; /** * Consumer for Known Repository Content. - * - * */ public interface KnownRepositoryContentConsumer extends RepositoryContentConsumer diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java index e1b6009f2..cb1f78f5c 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java @@ -70,32 +70,17 @@ public class MetadataUpdaterConsumer */ private String id = "metadata-updater"; - /** - * default-value="Update / Create maven-metadata.xml files" - */ private String description = "Update / Create maven-metadata.xml files"; - /** - * - */ @Inject private RepositoryContentFactory repositoryFactory; - /** - * - */ @Inject private MetadataTools metadataTools; - /** - * - */ @Inject private ArchivaConfiguration configuration; - /** - * - */ @Inject private FileTypes filetypes; diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java index 7cd49a652..935f2a6e0 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java @@ -88,6 +88,12 @@ public class MockConfiguration registryListeners.add( listener ); } + @Override + public void removeChangeListener( RegistryListener listener ) + { + registryListeners.remove( listener ); + } + @Override public Configuration getConfiguration() { diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java index 492845d4f..56ef2fd42 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java @@ -21,6 +21,7 @@ package org.apache.archiva.repository.scanner; import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; @@ -32,6 +33,7 @@ import org.springframework.stereotype.Service; import javax.inject.Inject; import java.io.File; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -57,9 +59,10 @@ public class DefaultRepositoryScanner public RepositoryScanStatistics scan( ManagedRepository repository, long changesSince ) throws RepositoryScannerException { + List knownContentConsumers = null; try { - List knownContentConsumers = repositoryContentConsumers.getSelectedKnownConsumers(); + knownContentConsumers = repositoryContentConsumers.getSelectedKnownConsumers(); List invalidContentConsumers = repositoryContentConsumers.getSelectedInvalidConsumers(); List ignoredPatterns = filetypes.getFileTypePatterns( FileTypes.IGNORED ); @@ -68,6 +71,9 @@ public class DefaultRepositoryScanner catch ( RepositoryAdminException e ) { throw new RepositoryScannerException( e.getMessage(), e ); + } finally + { + repositoryContentConsumers.releaseSelectedKnownConsumers( knownContentConsumers ); } } diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java index 4ce22d2c4..4c6077a69 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java @@ -23,9 +23,11 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.admin.ArchivaAdministration; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.common.utils.BaseFile; +import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate; +import org.apache.archiva.redback.components.registry.RegistryListener; import org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure; import org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure; import org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure; @@ -48,7 +50,7 @@ import java.util.Map; /** * RepositoryContentConsumerUtil */ -@Service( "repositoryContentConsumers" ) +@Service("repositoryContentConsumers") public class RepositoryContentConsumers implements ApplicationContextAware { @@ -62,6 +64,9 @@ public class RepositoryContentConsumers private List selectedInvalidConsumers; + @Inject + private ArchivaConfiguration archivaConfiguration; + @Inject public RepositoryContentConsumers( ArchivaAdministration archivaAdministration ) { @@ -156,7 +161,7 @@ public class RepositoryContentConsumers * @return the list of {@link KnownRepositoryContentConsumer} that have been selected * by the active configuration. */ - public synchronized List getSelectedKnownConsumers() + public List getSelectedKnownConsumers() throws RepositoryAdminException { // FIXME only for testing @@ -178,6 +183,22 @@ public class RepositoryContentConsumers return ret; } + public void releaseSelectedKnownConsumers( List repositoryContentConsumers ) + { + if ( repositoryContentConsumers == null ) + { + return; + } + for ( KnownRepositoryContentConsumer knownRepositoryContentConsumer : repositoryContentConsumers ) + { + if ( RegistryListener.class.isAssignableFrom( knownRepositoryContentConsumer.getClass() ) ) + { + archivaConfiguration.removeChangeListener( + RegistryListener.class.cast( knownRepositoryContentConsumer ) ); + } + } + } + /** * Get the list of {@link InvalidRepositoryContentConsumer} objects that are * selected according to the active configuration. @@ -248,12 +269,13 @@ public class RepositoryContentConsumers public void executeConsumers( ManagedRepository repository, File localFile, boolean updateRelatedArtifacts ) throws RepositoryAdminException { + List selectedKnownConsumers = null; // Run the repository consumers try { Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime(), false ); - List selectedKnownConsumers = getSelectedKnownConsumers(); + selectedKnownConsumers = getSelectedKnownConsumers(); // MRM-1212/MRM-1197 // - do not create missing/fix invalid checksums and update metadata when deploying from webdav since these are uploaded by maven @@ -307,6 +329,7 @@ public class RepositoryContentConsumers CollectionUtils.forAllDo( availableKnownConsumers, triggerCompleteScan ); CollectionUtils.forAllDo( availableInvalidConsumers, triggerCompleteScan ); */ + releaseSelectedKnownConsumers( selectedKnownConsumers ); } } diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java index 12ab3b99c..20562995c 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java @@ -66,6 +66,12 @@ public class TestConfiguration // no op } + @Override + public void removeChangeListener( RegistryListener listener ) + { + // no op + } + @Override public void reload() { diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java index 09ef4959f..51479bbbd 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java @@ -64,6 +64,12 @@ public class MockConfiguration registryListeners.add( listener ); } + @Override + public void removeChangeListener( RegistryListener listener ) + { + registryListeners.remove( listener ); + } + @Override public Configuration getConfiguration() { diff --git a/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java b/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java index 642e52371..b4659ac34 100644 --- a/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java +++ b/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java @@ -66,6 +66,12 @@ public class StubConfiguration throw new UnsupportedOperationException(); } + @Override + public void removeChangeListener( RegistryListener listener ) + { + throw new UnsupportedOperationException(); + } + @Override public void reload() {