diff options
author | Martin Stockhammer <martin_s@apache.org> | 2021-06-29 21:09:52 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2021-06-29 21:09:52 +0200 |
commit | 478c60608d6ca1bd5ac882e1c97679e019f26031 (patch) | |
tree | e359316c0c3238c0c84c5480029fe4f357dbea43 /archiva-modules/archiva-base | |
parent | e8a70027d8342f78272b471aa0ac963c0a6f89be (diff) | |
download | archiva-478c60608d6ca1bd5ac882e1c97679e019f26031.tar.gz archiva-478c60608d6ca1bd5ac882e1c97679e019f26031.zip |
Refactoring group handling
Diffstat (limited to 'archiva-modules/archiva-base')
3 files changed, 22 insertions, 24 deletions
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; @@ -159,6 +160,12 @@ public interface RepositoryHandler<R extends Repository, C> Collection<R> getAll(); /** + * Returns a validator that can be used to validate repository data + * @return a validator instance + */ + RepositoryValidator<R> getValidator( ); + + /** * Returns <code>true</code>, if the repository is registered with the given id, otherwise <code>false</code> * @param id the repository identifier * @return <code>true</code>, if it is registered, otherwise <code>false</code> 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<RepositoryValidator<? extends Repository>> validators; - private final RepositoryChecker<RepositoryGroup, Map<String, List<ValidationError>>> groupChecker; - private final RepositoryChecker<ManagedRepository, Map<String, List<ValidationError>>> managedChecker; - private final RepositoryChecker<RemoteRepository, Map<String, List<ValidationError>>> 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 <R extends Repository> RepositoryChecker<R, Map<String, List<ValidationError>>> initChecker(Class<R> clazz) { - return new RepositoryChecker<R, Map<String, List<ValidationError>>>( ) - { - @Override - public CheckedResult<R, Map<String, List<ValidationError>>> apply( R repositoryGroup ) - { - return this.apply( repositoryGroup ); - } - - @Override - public CheckedResult<R, Map<String, List<ValidationError>>> applyForUpdate( R repo ) - { - return this.applyForUpdate( repo ); - } - }; - } private Set<RepositoryValidator<? extends Repository>> initValidatorList( List<RepositoryValidator<? extends Repository>> 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<RepositoryGroup private final MergedRemoteIndexesScheduler mergedRemoteIndexesScheduler; private final Map<String, RepositoryGroup> repositoryGroups = new HashMap<>( ); + private final RepositoryValidator<RepositoryGroup> validator; private Path groupsDirectory; + /** * Creates a new instance. All dependencies are injected on the constructor. * @@ -86,11 +89,14 @@ public class RepositoryGroupHandler implements RepositoryHandler<RepositoryGroup */ public RepositoryGroupHandler( ArchivaRepositoryRegistry repositoryRegistry, ConfigurationHandler configurationHandler, - @Named( "mergedRemoteIndexesScheduler#default" ) MergedRemoteIndexesScheduler mergedRemoteIndexesScheduler ) + @Named( "mergedRemoteIndexesScheduler#default" ) MergedRemoteIndexesScheduler mergedRemoteIndexesScheduler, + @Named( "repositoryValidator#common#group") RepositoryValidator<RepositoryGroup> repositoryGroupValidator + ) { this.configurationHandler = configurationHandler; this.mergedRemoteIndexesScheduler = mergedRemoteIndexesScheduler; this.repositoryRegistry = repositoryRegistry; + this.validator = repositoryGroupValidator; } @Override @@ -553,6 +559,12 @@ public class RepositoryGroupHandler implements RepositoryHandler<RepositoryGroup } @Override + public RepositoryValidator<RepositoryGroup> getValidator( ) + { + return this.validator; + } + + @Override public boolean has( String id ) { return repositoryGroups.containsKey( id ); |