From 478c60608d6ca1bd5ac882e1c97679e019f26031 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Tue, 29 Jun 2021 21:09:52 +0200 Subject: Refactoring group handling --- .../archiva/repository/RepositoryHandler.java | 7 ++++++ .../repository/base/ArchivaRepositoryRegistry.java | 25 ++-------------------- .../repository/base/RepositoryGroupHandler.java | 14 +++++++++++- 3 files changed, 22 insertions(+), 24 deletions(-) (limited to 'archiva-modules/archiva-base') diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryHandler.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryHandler.java index 49fc4de12..4bb414cf8 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryHandler.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryHandler.java @@ -19,6 +19,7 @@ package org.apache.archiva.repository; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.repository.validation.RepositoryChecker; +import org.apache.archiva.repository.validation.RepositoryValidator; import java.util.Collection; import java.util.Map; @@ -158,6 +159,12 @@ public interface RepositoryHandler */ Collection getAll(); + /** + * Returns a validator that can be used to validate repository data + * @return a validator instance + */ + RepositoryValidator getValidator( ); + /** * Returns true, if the repository is registered with the given id, otherwise false * @param id the repository identifier diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/ArchivaRepositoryRegistry.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/ArchivaRepositoryRegistry.java index db1d626a2..d3eb836c2 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/ArchivaRepositoryRegistry.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/ArchivaRepositoryRegistry.java @@ -52,6 +52,7 @@ import org.apache.archiva.repository.RepositoryProvider; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.UnsupportedRepositoryTypeException; +import org.apache.archiva.repository.base.validation.CommonGroupValidator; import org.apache.archiva.repository.event.LifecycleEvent; import org.apache.archiva.repository.event.RepositoryEvent; import org.apache.archiva.repository.event.RepositoryIndexEvent; @@ -136,9 +137,6 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa private RepositoryGroupHandler groupHandler; private final Set> validators; - private final RepositoryChecker>> groupChecker; - private final RepositoryChecker>> managedChecker; - private final RepositoryChecker>> remoteChecker; private final ConfigurationHandler configurationHandler; @@ -152,27 +150,8 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa this.eventManager = new EventManager( this ); this.configurationHandler = configurationHandler; this.validators = initValidatorList( validatorList ); - this.groupChecker = initChecker( RepositoryGroup.class ); - this.managedChecker = initChecker( ManagedRepository.class ); - this.remoteChecker = initChecker( RemoteRepository.class ); } - private RepositoryChecker>> initChecker(Class clazz) { - return new RepositoryChecker>>( ) - { - @Override - public CheckedResult>> apply( R repositoryGroup ) - { - return this.apply( repositoryGroup ); - } - - @Override - public CheckedResult>> applyForUpdate( R repo ) - { - return this.applyForUpdate( repo ); - } - }; - } private Set> initValidatorList( List> validators ) { @@ -909,7 +888,7 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa rwLock.writeLock( ).lock( ); try { - return groupHandler.putWithCheck( repositoryGroupConfiguration, this.groupChecker ); + return groupHandler.putWithCheck( repositoryGroupConfiguration, groupHandler.getValidator() ); } finally { diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryGroupHandler.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryGroupHandler.java index 376be6665..6783f7467 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryGroupHandler.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryGroupHandler.java @@ -36,6 +36,7 @@ import org.apache.archiva.repository.event.RepositoryEvent; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.repository.validation.RepositoryChecker; +import org.apache.archiva.repository.validation.RepositoryValidator; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,9 +75,11 @@ public class RepositoryGroupHandler implements RepositoryHandler repositoryGroups = new HashMap<>( ); + private final RepositoryValidator validator; private Path groupsDirectory; + /** * Creates a new instance. All dependencies are injected on the constructor. * @@ -86,11 +89,14 @@ public class RepositoryGroupHandler implements RepositoryHandler repositoryGroupValidator + ) { this.configurationHandler = configurationHandler; this.mergedRemoteIndexesScheduler = mergedRemoteIndexesScheduler; this.repositoryRegistry = repositoryRegistry; + this.validator = repositoryGroupValidator; } @Override @@ -552,6 +558,12 @@ public class RepositoryGroupHandler implements RepositoryHandler getValidator( ) + { + return this.validator; + } + @Override public boolean has( String id ) { -- cgit v1.2.3