From 292dbe1bb4323dd299d36b78f37d9c1d55c889f8 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Tue, 31 Aug 2021 15:48:12 +0200 Subject: [PATCH] Migration to remote repository handler --- .../test/java/SimpleArtifactConsumerTest.java | 8 +- .../core/AbstractArtifactConsumerTest.java | 15 +- .../AbstractRepositoryPurgeTest.java | 9 +- .../lucene/NexusIndexerConsumerTest.java | 19 +- .../model/remote/RemoteRepositoryAdmin.java | 8 - .../DefaultManagedRepositoryAdmin.java | 23 +- .../DefaultNetworkProxyAdmin.java | 12 +- .../remote/DefaultRemoteRepositoryAdmin.java | 197 ++++---- .../AbstractRepositoryAdminTest.java | 10 +- .../group/RepositoryGroupAdminTest.java | 3 - .../archiva/repository/RepositoryHandler.java | 9 + .../repository/RepositoryRegistry.java | 13 - .../base/AbstractRepositoryHandler.java | 3 +- .../base/ArchivaRepositoryRegistry.java | 452 ++++-------------- .../base/RepositoryHandlerDependencies.java | 43 ++ .../managed/ManagedRepositoryHandler.java | 78 ++- .../base/remote/BasicRemoteRepository.java | 7 +- .../BasicRemoteRepositoryValidator.java | 147 ++++++ .../base/remote/RemoteRepositoryHandler.java | 452 ++++++++++++++++++ .../base/ArchivaRepositoryRegistryTest.java | 17 +- .../BasicRepositoryGroupValidatorTest.java | 5 +- .../group/RepositoryGroupHandlerTest.java | 28 ++ .../BasicRemoteRepositoryValidatorTest.java | 233 +++++++++ .../remote/RemoteRepositoryHandlerTest.java | 426 +++++++++++++++++ .../src/test/resources/archiva-remote.xml | 219 +++++++++ .../test/resources/spring-context-remote.xml | 57 +++ .../indexer/maven/MavenIndexManagerTest.java | 12 +- .../search/AbstractMavenRepositorySearch.java | 12 +- .../search/MavenRepositorySearchOSGITest.java | 9 +- .../MavenRepositorySearchPaginateTest.java | 10 +- .../archiva/proxy/AbstractProxyTestCase.java | 31 +- .../proxy/CacheFailuresTransferTest.java | 3 +- .../archiva/proxy/HttpProxyTransferTest.java | 6 +- .../maven/MavenRepositoryProvider.java | 25 +- ...yMetadataResolverMRM1411RepoGroupTest.java | 4 +- ...RepositoryMetadataResolverMRM1411Test.java | 4 +- ...oryMetadataResolverManagedReleaseTest.java | 4 +- ...ryMetadataResolverManagedSnapshotTest.java | 4 +- .../Maven2RepositoryMetadataResolverTest.java | 4 +- .../mock/configuration/MockRepoAdmin.java | 8 - .../ArchivaIndexingTaskExecutorTest.java | 15 +- .../maven/DownloadRemoteIndexTaskTest.java | 10 +- .../mock/MockRemoteRepositoryAdmin.java | 7 - ...ivaRepositoryScanningTaskExecutorTest.java | 8 +- .../AbstractRepositoryServletTestCase.java | 19 +- .../webdav/ArchivaDavResourceFactoryTest.java | 15 +- 46 files changed, 1969 insertions(+), 734 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryHandlerDependencies.java create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/remote/BasicRemoteRepositoryValidator.java create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/remote/RemoteRepositoryHandler.java create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/remote/BasicRemoteRepositoryValidatorTest.java create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/remote/RemoteRepositoryHandlerTest.java create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/archiva-remote.xml create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/spring-context-remote.xml diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/SimpleArtifactConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/SimpleArtifactConsumerTest.java index 9f3f2f3f5..445ab9859 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/SimpleArtifactConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/SimpleArtifactConsumerTest.java @@ -23,7 +23,7 @@ import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; import org.apache.archiva.repository.base.managed.BasicManagedRepository; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryRegistry; import org.junit.Before; @@ -59,11 +59,7 @@ public class SimpleArtifactConsumerTest @SuppressWarnings( "unused" ) @Inject - private ManagedRepositoryHandler managedRepositoryHandler; - - @SuppressWarnings( "unused" ) - @Inject - private org.apache.archiva.repository.base.group.RepositoryGroupHandler repositoryGroupHandler; + private RepositoryHandlerDependencies repositoryHandlerDependencies; @Inject private RepositorySessionFactory repositorySessionFactory; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java index b8f6d55e1..8a50d78a4 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java @@ -26,24 +26,21 @@ import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate; import org.apache.archiva.repository.RepositoryRegistry; -import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.lang3.StringUtils; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.context.ApplicationContext; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; import java.nio.file.Path; import java.nio.file.Paths; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; @RunWith( ArchivaSpringJUnit4ClassRunner.class ) @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) @@ -65,11 +62,7 @@ public abstract class AbstractArtifactConsumerTest @SuppressWarnings( "unused" ) @Inject - RepositoryGroupHandler repositoryGroupHandler; - - @SuppressWarnings( "unused" ) - @Inject - ManagedRepositoryHandler managedRepositoryHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; @Before diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java index 5300a4a67..fc4311247 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java @@ -24,8 +24,7 @@ import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.repository.maven.metadata.storage.Maven2RepositoryPathTranslator; import org.apache.archiva.repository.base.managed.BasicManagedRepository; import org.apache.archiva.repository.ReleaseScheme; @@ -114,11 +113,7 @@ public abstract class AbstractRepositoryPurgeTest @SuppressWarnings( "unused" ) @Inject - RepositoryGroupHandler repositoryGroupHandler; - - @SuppressWarnings( "unused" ) - @Inject - ManagedRepositoryHandler managedRepositoryHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; @Before diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-indexer-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-indexer-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java index d6198e3d1..cf2768584 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-indexer-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-indexer-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java @@ -21,14 +21,13 @@ package org.apache.archiva.consumers.lucene; import junit.framework.TestCase; import org.apache.archiva.common.utils.PathUtil; +import org.apache.archiva.components.taskqueue.TaskQueueException; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.FileTypes; -import org.apache.archiva.components.taskqueue.TaskQueueException; +import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.repository.base.managed.BasicManagedRepository; -import org.apache.archiva.repository.ReleaseScheme; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; import org.apache.archiva.scheduler.ArchivaTaskScheduler; import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; @@ -45,7 +44,11 @@ import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.*; +import java.util.Calendar; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; /** * NexusIndexerConsumerTest @@ -100,11 +103,7 @@ public class NexusIndexerConsumerTest @SuppressWarnings( "unused" ) @Inject - RepositoryGroupHandler repositoryGroupHandler; - - @SuppressWarnings( "unused" ) - @Inject - ManagedRepositoryHandler managedRepositoryHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; @Override @Before diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/remote/RemoteRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/remote/RemoteRepositoryAdmin.java index f9bc61a29..988e2cb77 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/remote/RemoteRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/remote/RemoteRepositoryAdmin.java @@ -51,12 +51,4 @@ public interface RemoteRepositoryAdmin Map getRemoteRepositoriesAsMap() throws RepositoryAdminException; - /** - * @param repository - * @return - * @throws RepositoryAdminException - * @since 1.4-M2 - */ - ArchivaIndexingContext createIndexContext( RemoteRepository repository ) - throws RepositoryAdminException; } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java index b8cd3a893..da240c111 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java @@ -23,28 +23,27 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; import org.apache.archiva.admin.repository.AbstractRepositoryAdmin; +import org.apache.archiva.components.cache.Cache; +import org.apache.archiva.components.taskqueue.TaskQueueException; import org.apache.archiva.configuration.Configuration; -import org.apache.archiva.configuration.IndeterminateConfigurationException; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.archiva.configuration.ProxyConnectorConfiguration; -import org.apache.archiva.configuration.RepositoryGroupConfiguration; import org.apache.archiva.indexer.ArchivaIndexManager; import org.apache.archiva.indexer.IndexManagerFactory; import org.apache.archiva.indexer.IndexUpdateFailedException; import org.apache.archiva.metadata.model.facets.AuditEvent; -import org.apache.archiva.metadata.repository.*; +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; +import org.apache.archiva.metadata.repository.MetadataSessionException; +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsManager; -import org.apache.archiva.components.cache.Cache; -import org.apache.archiva.components.registry.RegistryException; -import org.apache.archiva.components.taskqueue.TaskQueueException; import org.apache.archiva.redback.role.RoleManager; import org.apache.archiva.redback.role.RoleManagerException; import org.apache.archiva.repository.ReleaseScheme; -import org.apache.archiva.repository.Repository; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryRegistry; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.StagingRepositoryFeature; @@ -88,11 +87,9 @@ public class DefaultManagedRepositoryAdmin @Inject private RepositoryRegistry repositoryRegistry; + @SuppressWarnings( "unused" ) @Inject - private ManagedRepositoryHandler managedRepositoryHandler; - - @Inject - private RepositoryGroupHandler repositoryGroupHandler; + private RepositoryHandlerDependencies managedRepositoryHandler; @Inject @Named(value = "archivaTaskScheduler#repository") diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java index 5c03abc1f..b6ccc73ff 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/networkproxy/DefaultNetworkProxyAdmin.java @@ -133,10 +133,6 @@ public class DefaultNetworkProxyAdmin throw new RepositoryAdminException( "cannot delete NetworkProxy with id " + networkProxyId + " as not exist" ); } - Configuration configuration = getArchivaConfiguration().getConfiguration(); - NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy ); - configuration.removeNetworkProxy( networkProxyConfiguration ); - for ( RemoteRepository repo : repositoryRegistry.getRemoteRepositories()) { if (repo.supportsFeature( RemoteIndexFeature.class )) { RemoteIndexFeature rif = repo.getFeature( RemoteIndexFeature.class ).get(); @@ -144,7 +140,7 @@ public class DefaultNetworkProxyAdmin rif.setProxyId( null ); try { - repositoryRegistry.putRepository( repo, configuration); + repositoryRegistry.putRepository( repo ); } catch ( RepositoryException e ) { @@ -154,9 +150,11 @@ public class DefaultNetworkProxyAdmin } } - triggerAuditEvent( networkProxy.getId(), null, AuditEvent.DELETE_NETWORK_PROXY, auditInformation ); - + Configuration configuration = getArchivaConfiguration().getConfiguration(); + NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy ); + configuration.removeNetworkProxy( networkProxyConfiguration ); saveConfiguration( configuration ); + triggerAuditEvent( networkProxy.getId(), null, AuditEvent.DELETE_NETWORK_PROXY, auditInformation ); } protected NetworkProxy getNetworkProxy( NetworkProxyConfiguration networkProxyConfiguration ) diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java index 3e655d927..4a845beea 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java @@ -26,7 +26,6 @@ import org.apache.archiva.common.utils.PathUtil; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.archiva.configuration.RepositoryCheckPath; -import org.apache.archiva.indexer.ArchivaIndexingContext; import org.apache.archiva.metadata.model.facets.AuditEvent; import org.apache.archiva.repository.RemoteRepository; import org.apache.archiva.repository.RepositoryCredentials; @@ -40,7 +39,6 @@ import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import javax.inject.Inject; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -49,7 +47,7 @@ import java.util.stream.Collectors; * @author Olivier Lamy * @since 1.4-M1 */ -@Service("remoteRepositoryAdmin#default") +@Service( "remoteRepositoryAdmin#default" ) public class DefaultRemoteRepositoryAdmin extends AbstractRepositoryAdmin implements RemoteRepositoryAdmin @@ -60,134 +58,136 @@ public class DefaultRemoteRepositoryAdmin @PostConstruct - private void initialize() + private void initialize( ) throws RepositoryAdminException { - for ( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository : getRemoteRepositories() ) - { - createIndexContext( remoteRepository ); - } } /* - * Conversion between the repository from the registry and the serialized DTO for the admin API - */ - private org.apache.archiva.admin.model.beans.RemoteRepository convertRepo( RemoteRepository repo ) { - if (repo==null) { + * Conversion between the repository from the registry and the serialized DTO for the admin API + */ + private org.apache.archiva.admin.model.beans.RemoteRepository convertRepo( RemoteRepository repo ) + { + if ( repo == null ) + { return null; } - org.apache.archiva.admin.model.beans.RemoteRepository adminRepo = new org.apache.archiva.admin.model.beans.RemoteRepository( getArchivaConfiguration().getDefaultLocale() ); + org.apache.archiva.admin.model.beans.RemoteRepository adminRepo = new org.apache.archiva.admin.model.beans.RemoteRepository( getArchivaConfiguration( ).getDefaultLocale( ) ); setBaseRepoAttributes( adminRepo, repo ); - adminRepo.setUrl( convertUriToString( repo.getLocation() )); - adminRepo.setCronExpression( repo.getSchedulingDefinition() ); - adminRepo.setCheckPath( repo.getCheckPath() ); - adminRepo.setExtraHeaders( repo.getExtraHeaders() ); - adminRepo.setExtraParameters( repo.getExtraParameters() ); - adminRepo.setTimeout( (int) repo.getTimeout().getSeconds() ); - RepositoryCredentials creds = repo.getLoginCredentials(); - if (creds!=null && creds instanceof PasswordCredentials) { + adminRepo.setUrl( convertUriToString( repo.getLocation( ) ) ); + adminRepo.setCronExpression( repo.getSchedulingDefinition( ) ); + adminRepo.setCheckPath( repo.getCheckPath( ) ); + adminRepo.setExtraHeaders( repo.getExtraHeaders( ) ); + adminRepo.setExtraParameters( repo.getExtraParameters( ) ); + adminRepo.setTimeout( (int) repo.getTimeout( ).getSeconds( ) ); + RepositoryCredentials creds = repo.getLoginCredentials( ); + if ( creds != null && creds instanceof PasswordCredentials ) + { PasswordCredentials pCreds = (PasswordCredentials) creds; - adminRepo.setUserName( pCreds.getUsername() ); - adminRepo.setPassword( new String(pCreds.getPassword()!=null ? pCreds.getPassword() : new char[0]) ); + adminRepo.setUserName( pCreds.getUsername( ) ); + adminRepo.setPassword( new String( pCreds.getPassword( ) != null ? pCreds.getPassword( ) : new char[0] ) ); } - if (repo.supportsFeature( RemoteIndexFeature.class )) { - RemoteIndexFeature rif = repo.getFeature( RemoteIndexFeature.class ).get(); - adminRepo.setRemoteIndexUrl( convertUriToString( rif.getIndexUri() ) ); - adminRepo.setDownloadRemoteIndex( rif.isDownloadRemoteIndex() ); - adminRepo.setRemoteDownloadNetworkProxyId( rif.getProxyId() ); - adminRepo.setDownloadRemoteIndexOnStartup( rif.isDownloadRemoteIndexOnStartup() ); - adminRepo.setRemoteDownloadTimeout( (int) rif.getDownloadTimeout().getSeconds() ); + if ( repo.supportsFeature( RemoteIndexFeature.class ) ) + { + RemoteIndexFeature rif = repo.getFeature( RemoteIndexFeature.class ).get( ); + adminRepo.setRemoteIndexUrl( convertUriToString( rif.getIndexUri( ) ) ); + adminRepo.setDownloadRemoteIndex( rif.isDownloadRemoteIndex( ) ); + adminRepo.setRemoteDownloadNetworkProxyId( rif.getProxyId( ) ); + adminRepo.setDownloadRemoteIndexOnStartup( rif.isDownloadRemoteIndexOnStartup( ) ); + adminRepo.setRemoteDownloadTimeout( (int) rif.getDownloadTimeout( ).getSeconds( ) ); } - if (repo.supportsFeature(IndexCreationFeature.class)) { - IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get(); - adminRepo.setIndexDirectory(PathUtil.getPathFromUri(icf.getIndexPath()).toString()); + if ( repo.supportsFeature( IndexCreationFeature.class ) ) + { + IndexCreationFeature icf = repo.getFeature( IndexCreationFeature.class ).get( ); + adminRepo.setIndexDirectory( PathUtil.getPathFromUri( icf.getIndexPath( ) ).toString( ) ); } - adminRepo.setDescription(repo.getDescription()); + adminRepo.setDescription( repo.getDescription( ) ); return adminRepo; } - private RemoteRepositoryConfiguration getRepositoryConfiguration( org.apache.archiva.admin.model.beans.RemoteRepository repo) { - RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration(); + private RemoteRepositoryConfiguration getRepositoryConfiguration( org.apache.archiva.admin.model.beans.RemoteRepository repo ) + { + RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration( ); setBaseRepoAttributes( repoConfig, repo ); - repoConfig.setUrl( getRepositoryCommonValidator().removeExpressions( repo.getUrl() ) ); - repoConfig.setRefreshCronExpression( repo.getCronExpression() ); - repoConfig.setCheckPath( repo.getCheckPath() ); - repoConfig.setExtraHeaders( repo.getExtraHeaders() ); - repoConfig.setExtraParameters( repo.getExtraParameters() ); - repoConfig.setUsername( repo.getUserName() ); - repoConfig.setPassword( repo.getPassword() ); - repoConfig.setTimeout( repo.getTimeout() ); - repoConfig.setRemoteIndexUrl( repo.getRemoteIndexUrl() ); - repoConfig.setDownloadRemoteIndex( repo.isDownloadRemoteIndex() ); - repoConfig.setRemoteDownloadNetworkProxyId( repo.getRemoteDownloadNetworkProxyId() ); - repoConfig.setDownloadRemoteIndexOnStartup( repo.isDownloadRemoteIndexOnStartup() ); - repoConfig.setRemoteDownloadTimeout( repo.getRemoteDownloadTimeout() ); - repoConfig.setDescription(repo.getDescription()); - repoConfig.setIndexDir(repo.getIndexDirectory()); + repoConfig.setUrl( getRepositoryCommonValidator( ).removeExpressions( repo.getUrl( ) ) ); + repoConfig.setRefreshCronExpression( repo.getCronExpression( ) ); + repoConfig.setCheckPath( repo.getCheckPath( ) ); + repoConfig.setExtraHeaders( repo.getExtraHeaders( ) ); + repoConfig.setExtraParameters( repo.getExtraParameters( ) ); + repoConfig.setUsername( repo.getUserName( ) ); + repoConfig.setPassword( repo.getPassword( ) ); + repoConfig.setTimeout( repo.getTimeout( ) ); + repoConfig.setRemoteIndexUrl( repo.getRemoteIndexUrl( ) ); + repoConfig.setDownloadRemoteIndex( repo.isDownloadRemoteIndex( ) ); + repoConfig.setRemoteDownloadNetworkProxyId( repo.getRemoteDownloadNetworkProxyId( ) ); + repoConfig.setDownloadRemoteIndexOnStartup( repo.isDownloadRemoteIndexOnStartup( ) ); + repoConfig.setRemoteDownloadTimeout( repo.getRemoteDownloadTimeout( ) ); + repoConfig.setDescription( repo.getDescription( ) ); + repoConfig.setIndexDir( repo.getIndexDirectory( ) ); return repoConfig; } @Override - public List getRemoteRepositories() + public List getRemoteRepositories( ) throws RepositoryAdminException { - return repositoryRegistry.getRemoteRepositories().stream().map( repo -> convertRepo( repo ) ).collect( Collectors.toList()); + return repositoryRegistry.getRemoteRepositories( ).stream( ).map( repo -> convertRepo( repo ) ).collect( Collectors.toList( ) ); } @Override public org.apache.archiva.admin.model.beans.RemoteRepository getRemoteRepository( String repositoryId ) throws RepositoryAdminException { - return convertRepo( repositoryRegistry.getRemoteRepository( repositoryId )); + return convertRepo( repositoryRegistry.getRemoteRepository( repositoryId ) ); } @Override public Boolean addRemoteRepository( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository, AuditInformation auditInformation ) throws RepositoryAdminException { - triggerAuditEvent( remoteRepository.getId(), null, AuditEvent.ADD_REMOTE_REPO, auditInformation ); - getRepositoryCommonValidator().basicValidation( remoteRepository, false ); + triggerAuditEvent( remoteRepository.getId( ), null, AuditEvent.ADD_REMOTE_REPO, auditInformation ); + getRepositoryCommonValidator( ).basicValidation( remoteRepository, false ); //TODO we can validate it's a good uri/url - if ( StringUtils.isEmpty( remoteRepository.getUrl() ) ) + if ( StringUtils.isEmpty( remoteRepository.getUrl( ) ) ) { throw new RepositoryAdminException( "url cannot be null" ); } //MRM-752 - url needs trimming //MRM-1940 - URL should not end with a slash - remoteRepository.setUrl( StringUtils.stripEnd(StringUtils.trim( remoteRepository.getUrl() ), "/")); - - if (StringUtils.isEmpty(remoteRepository.getCheckPath())) { - String checkUrl = remoteRepository.getUrl().toLowerCase(); - for (RepositoryCheckPath path : getArchivaConfiguration ().getConfiguration().getArchivaDefaultConfiguration().getDefaultCheckPaths()) { - log.debug("Checking path for urls: {} <-> {}", checkUrl, path.getUrl()); - if (checkUrl.startsWith(path.getUrl())) { - remoteRepository.setCheckPath(path.getPath()); + remoteRepository.setUrl( StringUtils.stripEnd( StringUtils.trim( remoteRepository.getUrl( ) ), "/" ) ); + + if ( StringUtils.isEmpty( remoteRepository.getCheckPath( ) ) ) + { + String checkUrl = remoteRepository.getUrl( ).toLowerCase( ); + for ( RepositoryCheckPath path : getArchivaConfiguration( ).getConfiguration( ).getArchivaDefaultConfiguration( ).getDefaultCheckPaths( ) ) + { + log.debug( "Checking path for urls: {} <-> {}", checkUrl, path.getUrl( ) ); + if ( checkUrl.startsWith( path.getUrl( ) ) ) + { + remoteRepository.setCheckPath( path.getPath( ) ); break; } } } - Configuration configuration = getArchivaConfiguration().getConfiguration(); RemoteRepositoryConfiguration remoteRepositoryConfiguration = getRepositoryConfiguration( remoteRepository ); - log.debug("Adding remote repo {}", remoteRepositoryConfiguration); + log.debug( "Adding remote repo {}", remoteRepositoryConfiguration ); try { - repositoryRegistry.putRepository( remoteRepositoryConfiguration, configuration ); + repositoryRegistry.putRepository( remoteRepositoryConfiguration ); } catch ( RepositoryException e ) { - log.error("Could not add remote repository {}: {}", remoteRepositoryConfiguration.getId(), e.getMessage(), e); - throw new RepositoryAdminException( "Adding of remote repository failed"+(e.getMessage()==null?"":": "+e.getMessage()) ); + log.error( "Could not add remote repository {}: {}", remoteRepositoryConfiguration.getId( ), e.getMessage( ), e ); + throw new RepositoryAdminException( "Adding of remote repository failed" + ( e.getMessage( ) == null ? "" : ": " + e.getMessage( ) ) ); } - saveConfiguration( configuration ); - return Boolean.TRUE; } @@ -198,24 +198,23 @@ public class DefaultRemoteRepositoryAdmin triggerAuditEvent( repositoryId, null, AuditEvent.DELETE_REMOTE_REPO, auditInformation ); - Configuration configuration = getArchivaConfiguration().getConfiguration(); + Configuration configuration = getArchivaConfiguration( ).getConfiguration( ); RemoteRepository repo = repositoryRegistry.getRemoteRepository( repositoryId ); - if (repo==null) { - throw new RepositoryAdminException( "Could not delete repository "+repositoryId+". The repository does not exist." ); + if ( repo == null ) + { + throw new RepositoryAdminException( "Could not delete repository " + repositoryId + ". The repository does not exist." ); } try { - repositoryRegistry.removeRepository( repo, configuration ); + repositoryRegistry.removeRepository( repo ); } catch ( RepositoryException e ) { - log.error("Deletion of remote repository failed {}: {}", repo.getId(), e.getMessage(), e); - throw new RepositoryAdminException( "Could not delete remote repository"+(e.getMessage()==null?"":": "+e.getMessage()) ); + log.error( "Deletion of remote repository failed {}: {}", repo.getId( ), e.getMessage( ), e ); + throw new RepositoryAdminException( "Could not delete remote repository" + ( e.getMessage( ) == null ? "" : ": " + e.getMessage( ) ) ); } - saveConfiguration( configuration ); - return Boolean.TRUE; } @@ -224,52 +223,38 @@ public class DefaultRemoteRepositoryAdmin throws RepositoryAdminException { - String repositoryId = remoteRepository.getId(); + String repositoryId = remoteRepository.getId( ); triggerAuditEvent( repositoryId, null, AuditEvent.MODIFY_REMOTE_REPO, auditInformation ); // update means : remove and add - Configuration configuration = getArchivaConfiguration().getConfiguration(); + Configuration configuration = getArchivaConfiguration( ).getConfiguration( ); RemoteRepositoryConfiguration remoteRepositoryConfiguration = getRepositoryConfiguration( remoteRepository ); try { - repositoryRegistry.putRepository( remoteRepositoryConfiguration, configuration ); + repositoryRegistry.putRepository( remoteRepositoryConfiguration ); } catch ( RepositoryException e ) { - log.error("Could not update remote repository {}: {}", remoteRepositoryConfiguration.getId(), e.getMessage(), e); - throw new RepositoryAdminException( "Update of remote repository failed"+(e.getMessage()==null?"":": "+e.getMessage()) ); + log.error( "Could not update remote repository {}: {}", remoteRepositoryConfiguration.getId( ), e.getMessage( ), e ); + throw new RepositoryAdminException( "Update of remote repository failed" + ( e.getMessage( ) == null ? "" : ": " + e.getMessage( ) ) ); } - saveConfiguration( configuration ); return Boolean.TRUE; } @Override - public Map getRemoteRepositoriesAsMap() + public Map getRemoteRepositoriesAsMap( ) throws RepositoryAdminException { - java.util.Map map = new HashMap<>(); - - for ( org.apache.archiva.admin.model.beans.RemoteRepository repo : getRemoteRepositories() ) - { - map.put( repo.getId(), repo ); - } - - return map; + return repositoryRegistry.getRemoteRepositories( ).stream( ) + .map( r -> convertRepo( r ) ) + .collect( Collectors.toMap( + r -> r.getId( ), + r -> r + ) ); } - @Override - public ArchivaIndexingContext createIndexContext( org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository ) - throws RepositoryAdminException - { - RemoteRepository repo = repositoryRegistry.getRemoteRepository(remoteRepository.getId()); - return repo.getIndexingContext(); - - } - - - } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java index 738ea3278..2d84e474f 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java @@ -32,8 +32,7 @@ import org.apache.archiva.redback.role.RoleManager; import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.memory.SimpleUser; import org.apache.archiva.repository.RepositoryRegistry; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.lang3.StringUtils; import org.junit.Before; @@ -91,12 +90,7 @@ public abstract class AbstractRepositoryAdminTest @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; - - @SuppressWarnings( "unused" ) - @Inject - RepositoryGroupHandler repositoryGroupHandler; - + RepositoryHandlerDependencies repositoryHandlerDependencies; @Before public void initialize() { diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java index 384d8a9e9..34a0a320d 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java @@ -25,9 +25,6 @@ import org.apache.archiva.admin.model.group.RepositoryGroupAdmin; import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest; import org.apache.archiva.metadata.model.facets.AuditEvent; import org.apache.archiva.repository.Repository; -import org.apache.archiva.repository.RepositoryRegistry; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; import org.junit.Test; import javax.inject.Inject; 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 2285c5557..ee7f1e4e1 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 @@ -42,6 +42,7 @@ import java.util.Map; *
  • Instance initialized:
  • * * + * The repository handler are not thread safe. Synchronization is done by registry if necessary. * * @author Martin Stockhammer */ @@ -259,7 +260,15 @@ public interface RepositoryHandler> repositoryValidatorList ); + /** + * Returns the repository variant, this handler manages. + * @return the concrete variant class + */ Class getVariant(); + /** + * Returns the repository configuration variant, this handler manages. + * @return the concrete configuration variant class + */ Class getConfigurationVariant(); } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java index bf02d2867..718045e29 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java @@ -237,19 +237,6 @@ public interface RepositoryRegistry extends EventSource, RepositoryHandlerManage */ RepositoryGroup putRepositoryGroup( RepositoryGroupConfiguration repositoryGroupConfiguration, Configuration configuration ) throws RepositoryException; - /** - * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated - * from the data of the given instance. Otherwise a new repository is created and updated by the data of the given instance. - * - * This method can be used, if the archiva configuration should not be saved. It will only update the given configuration object. - * - * @param remoteRepository the remote repository - * @param configuration the configuration that is updated - * @return the repository instance, that was created or updated - * @throws RepositoryException if an error occurred while creating or updating the instance - */ - RemoteRepository putRepository( RemoteRepository remoteRepository, Configuration configuration ) throws RepositoryException; - /** * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated * from the data of the given instance. Otherwise a new repository is created and updated by the data of the given instance. diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepositoryHandler.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepositoryHandler.java index 819905598..9e316a7fe 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepositoryHandler.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepositoryHandler.java @@ -185,7 +185,7 @@ public abstract class AbstractRepositoryHandler repositoryProviders; + @SuppressWarnings( "SpringJavaInjectionPointsAutowiringInspection" ) @Inject IndexManagerFactory indexManagerFactory; @@ -122,30 +111,24 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa @Inject List> repositoryValidatorList; - @Inject - @Named( "repositoryContentFactory#default" ) - RepositoryContentFactory repositoryContentFactory; - - private boolean ignoreIndexing = false; private final EventManager eventManager; - private Map remoteRepositories = new HashMap<>( ); - private Map uRemoteRepositories = Collections.unmodifiableMap( remoteRepositories ); - - private ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock( ); + private final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock( ); private RepositoryHandler groupHandler; private RepositoryHandler managedRepositoryHandler; + private RepositoryHandler remoteRepositoryHandler; + private final Set> validators; private final ConfigurationHandler configurationHandler; - private AtomicBoolean groups_initalized = new AtomicBoolean( false ); - private AtomicBoolean managed_initialized = new AtomicBoolean( false ); - private AtomicBoolean remote_initialized = new AtomicBoolean( false ); + private final AtomicBoolean groups_initalized = new AtomicBoolean( false ); + private final AtomicBoolean managed_initialized = new AtomicBoolean( false ); + private final AtomicBoolean remote_initialized = new AtomicBoolean( false ); public ArchivaRepositoryRegistry( ConfigurationHandler configurationHandler, List> validatorList ) @@ -181,10 +164,7 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa { log.debug( "Initializing repository registry" ); initializeManagedRepositories(); - updateRemoteRepositoriesFromConfig( ); - pushEvent( new RepositoryRegistryEvent( RepositoryRegistryEvent.REMOTE_REPOS_INITIALIZED, this ) ); - remote_initialized.set( true ); - + initializeRemoteRepositories(); initializeRepositoryGroups( ); for ( RepositoryProvider provider : repositoryProviders ) @@ -224,10 +204,19 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa } } + private void initializeRemoteRepositories() { + if (this.remoteRepositoryHandler != null ){ + this.remoteRepositoryHandler.initializeFromConfig( ); + this.remote_initialized.set( true ); + pushEvent( new RepositoryRegistryEvent( RepositoryRegistryEvent.REMOTE_REPOS_INITIALIZED, this ) ); + + } + } + public void registerGroupHandler( RepositoryHandler groupHandler ) { this.groupHandler = groupHandler; - registerRepositoryHandler( groupHandler ); + doRegister( groupHandler ); initializeRepositoryGroups( ); if ( managed_initialized.get( ) && remote_initialized.get( ) && groups_initalized.get( ) ) { @@ -238,7 +227,7 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa public void registerManagedRepositoryHandler( RepositoryHandler managedRepositoryHandler ) { this.managedRepositoryHandler = managedRepositoryHandler; - registerRepositoryHandler( managedRepositoryHandler ); + doRegister( managedRepositoryHandler ); initializeManagedRepositories(); if ( managed_initialized.get( ) && remote_initialized.get( ) && groups_initalized.get( ) ) { @@ -246,16 +235,22 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa } } + public void registerRemoteRepositoryHandler( RepositoryHandler remoteRepositoryHandler ) + { + this.remoteRepositoryHandler = remoteRepositoryHandler; + doRegister( remoteRepositoryHandler ); + initializeRemoteRepositories(); + if ( managed_initialized.get( ) && remote_initialized.get( ) && groups_initalized.get( ) ) + { + pushEvent( new RepositoryRegistryEvent( RepositoryRegistryEvent.INITIALIZED, this ) ); + } + } @PreDestroy public void destroy( ) { managedRepositoryHandler.close( ); - for ( RemoteRepository repo : remoteRepositories.values( ) ) - { - repo.close( ); - } - remoteRepositories.clear( ); + remoteRepositoryHandler.close(); groupHandler.close( ); pushEvent( new RepositoryRegistryEvent( RepositoryRegistryEvent.DESTROYED, this ) ); } @@ -282,20 +277,6 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa return repositoryProviders.stream( ).filter( repositoryProvider -> repositoryProvider.provides( ).contains( type ) ).findFirst( ).orElseThrow( ( ) -> new RepositoryException( "Repository type cannot be handled: " + type ) ); } - /* - * Updates the repositories - */ - private void updateManagedRepositoriesFromConfig( ) - { - managedRepositoryHandler.initializeFromConfig( ); - } - - - private String getStagingId( String repoId ) - { - return repoId + StagingRepositoryFeature.STAGING_REPO_POSTFIX; - } - @Override public ArchivaIndexManager getIndexManager( RepositoryType type ) @@ -316,80 +297,6 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa } } - private void createIndexingContext( EditableRepository editableRepo ) throws RepositoryException - { - if ( editableRepo.supportsFeature( IndexCreationFeature.class ) ) - { - ArchivaIndexManager idxManager = getIndexManager( editableRepo.getType( ) ); - try - { - editableRepo.setIndexingContext( idxManager.createContext( editableRepo ) ); - idxManager.updateLocalIndexPath( editableRepo ); - } - catch ( IndexCreationFailedException e ) - { - throw new RepositoryException( "Could not create index for repository " + editableRepo.getId( ) + ": " + e.getMessage( ), e ); - } - } - } - - - private void updateRemoteRepositoriesFromConfig( ) - { - try - { - List remoteRepoConfigs = - configurationHandler.getBaseConfiguration( ).getRemoteRepositories( ); - - if ( remoteRepoConfigs == null ) - { - return; - } - Set repoIds = new HashSet<>( ); - for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs ) - { - putRepository( repoConfig, null ); - repoIds.add( repoConfig.getId( ) ); - } - - List toRemove = remoteRepositories.keySet( ).stream( ).filter( id -> !repoIds.contains( id ) ).collect( Collectors.toList( ) ); - for ( String id : toRemove ) - { - RemoteRepository removed = remoteRepositories.remove( id ); - removed.close( ); - } - - } - catch ( Throwable e ) - { - log.error( "Could not initialize remote repositories from config: {}", e.getMessage( ), e ); - return; - } - } - - private RemoteRepository createNewRemoteRepository( RepositoryProvider provider, RemoteRepositoryConfiguration cfg ) throws RepositoryException - { - log.debug( "Creating remote repo {}", cfg.getId( ) ); - RemoteRepository repo = provider.createRemoteInstance( cfg ); - updateRepositoryReferences( provider, repo, cfg, null ); - return repo; - - } - - private void updateRepositoryReferences( RepositoryProvider provider, RemoteRepository repo, RemoteRepositoryConfiguration cfg, Configuration configuration ) throws RepositoryException - { - if ( repo instanceof EditableRemoteRepository && repo.getContent( ) == null ) - { - EditableRemoteRepository editableRepo = (EditableRemoteRepository) repo; - editableRepo.setContent( repositoryContentFactory.getRemoteRepositoryContent( repo ) ); - if ( repo.supportsFeature( IndexCreationFeature.class ) && repo.getIndexingContext( ) == null ) - { - createIndexingContext( editableRepo ); - } - } - repo.registerEventHandler( RepositoryEvent.ANY, this ); - } - /** * Returns all repositories that are registered. There is no defined order of the returned repositories. @@ -402,7 +309,7 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa rwLock.readLock( ).lock( ); try { - return Stream.concat( managedRepositoryHandler.getAll().stream( ), remoteRepositories.values( ).stream( ) ).collect( Collectors.toList( ) ); + return Stream.concat( managedRepositoryHandler.getAll().stream( ), remoteRepositoryHandler.getAll().stream( ) ).collect( Collectors.toList( ) ); } finally { @@ -440,7 +347,7 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa rwLock.readLock( ).lock( ); try { - return uRemoteRepositories.values( ); + return remote_initialized.get() ? remoteRepositoryHandler.getAll( ) : Collections.emptyList(); } finally { @@ -481,10 +388,10 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa log.debug( "Managed repo" ); return managedRepositoryHandler.get( repoId ); } - else if ( remoteRepositories.containsKey( repoId ) ) + else if ( remoteRepositoryHandler.hasRepository( repoId ) ) { log.debug( "Remote repo" ); - return remoteRepositories.get( repoId ); + return remoteRepositoryHandler.get( repoId ); } else if ( groupHandler.hasRepository( repoId ) ) { @@ -535,7 +442,7 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa rwLock.readLock( ).lock( ); try { - return remoteRepositories.get( repoId ); + return remote_initialized.get() ? remoteRepositoryHandler.get( repoId ) : null; } finally { @@ -561,20 +468,20 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa public boolean hasRepository( String repoId ) { return ( managedRepositoryHandler != null && managedRepositoryHandler.hasRepository( repoId ) ) - || ( this.remoteRepositories != null && this.remoteRepositories.containsKey( repoId ) ) + || ( remoteRepositoryHandler != null && remoteRepositoryHandler.hasRepository( repoId ) ) || ( this.groupHandler != null && groupHandler.hasRepository( repoId ) ); } @Override public boolean hasManagedRepository( String repoId ) { - return managedRepositoryHandler.hasRepository( repoId ); + return managedRepositoryHandler!=null && managedRepositoryHandler.hasRepository( repoId ); } @Override public boolean hasRemoteRepository( String repoId ) { - return this.remoteRepositories.containsKey( repoId ); + return remoteRepositoryHandler!=null && remoteRepositoryHandler.hasRepository( repoId ); } @Override @@ -744,87 +651,6 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa } } - private void replaceOrAddRepositoryConfig( RemoteRepositoryConfiguration remoteRepositoryConfiguration, Configuration configuration ) - { - if ( configuration != null ) - { - RemoteRepositoryConfiguration oldCfg = configuration.findRemoteRepositoryById( remoteRepositoryConfiguration.getId( ) ); - if ( oldCfg != null ) - { - configuration.removeRemoteRepository( oldCfg ); - } - configuration.addRemoteRepository( remoteRepositoryConfiguration ); - } - } - - @Override - public RemoteRepository putRepository( RemoteRepository remoteRepository, Configuration configuration ) throws RepositoryException - { - rwLock.writeLock( ).lock( ); - try - { - final String id = remoteRepository.getId( ); - if ( managedRepositoryHandler.hasRepository( id ) ) - { - throw new RepositoryException( "There exists a managed repository with id " + id + ". Could not update with remote repository." ); - } - RemoteRepository originRepo = remoteRepositories.put( id, remoteRepository ); - RemoteRepositoryConfiguration oldCfg = null; - RemoteRepositoryConfiguration newCfg; - try - { - if ( originRepo != null && originRepo != remoteRepository ) - { - originRepo.close( ); - } - final RepositoryProvider provider = getProvider( remoteRepository.getType( ) ); - newCfg = provider.getRemoteConfiguration( remoteRepository ); - updateRepositoryReferences( provider, remoteRepository, newCfg, configuration ); - oldCfg = configuration.findRemoteRepositoryById( id ); - if ( oldCfg != null ) - { - configuration.removeRemoteRepository( oldCfg ); - } - configuration.addRemoteRepository( newCfg ); - if ( remoteRepository != originRepo ) - { - pushEvent( new LifecycleEvent( LifecycleEvent.REGISTERED, this, remoteRepository ) ); - } - else - { - pushEvent( new LifecycleEvent( LifecycleEvent.UPDATED, this, remoteRepository ) ); - } - return remoteRepository; - } - catch ( Exception e ) - { - // Rollback - if ( originRepo != null ) - { - remoteRepositories.put( id, originRepo ); - } - else - { - remoteRepositories.remove( id ); - } - if ( oldCfg != null ) - { - RemoteRepositoryConfiguration cfg = configuration.findRemoteRepositoryById( id ); - if ( cfg != null ) - { - configuration.removeRemoteRepository( cfg ); - configuration.addRemoteRepository( oldCfg ); - } - } - log.error( "Error while adding remote repository {}", e.getMessage( ), e ); - throw new RepositoryException( "Could not save the configuration" + ( e.getMessage( ) == null ? "" : ": " + e.getMessage( ) ) ); - } - } - finally - { - rwLock.writeLock( ).unlock( ); - } - } /** * Adds a remote repository, or overwrites the repository definition with the same id, if it exists already. @@ -839,18 +665,7 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa rwLock.writeLock( ).lock( ); try { - Configuration configuration = configurationHandler.getBaseConfiguration( ); - try - { - RemoteRepository repo = putRepository( remoteRepository, configuration ); - saveConfiguration( configuration ); - return repo; - } - catch ( RegistryException | IndeterminateConfigurationException e ) - { - log.error( "Error while saving remote repository {}", e.getMessage( ), e ); - throw new RepositoryException( "Could not save the configuration" + ( e.getMessage( ) == null ? "" : ": " + e.getMessage( ) ) ); - } + return remoteRepositoryHandler.put( remoteRepository ); } finally { @@ -872,32 +687,12 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa rwLock.writeLock( ).lock( ); try { - final String id = remoteRepositoryConfiguration.getId( ); - final RepositoryType repositoryType = RepositoryType.valueOf( remoteRepositoryConfiguration.getType( ) ); - Configuration configuration = configurationHandler.getBaseConfiguration( ); - RemoteRepository repo = remoteRepositories.get( id ); - RemoteRepositoryConfiguration oldCfg = repo != null ? getProvider( repositoryType ).getRemoteConfiguration( repo ) : null; - repo = putRepository( remoteRepositoryConfiguration, configuration ); - try - { - saveConfiguration( configuration ); - } - catch ( IndeterminateConfigurationException | RegistryException e ) - { - if ( oldCfg != null ) - { - getProvider( repositoryType ).updateRemoteInstance( (EditableRemoteRepository) repo, oldCfg ); - } - log.error( "Could not save the configuration for repository {}: {}", id, e.getMessage( ), e ); - throw new RepositoryException( "Could not save the configuration for repository " + id + ": " + e.getMessage( ) ); - } - return repo; + return remoteRepositoryHandler.put( remoteRepositoryConfiguration ); } finally { rwLock.writeLock( ).unlock( ); } - } /** @@ -910,52 +705,17 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa * @throws RepositoryException if the configuration cannot be saved or updated */ @Override - @SuppressWarnings( "unchecked" ) public RemoteRepository putRepository( RemoteRepositoryConfiguration remoteRepositoryConfiguration, Configuration configuration ) throws RepositoryException { rwLock.writeLock( ).lock( ); try { - final String id = remoteRepositoryConfiguration.getId( ); - final RepositoryType repoType = RepositoryType.valueOf( remoteRepositoryConfiguration.getType( ) ); - RemoteRepository repo; - boolean registeredNew = false; - repo = remoteRepositories.get( id ); - if ( repo != null && repo.isOpen( ) ) - { - if ( repo instanceof EditableRemoteRepository ) - { - getProvider( repoType ).updateRemoteInstance( (EditableRemoteRepository) repo, remoteRepositoryConfiguration ); - } - else - { - throw new RepositoryException( "The repository is not editable " + id ); - } - } - else - { - repo = getProvider( repoType ).createRemoteInstance( remoteRepositoryConfiguration ); - remoteRepositories.put( id, repo ); - registeredNew = true; - } - updateRepositoryReferences( getProvider( repoType ), repo, remoteRepositoryConfiguration, configuration ); - replaceOrAddRepositoryConfig( remoteRepositoryConfiguration, configuration ); - if ( registeredNew ) - { - pushEvent( new LifecycleEvent( LifecycleEvent.REGISTERED, this, repo ) ); - } - else - { - pushEvent( new LifecycleEvent( LifecycleEvent.UPDATED, this, repo ) ); - } - return repo; + return remoteRepositoryHandler.put( remoteRepositoryConfiguration, configuration ); } finally { rwLock.writeLock( ).unlock( ); } - - } @Override @@ -1091,24 +851,6 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa } } - private void doRemoveRepo( RemoteRepository repo, Configuration configuration ) - { - repo.close( ); - RemoteRepositoryConfiguration cfg = configuration.findRemoteRepositoryById( repo.getId( ) ); - if ( cfg != null ) - { - configuration.removeRemoteRepository( cfg ); - } - List proxyConnectors = new ArrayList<>( configuration.getProxyConnectors( ) ); - for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors ) - { - if ( StringUtils.equals( proxyConnector.getTargetRepoId( ), repo.getId( ) ) ) - { - configuration.removeProxyConnector( proxyConnector ); - } - } - } - /** * Removes the remote repository from the registry and configuration. * The change is saved to the configuration immediately. @@ -1124,27 +866,12 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa return; } final String id = remoteRepository.getId( ); - RemoteRepository repo = getRemoteRepository( id ); - if ( repo != null ) + if ( remoteRepositoryHandler.hasRepository( id ) ) { rwLock.writeLock( ).lock( ); try { - repo = remoteRepositories.remove( id ); - if ( repo != null ) - { - Configuration configuration = configurationHandler.getBaseConfiguration( ); - doRemoveRepo( repo, configuration ); - saveConfiguration( configuration ); - } - pushEvent( new LifecycleEvent( LifecycleEvent.UNREGISTERED, this, repo ) ); - } - catch ( RegistryException | IndeterminateConfigurationException e ) - { - // Rollback - log.error( "Could not save config after repository removal: {}", e.getMessage( ), e ); - remoteRepositories.put( repo.getId( ), repo ); - throw new RepositoryException( "Could not save configuration after repository removal: " + e.getMessage( ) ); + remoteRepositoryHandler.remove( id ); } finally { @@ -1161,25 +888,18 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa return; } final String id = remoteRepository.getId( ); - RemoteRepository repo = getRemoteRepository( id ); - if ( repo != null ) + if ( remoteRepositoryHandler.hasRepository( id ) ) { rwLock.writeLock( ).lock( ); try { - repo = remoteRepositories.remove( id ); - if ( repo != null ) - { - doRemoveRepo( repo, configuration ); - } - pushEvent( new LifecycleEvent( LifecycleEvent.UNREGISTERED, this, repo ) ); + remoteRepositoryHandler.remove( id, configuration ); } finally { rwLock.writeLock( ).unlock( ); } } - } /** @@ -1221,20 +941,41 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa if (isRegisteredId( newId )) { throw new RepositoryException( "The new id exists already: " + newId ); } - EditableManagedRepository newRepo = (EditableManagedRepository) managedRepositoryHandler.clone( repo, newId ); - return newRepo; + return managedRepositoryHandler.clone( repo, newId ); + } + + /** + * Creates a new repository instance with the same settings as this one. The cloned repository is not + * registered or saved to the configuration. + * + * @param repo The origin repository + * @return The cloned repository. + */ + public RemoteRepository clone( RemoteRepository repo, String newId ) throws RepositoryException + { + if (isRegisteredId( newId )) { + throw new RepositoryException( "The new id exists already: " + newId ); + } + return remoteRepositoryHandler.clone( repo, newId ); } + @SuppressWarnings( "unchecked" ) @Override public T clone( T repo, String newId ) throws RepositoryException { + if (isRegisteredId( newId )) { + throw new RepositoryException( "The new id exists already: " + newId ); + } if ( repo instanceof RemoteRepository ) { - return (T) this.clone( (RemoteRepository) repo, newId ); + return (T) remoteRepositoryHandler.clone( (RemoteRepository) repo, newId ); } else if ( repo instanceof ManagedRepository ) { - return (T) this.clone( (ManagedRepository) repo, newId ); + return (T) managedRepositoryHandler.clone( (ManagedRepository) repo, newId ); + } + else if (repo instanceof RepositoryGroup) { + return (T) groupHandler.clone( (RepositoryGroup) repo, newId ); } else { @@ -1242,26 +983,6 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa } } - /** - * Creates a new repository instance with the same settings as this one. The cloned repository is not - * registered or saved to the configuration. - * - * @param repo The origin repository - * @return The cloned repository. - */ - public RemoteRepository clone( RemoteRepository repo, String newId ) throws RepositoryException - { - if ( isRegisteredId( newId ) ) - { - throw new RepositoryException( "The given id exists already " + newId ); - } - RepositoryProvider provider = getProvider( repo.getType( ) ); - RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration( repo ); - cfg.setId( newId ); - RemoteRepository cloned = provider.createRemoteInstance( cfg ); - cloned.registerEventHandler( RepositoryEvent.ANY, this ); - return cloned; - } @Override public Repository getRepositoryOfAsset( StorageAsset asset ) @@ -1280,31 +1001,31 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa @Override public ValidationResponse validateRepository( R repository ) { - Map> errorMap = this.validators.stream( ) + @SuppressWarnings( "unchecked" ) Map> errorMap = this.validators.stream( ) .filter( ( validator ) -> validator.getType( ).equals( RepositoryType.ALL ) || repository.getType( ).equals( validator.getType( ) ) ) .filter( val -> val.isFlavour( repository.getClass( ) ) ) .flatMap( validator -> ( (RepositoryValidator) validator ).apply( repository ).getResult( ).entrySet( ).stream( ) ) .collect( Collectors.toMap( - entry -> entry.getKey( ), - entry -> entry.getValue( ), - ( list1, list2 ) -> ListUtils.union( list1, list2 ) + Map.Entry::getKey, + Map.Entry::getValue, + ListUtils::union ) ); - return new ValidationResponse( repository, errorMap ); + return new ValidationResponse<>( repository, errorMap ); } @Override public ValidationResponse validateRepositoryForUpdate( R repository ) { - Map> errorMap = this.validators.stream( ) + @SuppressWarnings( "unchecked" ) Map> errorMap = this.validators.stream( ) .filter( ( validator ) -> validator.getType( ).equals( RepositoryType.ALL ) || repository.getType( ).equals( validator.getType( ) ) ) .filter( val -> val.isFlavour( repository.getClass( ) ) ) .flatMap( validator -> ( (RepositoryValidator) validator ).applyForUpdate( repository ).getResult( ).entrySet( ).stream( ) ) .collect( Collectors.toMap( - entry -> entry.getKey( ), - entry -> entry.getValue( ), - ( list1, list2 ) -> ListUtils.union( list1, list2 ) + Map.Entry::getKey, + Map.Entry::getValue, + ListUtils::union ) ); - return new ValidationResponse( repository, errorMap ); + return new ValidationResponse<>( repository, errorMap ); } @Override @@ -1352,8 +1073,7 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa { if (!ignoreIndexing && !( event.getRepository() instanceof ManagedRepository )) { - RepositoryIndexEvent idxEvent = event; - EditableRepository repo = (EditableRepository) idxEvent.getRepository( ); + EditableRepository repo = (EditableRepository) event.getRepository( ); if ( repo != null ) { ArchivaIndexManager idxmgr = getIndexManager( repo.getType( ) ); @@ -1409,12 +1129,13 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa eventManager.fireEvent( event ); } - private void registerRepositoryHandler( RepositoryHandler repositoryHandler ) + private void doRegister( RepositoryHandler repositoryHandler ) { repositoryHandler.setRepositoryProviders( this.repositoryProviders ); repositoryHandler.setRepositoryValidator( this.repositoryValidatorList ); } + @SuppressWarnings( "unchecked" ) @Override public void registerHandler( RepositoryHandler handler ) { @@ -1426,6 +1147,9 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa { registerManagedRepositoryHandler( (RepositoryHandler) handler ); } + else if ( handler.getVariant().isAssignableFrom( RemoteRepository.class )) { + registerRemoteRepositoryHandler( (RepositoryHandler) handler ); + } } @Override @@ -1434,6 +1158,7 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa return hasRepository( id ); } + @SuppressWarnings( "unchecked" ) @Override public RepositoryHandler getHandler( Class repositoryClazz, Class configurationClazz ) { @@ -1445,6 +1170,9 @@ public class ArchivaRepositoryRegistry implements ConfigurationListener, EventHa { return (RepositoryHandler) this.managedRepositoryHandler; } + else if ( repositoryClazz.isAssignableFrom( RemoteRepository.class )) { + return (RepositoryHandler) this.remoteRepositoryHandler; + } else { return null; diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryHandlerDependencies.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryHandlerDependencies.java new file mode 100644 index 000000000..6aba0e359 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryHandlerDependencies.java @@ -0,0 +1,43 @@ +package org.apache.archiva.repository.base; +/* + * 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.archiva.repository.base.group.RepositoryGroupHandler; +import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.remote.RemoteRepositoryHandler; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; + +/** + * This is just a class that pulls the handler dependencies. It is used by test classes. + * + * @author Martin Stockhammer + */ +@Service() +public class RepositoryHandlerDependencies +{ + @Inject + ManagedRepositoryHandler managedRepositoryHandler; + + @Inject + RemoteRepositoryHandler remoteRepositoryHandler; + + @Inject + RepositoryGroupHandler repositoryGroupHandler; +} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/managed/ManagedRepositoryHandler.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/managed/ManagedRepositoryHandler.java index 1ce5da635..0ed99ecc7 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/managed/ManagedRepositoryHandler.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/managed/ManagedRepositoryHandler.java @@ -32,7 +32,6 @@ import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryHandler; import org.apache.archiva.repository.RepositoryHandlerManager; import org.apache.archiva.repository.RepositoryProvider; -import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.RepositoryState; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.base.AbstractRepositoryHandler; @@ -66,21 +65,21 @@ public class ManagedRepositoryHandler implements RepositoryHandler { private static final Logger log = LoggerFactory.getLogger( ManagedRepositoryHandler.class ); - private final RepositoryHandlerManager repositoryRegistry; + private final RepositoryHandlerManager repositoryHandlerManager; private final RepositoryContentFactory repositoryContentFactory; IndexManagerFactory indexManagerFactory; - public ManagedRepositoryHandler( RepositoryHandlerManager repositoryRegistry, + public ManagedRepositoryHandler( RepositoryHandlerManager repositoryHandlerManager, ConfigurationHandler configurationHandler, IndexManagerFactory indexManagerFactory, @Named( "repositoryContentFactory#default" ) RepositoryContentFactory repositoryContentFactory ) { super( ManagedRepository.class, ManagedRepositoryConfiguration.class, configurationHandler ); - this.repositoryRegistry = repositoryRegistry; + this.repositoryHandlerManager = repositoryHandlerManager; this.indexManagerFactory = indexManagerFactory; this.repositoryContentFactory = repositoryContentFactory; } @@ -89,10 +88,10 @@ public class ManagedRepositoryHandler @PostConstruct public void init( ) { - log.debug( "Initializing managed repository handler " + repositoryRegistry.toString( ) ); + log.debug( "Initializing repository handler " + ManagedRepositoryHandler.class ); initializeStorage( ); // We are registering this class on the registry. This is necessary to avoid circular dependencies via injection. - this.repositoryRegistry.registerHandler( this ); + this.repositoryHandlerManager.registerHandler( this ); } private void initializeStorage( ) @@ -174,6 +173,10 @@ public class ManagedRepositoryHandler for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs ) { String id = repoConfig.getId( ); + if (result.containsKey( id )) { + log.error( "There are repositories with the same id in the configuration: {}", id ); + continue; + } ManagedRepository repo; if ( currentInstances.containsKey( id ) ) { @@ -246,7 +249,7 @@ public class ManagedRepositoryHandler { throw new RepositoryException( "Could not create repository '" + id + "': " + e.getMessage( ) ); } - repo.registerEventHandler( RepositoryEvent.ANY, repositoryRegistry ); + repo.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager ); updateReferences( repo, null ); repo.setLastState( RepositoryState.REFERENCES_SET ); return repo; @@ -309,7 +312,7 @@ public class ManagedRepositoryHandler throw new RepositoryException( "Provider not found for repository type: " + repositoryConfiguration.getType( ) ); } final ManagedRepository repo = provider.createManagedInstance( repositoryConfiguration ); - repo.registerEventHandler( RepositoryEvent.ANY, repositoryRegistry ); + repo.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager ); updateReferences( repo, null ); if ( repo instanceof EditableRepository ) { @@ -337,28 +340,28 @@ public class ManagedRepositoryHandler } @Override - public ManagedRepository put( ManagedRepository managedRepository ) throws RepositoryException + public ManagedRepository put( ManagedRepository repository ) throws RepositoryException { - final String id = managedRepository.getId( ); + final String id = repository.getId( ); ManagedRepository originRepo = getRepositories( ).remove( id ); - if ( originRepo == null && repositoryRegistry.isRegisteredId( id ) ) + if ( originRepo == null && repositoryHandlerManager.isRegisteredId( id ) ) { throw new RepositoryException( "There exists a repository with id " + id + ". Could not update with managed repository." ); } try { - if ( originRepo != null && managedRepository != originRepo ) + if ( originRepo != null && repository != originRepo ) { deactivateRepository( originRepo ); pushEvent( LifecycleEvent.UNREGISTERED, originRepo ); } - RepositoryProvider provider = getProvider( managedRepository.getType( ) ); - ManagedRepositoryConfiguration newCfg = provider.getManagedConfiguration( managedRepository ); + RepositoryProvider provider = getProvider( repository.getType( ) ); + ManagedRepositoryConfiguration newCfg = provider.getManagedConfiguration( repository ); getConfigurationHandler( ).getLock( ).writeLock( ).lock( ); try { Configuration configuration = getConfigurationHandler( ).getBaseConfiguration( ); - updateReferences( managedRepository, newCfg ); + updateReferences( repository, newCfg ); ManagedRepositoryConfiguration oldCfg = configuration.findManagedRepositoryById( id ); if ( oldCfg != null ) { @@ -366,16 +369,16 @@ public class ManagedRepositoryHandler } configuration.addManagedRepository( newCfg ); getConfigurationHandler( ).save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG ); - setLastState( managedRepository, RepositoryState.SAVED ); - activateRepository( managedRepository ); + setLastState( repository, RepositoryState.SAVED ); + activateRepository( repository ); } finally { getConfigurationHandler( ).getLock( ).writeLock( ).unlock( ); } - getRepositories( ).put( id, managedRepository ); - setLastState( managedRepository, RepositoryState.REGISTERED ); - return managedRepository; + getRepositories( ).put( id, repository ); + setLastState( repository, RepositoryState.REGISTERED ); + return repository; } catch ( Exception e ) { @@ -395,10 +398,10 @@ public class ManagedRepositoryHandler @Override - public ManagedRepository put( ManagedRepositoryConfiguration managedRepositoryConfiguration ) throws RepositoryException + public ManagedRepository put( ManagedRepositoryConfiguration repositoryConfiguration ) throws RepositoryException { - final String id = managedRepositoryConfiguration.getId( ); - final RepositoryType repositoryType = RepositoryType.valueOf( managedRepositoryConfiguration.getType( ) ); + final String id = repositoryConfiguration.getId( ); + final RepositoryType repositoryType = RepositoryType.valueOf( repositoryConfiguration.getType( ) ); final RepositoryProvider provider = getProvider( repositoryType ); ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler( ).getLock( ).writeLock( ); configLock.lock( ); @@ -413,16 +416,16 @@ public class ManagedRepositoryHandler oldRepository = repo == null ? null : clone( repo, id ); if ( repo == null ) { - repo = put( managedRepositoryConfiguration, configuration ); + repo = put( repositoryConfiguration, configuration ); } else { - setManagedRepositoryDefaults( managedRepositoryConfiguration ); - provider.updateManagedInstance( (EditableManagedRepository) repo, managedRepositoryConfiguration ); + setRepositoryDefaults( repositoryConfiguration ); + provider.updateManagedInstance( (EditableManagedRepository) repo, repositoryConfiguration ); updated = true; pushEvent( LifecycleEvent.UPDATED, repo ); } - registerNewRepository( managedRepositoryConfiguration, repo, configuration, updated ); + registerNewRepository( repositoryConfiguration, repo, configuration, updated ); } catch ( IndeterminateConfigurationException | RegistryException e ) { @@ -452,7 +455,7 @@ public class ManagedRepositoryHandler final String id = repositoryConfiguration.getId( ); final RepositoryType repoType = RepositoryType.valueOf( repositoryConfiguration.getType( ) ); ManagedRepository repo; - setManagedRepositoryDefaults( repositoryConfiguration ); + setRepositoryDefaults( repositoryConfiguration ); if ( getRepositories( ).containsKey( id ) ) { repo = clone( getRepositories( ).get( id ), id ); @@ -480,7 +483,7 @@ public class ManagedRepositoryHandler } @SuppressWarnings( "unused" ) - private void setManagedRepositoryDefaults( ManagedRepositoryConfiguration repositoryConfiguration ) + private void setRepositoryDefaults( ManagedRepositoryConfiguration repositoryConfiguration ) { // We do nothing here } @@ -492,7 +495,7 @@ public class ManagedRepositoryHandler ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration( repo ); cfg.setId( id ); ManagedRepository cloned = provider.createManagedInstance( cfg ); - cloned.registerEventHandler( RepositoryEvent.ANY, repositoryRegistry ); + cloned.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager ); setLastState( cloned, RepositoryState.CREATED ); return cloned; } @@ -538,20 +541,7 @@ public class ManagedRepositoryHandler createIndexingContext( editableRepo ); } } - repo.registerEventHandler( RepositoryEvent.ANY, repositoryRegistry ); + repo.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager ); } - @Override - public void close( ) - { - getRepositories( ).values( ).stream( ).forEach( - r -> deactivateRepository( r ) - ); - } - - @Override - public void deactivateRepository( ManagedRepository repository ) - { - repository.close( ); - } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/remote/BasicRemoteRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/remote/BasicRemoteRepository.java index 5f9da87ea..c98512502 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/remote/BasicRemoteRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/remote/BasicRemoteRepository.java @@ -20,15 +20,16 @@ package org.apache.archiva.repository.base.remote; import org.apache.archiva.common.filelock.DefaultFileLockManager; import org.apache.archiva.common.filelock.FileLockManager; +import org.apache.archiva.repository.EditableRemoteRepository; import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryCapabilities; import org.apache.archiva.repository.RepositoryState; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.StandardCapabilities; -import org.apache.archiva.repository.storage.fs.FilesystemStorage; -import org.apache.archiva.repository.storage.RepositoryStorage; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RemoteIndexFeature; +import org.apache.archiva.repository.storage.RepositoryStorage; +import org.apache.archiva.repository.storage.fs.FilesystemStorage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +43,7 @@ import java.util.Locale; * * */ -public class BasicRemoteRepository extends AbstractRemoteRepository +public class BasicRemoteRepository extends AbstractRemoteRepository implements EditableRemoteRepository { Logger log = LoggerFactory.getLogger(BasicRemoteRepository.class); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/remote/BasicRemoteRepositoryValidator.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/remote/BasicRemoteRepositoryValidator.java new file mode 100644 index 000000000..9b020403e --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/remote/BasicRemoteRepositoryValidator.java @@ -0,0 +1,147 @@ +package org.apache.archiva.repository.base.remote; +/* + * 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.archiva.components.registry.Registry; +import org.apache.archiva.components.scheduler.CronExpressionValidator; +import org.apache.archiva.repository.RemoteRepository; +import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.base.ConfigurationHandler; +import org.apache.archiva.repository.validation.AbstractRepositoryValidator; +import org.apache.archiva.repository.validation.RepositoryValidator; +import org.apache.archiva.repository.validation.ValidationError; +import org.apache.archiva.repository.validation.ValidationResponse; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + +import static org.apache.archiva.repository.validation.ErrorKeys.*; + +/** + * Validator for remote repository data. + * + * @author Martin Stockhammer + */ +@Service( "repositoryValidator#common#remote" ) +public class BasicRemoteRepositoryValidator extends AbstractRepositoryValidator implements RepositoryValidator +{ + RepositoryRegistry repositoryRegistry; + private static final String CATEGORY = "remote_repository"; + private static final Pattern REPOSITORY_ID_VALID_EXPRESSION_PATTERN = Pattern.compile( REPOSITORY_ID_VALID_EXPRESSION ); + private static final Pattern REPOSITORY_NAME_VALID_EXPRESSION_PATTERN = Pattern.compile( REPOSITORY_NAME_VALID_EXPRESSION ); + private static final Pattern REPOSITORY_LOCATION_VALID_EXPRESSION_PATTERN = Pattern.compile( REPOSITORY_LOCATION_VALID_EXPRESSION ); + + private final ConfigurationHandler configurationHandler; + + + public BasicRemoteRepositoryValidator( ConfigurationHandler configurationHandler) + { + super( CATEGORY ); + this.configurationHandler = configurationHandler; + } + + @Override + public ValidationResponse apply( RemoteRepository repository, boolean update ) + { + Map> errors = null; + if (repository==null) { + errors = appendError( errors, "object", ISNULL ); + return new ValidationResponse<>( repository, errors ); + } + final String repoId = repository.getId( ); + if ( StringUtils.isBlank( repoId ) ) { + errors = appendError( errors, "id", ISEMPTY ); + } + + if (!update) + { + if ( repositoryRegistry.hasManagedRepository( repository.getId( ) ) ) + { + errors = appendError( errors, "id", MANAGED_REPOSITORY_EXISTS, repoId ); + } + else if ( repositoryRegistry.hasRemoteRepository( repoId ) ) + { + errors = appendError( errors, "id", REMOTE_REPOSITORY_EXISTS, repoId ); + } + else if ( repositoryRegistry.hasRepositoryGroup( repoId ) ) + { + errors = appendError( errors, "id", REPOSITORY_GROUP_EXISTS, repoId ); + } + } + + if ( !REPOSITORY_ID_VALID_EXPRESSION_PATTERN.matcher( repoId ).matches( ) ) + { + errors = appendError( errors, "id", INVALID_CHARS, repoId, REPOSITORY_ID_ALLOWED ); + } + if ( StringUtils.isBlank( repository.getName() ) ) + { + errors = appendError( errors, "name", ISEMPTY ); + } else if ( !REPOSITORY_NAME_VALID_EXPRESSION_PATTERN.matcher( repository.getName( ) ).matches( ) ) + { + errors = appendError( errors, "name", INVALID_CHARS, repository.getName( ), REPOSITORY_NAME_ALLOWED ); + } + + String cronExpression = repository.getSchedulingDefinition( ); + if ( StringUtils.isNotBlank( cronExpression ) ) + { + CronExpressionValidator validator = new CronExpressionValidator( ); + + if ( !validator.validate( cronExpression ) ) + { + errors = appendError( errors, "scheduling_definition", INVALID_SCHEDULING_EXPRESSION, cronExpression ); + } + } + // Cron expression may be empty + + String repoLocation = interpolateVars( repository.getLocation( ).toString() ); + + if ( !REPOSITORY_LOCATION_VALID_EXPRESSION_PATTERN.matcher( repoLocation ).matches() ) + { + errors = appendError( errors, "location", INVALID_LOCATION, repoLocation, new String[]{"alphanumeric", "=", "?", "!", "&", "/", "\\", "_", ".", ":", "~", "-"} ); + } + + return new ValidationResponse<>( repository, errors ); + } + + public String interpolateVars( String directory ) + { + Registry registry = configurationHandler.getArchivaConfiguration( ).getRegistry( ); + String value = StringUtils.replace( directory, "${appserver.base}", + registry.getString( "appserver.base", "${appserver.base}" ) ); + value = StringUtils.replace( value, "${appserver.home}", + registry.getString( "appserver.home", "${appserver.home}" ) ); + return value; + } + + + @Override + public void setRepositoryRegistry( RepositoryRegistry repositoryRegistry ) + { + this.repositoryRegistry = repositoryRegistry; + } + + @Override + public Class getFlavour( ) + { + return RemoteRepository.class; + } + +} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/remote/RemoteRepositoryHandler.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/remote/RemoteRepositoryHandler.java new file mode 100644 index 000000000..ea1f19c91 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/remote/RemoteRepositoryHandler.java @@ -0,0 +1,452 @@ +package org.apache.archiva.repository.base.remote; +/* + * 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.archiva.components.registry.RegistryException; +import org.apache.archiva.configuration.Configuration; +import org.apache.archiva.configuration.IndeterminateConfigurationException; +import org.apache.archiva.configuration.ProxyConnectorConfiguration; +import org.apache.archiva.configuration.RemoteRepositoryConfiguration; +import org.apache.archiva.indexer.ArchivaIndexManager; +import org.apache.archiva.indexer.IndexCreationFailedException; +import org.apache.archiva.indexer.IndexManagerFactory; +import org.apache.archiva.repository.EditableRemoteRepository; +import org.apache.archiva.repository.EditableRepository; +import org.apache.archiva.repository.RemoteRepository; +import org.apache.archiva.repository.RepositoryContentFactory; +import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.RepositoryHandler; +import org.apache.archiva.repository.RepositoryHandlerManager; +import org.apache.archiva.repository.RepositoryProvider; +import org.apache.archiva.repository.RepositoryState; +import org.apache.archiva.repository.RepositoryType; +import org.apache.archiva.repository.base.AbstractRepositoryHandler; +import org.apache.archiva.repository.base.ConfigurationHandler; +import org.apache.archiva.repository.event.LifecycleEvent; +import org.apache.archiva.repository.event.RepositoryEvent; +import org.apache.archiva.repository.features.IndexCreationFeature; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.inject.Named; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +/** + * @author Martin Stockhammer + */ +@Service( "remoteRepositoryHandler#default" ) +public class RemoteRepositoryHandler extends AbstractRepositoryHandler implements RepositoryHandler +{ + private static final Logger log = LoggerFactory.getLogger( RemoteRepositoryHandler.class ); + private final RepositoryHandlerManager repositoryHandlerManager; + private final RepositoryContentFactory repositoryContentFactory; + private final IndexManagerFactory indexManagerFactory; + + + public RemoteRepositoryHandler( RepositoryHandlerManager repositoryHandlerManager, ConfigurationHandler configurationHandler, + IndexManagerFactory indexManagerFactory, + @Named( "repositoryContentFactory#default" ) RepositoryContentFactory repositoryContentFactory ) + { + super( RemoteRepository.class, RemoteRepositoryConfiguration.class, configurationHandler ); + this.repositoryHandlerManager = repositoryHandlerManager; + this.repositoryContentFactory = repositoryContentFactory; + this.indexManagerFactory = indexManagerFactory; + } + + @Override + @PostConstruct + public void init( ) + { + log.debug( "Initializing repository handler " + RemoteRepositoryHandler.class ); + initializeStorage( ); + // We are registering this class on the registry. This is necessary to avoid circular dependencies via injection. + this.repositoryHandlerManager.registerHandler( this ); + } + + private void initializeStorage( ) + { + + } + + @Override + public void initializeFromConfig( ) + { + Map currentInstances = new HashMap<>( getRepositories( ) ); + getRepositories().clear(); + Map newAndUpdated = newOrUpdateInstancesFromConfig( currentInstances ); + getRepositories( ).putAll( newAndUpdated ); + currentInstances.entrySet( ).stream( ).filter( entry -> !newAndUpdated.containsKey( entry.getKey( ) ) ).forEach( + r -> + deactivateRepository( r.getValue() ) + ); + for ( RemoteRepository remoteRepository : getRepositories( ).values( ) ) + { + activateRepository( remoteRepository ); + } + + + } + + public Map newOrUpdateInstancesFromConfig( Map currentInstances) + { + try + { + List remoteRepoConfigs = + new ArrayList<>( + getConfigurationHandler( ).getBaseConfiguration( ).getRemoteRepositories( ) ); + + if ( remoteRepoConfigs == null ) + { + return Collections.emptyMap( ); + } + + Map result = new HashMap<>( ); + for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs ) + { + String id = repoConfig.getId( ); + if (result.containsKey( id )) { + log.error( "There are repositories with the same id in the configuration: {}", id ); + continue; + } + RemoteRepository repo; + if ( currentInstances.containsKey( id ) ) + { + repo = currentInstances.remove( id ); + getProvider( repo.getType( ) ).updateRemoteInstance( (EditableRemoteRepository) repo, repoConfig ); + updateReferences( repo, repoConfig ); + } + else + { + repo = newInstance( repoConfig ); + } + result.put( id, repo ); + } + return result; + } + catch ( Throwable e ) + { + log.error( "Could not initialize repositories from config: {}", e.getMessage( ), e ); + return new HashMap<>( ); + } + } + + + @Override + public Map newInstancesFromConfig( ) + { + try + { + List remoteRepoConfigs = + new ArrayList<>( + getConfigurationHandler( ).getBaseConfiguration( ).getRemoteRepositories( ) ); + + if ( remoteRepoConfigs == null ) + { + return Collections.emptyMap( ); + } + + Map result = new HashMap<>( ); + for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs ) + { + RemoteRepository repo = newInstance( repoConfig ); + result.put( repo.getId( ), repo ); + } + return result; + } + catch ( Throwable e ) + { + log.error( "Could not initialize repositories from config: {}", e.getMessage( ), e ); + return new HashMap<>( ); + } + } + + @Override + public RemoteRepository newInstance( RepositoryType type, String id ) throws RepositoryException + { + log.debug( "Creating repo {}", id ); + RepositoryProvider provider = getProvider( type ); + EditableRemoteRepository repo; + repo = provider.createRemoteInstance( id, id ); + repo.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager ); + updateReferences( repo, null ); + repo.setLastState( RepositoryState.REFERENCES_SET ); + return repo; + + } + + + @Override + public RemoteRepository newInstance( RemoteRepositoryConfiguration repositoryConfiguration ) throws RepositoryException + { + RepositoryType type = RepositoryType.valueOf( repositoryConfiguration.getType( ) ); + RepositoryProvider provider = getProvider( type ); + if ( provider == null ) + { + throw new RepositoryException( "Provider not found for repository type: " + repositoryConfiguration.getType( ) ); + } + final RemoteRepository repo = provider.createRemoteInstance( repositoryConfiguration ); + repo.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager ); + updateReferences( repo, null ); + if ( repo instanceof EditableRepository ) + { + ( (EditableRepository) repo ).setLastState( RepositoryState.REFERENCES_SET ); + } + return repo; + } + + @Override + protected RemoteRepositoryConfiguration findRepositoryConfiguration( Configuration configuration, String id ) + { + return configuration.findRemoteRepositoryById( id ); + } + + @Override + protected void removeRepositoryConfiguration( Configuration configuration, RemoteRepositoryConfiguration repoConfiguration ) + { + configuration.removeRemoteRepository( repoConfiguration ); + List proxyConnectors = new ArrayList<>( configuration.getProxyConnectors( ) ); + for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors ) + { + if ( StringUtils.equals( proxyConnector.getTargetRepoId( ), repoConfiguration.getId( ) ) ) + { + configuration.removeProxyConnector( proxyConnector ); + } + } + } + + @Override + protected void addRepositoryConfiguration( Configuration configuration, RemoteRepositoryConfiguration repoConfiguration ) + { + configuration.addRemoteRepository( repoConfiguration ); + + } + + + + @Override + public RemoteRepository put( RemoteRepository repository ) throws RepositoryException + { + final String id = repository.getId( ); + RemoteRepository originRepo = getRepositories( ).remove( id ); + if ( originRepo == null && repositoryHandlerManager.isRegisteredId( id ) ) + { + throw new RepositoryException( "There exists a repository with id " + id + ". Could not update with managed repository." ); + } + try + { + if ( originRepo != null && repository != originRepo ) + { + deactivateRepository( originRepo ); + pushEvent( LifecycleEvent.UNREGISTERED, originRepo ); + } + RepositoryProvider provider = getProvider( repository.getType( ) ); + RemoteRepositoryConfiguration newCfg = provider.getRemoteConfiguration( repository ); + getConfigurationHandler( ).getLock( ).writeLock( ).lock( ); + try + { + Configuration configuration = getConfigurationHandler( ).getBaseConfiguration( ); + updateReferences( repository, newCfg ); + RemoteRepositoryConfiguration oldCfg = configuration.findRemoteRepositoryById( id ); + if ( oldCfg != null ) + { + configuration.removeRemoteRepository( oldCfg ); + } + configuration.addRemoteRepository( newCfg ); + getConfigurationHandler( ).save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG ); + setLastState( repository, RepositoryState.SAVED ); + activateRepository( repository ); + } + finally + { + getConfigurationHandler( ).getLock( ).writeLock( ).unlock( ); + } + getRepositories( ).put( id, repository ); + setLastState( repository, RepositoryState.REGISTERED ); + return repository; + } + catch ( Exception e ) + { + // Rollback only partly, because repository is closed already + if ( originRepo != null ) + { + getRepositories( ).put( id, originRepo ); + } + else + { + getRepositories( ).remove( id ); + } + log.error( "Exception during configuration update {}", e.getMessage( ), e ); + throw new RepositoryException( "Could not save the configuration" + ( e.getMessage( ) == null ? "" : ": " + e.getMessage( ) ) ); + } + + } + + @Override + public RemoteRepository put( RemoteRepositoryConfiguration repositoryConfiguration ) throws RepositoryException + { + final String id = repositoryConfiguration.getId( ); + final RepositoryType repositoryType = RepositoryType.valueOf( repositoryConfiguration.getType( ) ); + final RepositoryProvider provider = getProvider( repositoryType ); + ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler( ).getLock( ).writeLock( ); + configLock.lock( ); + RemoteRepository repo = null; + RemoteRepository oldRepository = null; + Configuration configuration = null; + try + { + boolean updated = false; + configuration = getConfigurationHandler( ).getBaseConfiguration( ); + repo = getRepositories( ).get( id ); + oldRepository = repo == null ? null : clone( repo, id ); + if ( repo == null ) + { + repo = put( repositoryConfiguration, configuration ); + } + else + { + setRepositoryDefaults( repositoryConfiguration ); + provider.updateRemoteInstance( (EditableRemoteRepository) repo, repositoryConfiguration ); + updated = true; + pushEvent( LifecycleEvent.UPDATED, repo ); + } + registerNewRepository( repositoryConfiguration, repo, configuration, updated ); + } + catch ( IndeterminateConfigurationException | RegistryException e ) + { + if ( oldRepository != null ) + { + RemoteRepositoryConfiguration oldCfg = provider.getRemoteConfiguration( oldRepository ); + provider.updateRemoteInstance( (EditableRemoteRepository) repo, oldCfg ); + rollback( configuration, oldRepository, e, oldCfg ); + } + else + { + getRepositories( ).remove( id ); + } + log.error( "Could not save the configuration for repository {}: {}", id, e.getMessage( ), e ); + throw new RepositoryException( "Could not save the configuration for repository " + id + ": " + e.getMessage( ) ); + } + finally + { + configLock.unlock( ); + } + return repo; + + } + + @SuppressWarnings( "unused" ) + private void setRepositoryDefaults( RemoteRepositoryConfiguration repositoryConfiguration ) + { + // We do nothing here + } + + + @Override + public RemoteRepository put( RemoteRepositoryConfiguration repositoryConfiguration, Configuration configuration ) throws RepositoryException + { + final String id = repositoryConfiguration.getId( ); + final RepositoryType repoType = RepositoryType.valueOf( repositoryConfiguration.getType( ) ); + RemoteRepository repo; + setRepositoryDefaults( repositoryConfiguration ); + if ( getRepositories( ).containsKey( id ) ) + { + repo = clone( getRepositories( ).get( id ), id ); + if ( repo instanceof EditableRemoteRepository ) + { + getProvider( repoType ).updateRemoteInstance( (EditableRemoteRepository) repo, repositoryConfiguration ); + } + else + { + throw new RepositoryException( "The repository is not editable " + id ); + } + } + else + { + repo = getProvider( repoType ).createRemoteInstance( repositoryConfiguration ); + setLastState( repo, RepositoryState.CREATED ); + } + if ( configuration != null ) + { + replaceOrAddRepositoryConfig( repositoryConfiguration, configuration ); + } + updateReferences( repo, repositoryConfiguration ); + setLastState( repo, RepositoryState.REFERENCES_SET ); + return repo; + + } + + @Override + public RemoteRepository clone( RemoteRepository repo, String newId ) throws RepositoryException + { + RepositoryProvider provider = getProvider( repo.getType( ) ); + RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration( repo ); + cfg.setId( newId ); + RemoteRepository cloned = provider.createRemoteInstance( cfg ); + cloned.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager ); + setLastState( cloned, RepositoryState.CREATED ); + return cloned; + + } + + @Override + public void updateReferences( RemoteRepository repo, RemoteRepositoryConfiguration repositoryConfiguration ) throws RepositoryException + { + if ( repo instanceof EditableRemoteRepository && repo.getContent( ) == null ) + { + EditableRemoteRepository editableRepo = (EditableRemoteRepository) repo; + editableRepo.setContent( repositoryContentFactory.getRemoteRepositoryContent( repo ) ); + if ( repo.supportsFeature( IndexCreationFeature.class ) && repo.getIndexingContext( ) == null ) + { + createIndexingContext( editableRepo ); + } + } + repo.registerEventHandler( RepositoryEvent.ANY, repositoryHandlerManager ); + + } + + private void createIndexingContext( EditableRepository editableRepo ) throws RepositoryException + { + if ( editableRepo.supportsFeature( IndexCreationFeature.class ) ) + { + ArchivaIndexManager idxManager = getIndexManager( editableRepo.getType( ) ); + try + { + editableRepo.setIndexingContext( idxManager.createContext( editableRepo ) ); + idxManager.updateLocalIndexPath( editableRepo ); + } + catch ( IndexCreationFailedException e ) + { + throw new RepositoryException( "Could not create index for repository " + editableRepo.getId( ) + ": " + e.getMessage( ), e ); + } + } + } + + public ArchivaIndexManager getIndexManager( RepositoryType type ) + { + return indexManagerFactory.getIndexManager( type ); + } + +} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/ArchivaRepositoryRegistryTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/ArchivaRepositoryRegistryTest.java index 0b98a1b8e..e4bb05230 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/ArchivaRepositoryRegistryTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/ArchivaRepositoryRegistryTest.java @@ -34,6 +34,7 @@ import org.apache.archiva.repository.base.group.RepositoryGroupHandler; import org.apache.archiva.repository.base.managed.BasicManagedRepository; import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; import org.apache.archiva.repository.base.remote.BasicRemoteRepository; +import org.apache.archiva.repository.base.remote.RemoteRepositoryHandler; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -78,6 +79,9 @@ public class ArchivaRepositoryRegistryTest @Inject ManagedRepositoryHandler managedRepositoryHandler; + @Inject + RemoteRepositoryHandler remoteRepositoryHandler; + private static final Path userCfg = Paths.get(System.getProperty( "user.home" ), ".m2/archiva.xml"); private static Path cfgCopy; @@ -356,7 +360,6 @@ public class ArchivaRepositoryRegistryTest cfg.setId("central"); cfg.setName("This is central test 002"); repo = repositoryRegistry.putRepository( cfg ); - assertSame( internalRepo, repo ); assertEquals("This is central test 002",repo.getName()); assertEquals(2, repositoryRegistry.getRemoteRepositories().size()); @@ -369,9 +372,11 @@ public class ArchivaRepositoryRegistryTest { Configuration configuration = archivaConfiguration.getConfiguration(); RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration(); + Configuration newConfiguration = new Configuration( ); + cfg.setId("test002"); cfg.setName("This is test 002"); - RemoteRepository repo = repositoryRegistry.putRepository( cfg, configuration ); + RemoteRepository repo = repositoryRegistry.putRepository( cfg, newConfiguration ); assertNotNull(repo); assertEquals("test002", repo.getId()); assertEquals("This is test 002", repo.getName()); @@ -379,16 +384,16 @@ public class ArchivaRepositoryRegistryTest archivaConfiguration.reload(); assertEquals(1, archivaConfiguration.getConfiguration().getRemoteRepositories().size()); Collection repos = repositoryRegistry.getRemoteRepositories(); - assertEquals(2, repos.size()); + assertEquals(1, repos.size()); + assertEquals( 1, newConfiguration.getRemoteRepositories( ).size( ) ); RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository( "central" ); cfg = new RemoteRepositoryConfiguration(); cfg.setId("central"); cfg.setName("This is central test 002"); - repo = repositoryRegistry.putRepository( cfg, configuration ); - assertSame( internalRepo, repo ); + repo = repositoryRegistry.putRepository( cfg, newConfiguration ); assertEquals("This is central test 002",repo.getName()); - assertEquals(2, repositoryRegistry.getRemoteRepositories().size()); + assertEquals( 2, newConfiguration.getRemoteRepositories( ).size( ) ); repositoryRegistry.reload(); assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/BasicRepositoryGroupValidatorTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/BasicRepositoryGroupValidatorTest.java index 9470302db..be04ca654 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/BasicRepositoryGroupValidatorTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/BasicRepositoryGroupValidatorTest.java @@ -26,7 +26,7 @@ import org.apache.archiva.repository.RepositoryGroup; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.base.ConfigurationHandler; import org.apache.archiva.repository.base.managed.BasicManagedRepository; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.repository.mock.ManagedRepositoryContentMock; import org.apache.archiva.repository.validation.ValidationResponse; import org.junit.jupiter.api.AfterEach; @@ -61,8 +61,9 @@ class BasicRepositoryGroupValidatorTest @Inject RepositoryGroupHandler repositoryGroupHandler; + @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; Path repoBaseDir; diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/RepositoryGroupHandlerTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/RepositoryGroupHandlerTest.java index f694f7aee..ea65a2e0e 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/RepositoryGroupHandlerTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/RepositoryGroupHandlerTest.java @@ -24,10 +24,12 @@ import org.apache.archiva.common.utils.FileUtils; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.archiva.configuration.RepositoryGroupConfiguration; import org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler; import org.apache.archiva.repository.EditableRepositoryGroup; import org.apache.archiva.repository.ManagedRepository; +import org.apache.archiva.repository.RemoteRepository; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryGroup; import org.apache.archiva.repository.RepositoryHandler; @@ -36,6 +38,7 @@ import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; import org.apache.archiva.repository.base.ConfigurationHandler; import org.apache.archiva.repository.base.managed.BasicManagedRepository; +import org.apache.archiva.repository.base.remote.BasicRemoteRepository; import org.apache.archiva.repository.storage.fs.FilesystemStorage; import org.apache.archiva.repository.validation.CheckedResult; import org.apache.archiva.repository.validation.ValidationError; @@ -90,6 +93,9 @@ class RepositoryGroupHandlerTest @Mock RepositoryHandler managedRepositoryHandler; + @Mock + RepositoryHandler remoteRepositoryHandler; + @Inject ArchivaConfiguration archivaConfiguration; @@ -154,6 +160,20 @@ class RepositoryGroupHandlerTest } Mockito.when( managedRepositoryHandler.get( ArgumentMatchers.eq("internal") ) ).thenReturn( internalRepo ); repositoryRegistry.registerHandler( managedRepositoryHandler ); + + Mockito.when( remoteRepositoryHandler.getVariant( ) ).thenReturn( RemoteRepository.class ); + final RemoteRepository centralRepo; + try + { + centralRepo = getRemote( "central", "central"); + } + catch ( IOException e ) + { + throw new Error( e ); + } + repositoryRegistry.registerHandler( remoteRepositoryHandler ); + + RepositoryGroupHandler groupHandler = new RepositoryGroupHandler( repositoryRegistry, configurationHandler, mergedRemoteIndexesScheduler); groupHandler.init( ); return groupHandler; @@ -176,6 +196,14 @@ class RepositoryGroupHandlerTest return new BasicManagedRepository( id, name, storage ); } + protected RemoteRepository getRemote(String id, String name) throws IOException + { + Path path = getRepoBaseDir().resolve( "../remote" ); + FileLockManager lockManager = new DefaultFileLockManager(); + FilesystemStorage storage = new FilesystemStorage(path.toAbsolutePath(), lockManager); + return new BasicRemoteRepository( id, name, storage ); + } + protected EditableRepositoryGroup createRepository( String id, String name, Path location ) throws IOException { diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/remote/BasicRemoteRepositoryValidatorTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/remote/BasicRemoteRepositoryValidatorTest.java new file mode 100644 index 000000000..97fa94811 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/remote/BasicRemoteRepositoryValidatorTest.java @@ -0,0 +1,233 @@ +package org.apache.archiva.repository.base.remote; + +/* + * 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.archiva.common.filelock.DefaultFileLockManager; +import org.apache.archiva.common.filelock.FileLockManager; +import org.apache.archiva.repository.EditableManagedRepository; +import org.apache.archiva.repository.EditableRemoteRepository; +import org.apache.archiva.repository.EditableRepository; +import org.apache.archiva.repository.ManagedRepository; +import org.apache.archiva.repository.RemoteRepository; +import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.base.ConfigurationHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; +import org.apache.archiva.repository.base.group.RepositoryGroupHandler; +import org.apache.archiva.repository.base.managed.BasicManagedRepository; +import org.apache.archiva.repository.base.managed.BasicManagedRepositoryValidator; +import org.apache.archiva.repository.mock.ManagedRepositoryContentMock; +import org.apache.archiva.repository.mock.RemoteRepositoryContentMock; +import org.apache.archiva.repository.storage.fs.FilesystemStorage; +import org.apache.archiva.repository.validation.ValidationResponse; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.inject.Inject; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * @author Martin Stockhammer + */ +@ExtendWith( SpringExtension.class) +@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" }) +class BasicRemoteRepositoryValidatorTest +{ + + @Inject + ConfigurationHandler configurationHandler; + + @Inject + RepositoryRegistry repositoryRegistry; + + @Inject + RepositoryHandlerDependencies repositoryHandlerDependencies; + + Path repoBaseDir; + + @AfterEach + void cleanup() { + try + { + repositoryRegistry.removeRepository( "test" ); + } + catch ( RepositoryException e ) + { + // Ignore this + } + + } + + protected EditableRemoteRepository createRepository( String id, String name, Path location ) throws IOException + { + FileLockManager lockManager = new DefaultFileLockManager(); + FilesystemStorage storage = new FilesystemStorage(location.toAbsolutePath(), lockManager); + BasicRemoteRepository repo = new BasicRemoteRepository(id, name, storage); + repo.setLocation( location.toAbsolutePath().toUri()); + repo.setContent(new RemoteRepositoryContentMock()); + return repo; + } + + private Path getRepoBaseDir() { + if (repoBaseDir==null) { + try + { + repoBaseDir = Paths.get(Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories" ).toURI()); + } + catch ( URISyntaxException e ) + { + throw new RuntimeException( "Could not retrieve repository base directory" ); + } + } + return repoBaseDir; + } + + + @Test + void apply( ) throws IOException + { + BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler ); + validator.setRepositoryRegistry( repositoryRegistry ); + Path repoDir = getRepoBaseDir().resolve("test" ); + EditableRemoteRepository repo = createRepository( "test", "test", repoDir ); + ValidationResponse result = validator.apply( repo ); + assertTrue( result.isValid( ) ); + } + + @Test + void applyWithExistingRepo( ) throws IOException, RepositoryException + { + BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler ); + validator.setRepositoryRegistry( repositoryRegistry ); + Path repoDir = getRepoBaseDir().resolve("test" ); + EditableRemoteRepository repo = createRepository( "test", "test", repoDir ); + Path repoDir2 = getRepoBaseDir().resolve("test2" ); + EditableRemoteRepository repo2 = createRepository( "test", "test", repoDir2 ); + repositoryRegistry.putRepository( repo ); + ValidationResponse result = validator.apply( repo ); + assertFalse( result.isValid( ) ); + assertEquals( 1, result.getResult( ).size( ) ); + assertTrue( result.getResult( ).containsKey( "id" ) ); + assertEquals( "remote_repository", result.getResult( ).get( "id" ).get( 0 ).getCategory( ) ); + assertEquals( "remote_repo_exists", result.getResult( ).get( "id" ).get( 0 ).getType( ) ); + assertEquals( "id", result.getResult( ).get( "id" ).get( 0 ).getAttribute() ); + } + + @Test + void applyUpdateWithExistingRepo( ) throws IOException, RepositoryException + { + BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler ); + validator.setRepositoryRegistry( repositoryRegistry ); + Path repoDir = getRepoBaseDir().resolve("test" ); + EditableRemoteRepository repo = createRepository( "test", "test", repoDir ); + Path repoDir2 = getRepoBaseDir().resolve("test2" ); + EditableRemoteRepository repo2 = createRepository( "test", "test", repoDir2 ); + repositoryRegistry.putRepository( repo ); + ValidationResponse result = validator.applyForUpdate( repo ); + assertTrue( result.isValid( ) ); + assertEquals( 0, result.getResult( ).size( ) ); + } + + @Test + void applyWithNullObject( ) throws IOException + { + BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler ); + validator.setRepositoryRegistry( repositoryRegistry ); + ValidationResponse result = validator.apply( null ); + assertFalse( result.isValid( ) ); + assertEquals( 1, result.getResult( ).size( ) ); + assertTrue( result.getResult( ).containsKey( "object" ) ); + assertEquals( "remote_repository", result.getResult( ).get( "object" ).get( 0 ).getCategory( ) ); + assertEquals( "isnull", result.getResult( ).get( "object" ).get( 0 ).getType( ) ); + assertEquals( "object", result.getResult( ).get( "object" ).get( 0 ).getAttribute() ); + } + + @Test + void applyWithEmptyId( ) throws IOException + { + BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler ); + validator.setRepositoryRegistry( repositoryRegistry ); + Path repoDir = getRepoBaseDir().resolve("test" ); + EditableRemoteRepository repo = createRepository( "", "test", repoDir ); + ValidationResponse result = validator.apply( repo ); + assertFalse( result.isValid( ) ); + assertEquals( 1, result.getResult( ).size( ) ); + assertTrue( result.getResult( ).containsKey( "id" ) ); + assertEquals( "remote_repository", result.getResult( ).get( "id" ).get( 0 ).getCategory( ) ); + assertEquals( "empty", result.getResult( ).get( "id" ).get( 0 ).getType( ) ); + assertEquals( "id", result.getResult( ).get( "id" ).get( 0 ).getAttribute() ); + } + + @Test + void applyWithBadName( ) throws IOException + { + BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler ); + validator.setRepositoryRegistry( repositoryRegistry ); + Path repoDir = getRepoBaseDir().resolve("test" ); + EditableRemoteRepository repo = createRepository( "test", "badtest\\name", repoDir ); + ValidationResponse result = validator.apply( repo ); + assertFalse( result.isValid( ) ); + assertEquals( 1, result.getResult( ).size( ) ); + assertEquals( "invalid_chars", result.getResult( ).get( "name" ).get( 0 ).getType( ) ); + } + + @Test + void applyWithBadSchedulingExpression( ) throws IOException + { + BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler ); + validator.setRepositoryRegistry( repositoryRegistry ); + Path repoDir = getRepoBaseDir().resolve("test" ); + EditableRemoteRepository repo = createRepository( "test", "test", repoDir ); + repo.setSchedulingDefinition( "xxxxx" ); + ValidationResponse result = validator.apply( repo ); + assertFalse( result.isValid( ) ); + assertEquals( 1, result.getResult( ).size( ) ); + assertEquals( "invalid_scheduling_exp", result.getResult( ).get( "scheduling_definition" ).get( 0 ).getType( ) ); + } + + @Test + void applyForUpdate( ) + { + } + + @Test + void getFlavour( ) + { + BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler ); + validator.setRepositoryRegistry( repositoryRegistry ); + assertEquals( RemoteRepository.class, validator.getFlavour( ) ); + } + + @Test + void isFlavour( ) + { + BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator( configurationHandler ); + validator.setRepositoryRegistry( repositoryRegistry ); + assertTrue( validator.isFlavour( RemoteRepository.class ) ); + assertTrue( validator.isFlavour( BasicRemoteRepository.class ) ); + } +} \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/remote/RemoteRepositoryHandlerTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/remote/RemoteRepositoryHandlerTest.java new file mode 100644 index 000000000..f596b8e23 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/remote/RemoteRepositoryHandlerTest.java @@ -0,0 +1,426 @@ +package org.apache.archiva.repository.base.remote; + +/* + * 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.archiva.common.filelock.DefaultFileLockManager; +import org.apache.archiva.common.filelock.FileLockManager; +import org.apache.archiva.common.utils.FileUtils; +import org.apache.archiva.configuration.ArchivaConfiguration; +import org.apache.archiva.configuration.Configuration; +import org.apache.archiva.configuration.RemoteRepositoryConfiguration; +import org.apache.archiva.indexer.IndexManagerFactory; +import org.apache.archiva.repository.EditableRemoteRepository; +import org.apache.archiva.repository.RemoteRepository; +import org.apache.archiva.repository.Repository; +import org.apache.archiva.repository.RepositoryContentFactory; +import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.RepositoryState; +import org.apache.archiva.repository.RepositoryType; +import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; +import org.apache.archiva.repository.base.ConfigurationHandler; +import org.apache.archiva.repository.storage.fs.FilesystemStorage; +import org.apache.archiva.repository.validation.CheckedResult; +import org.apache.archiva.repository.validation.RepositoryValidator; +import org.apache.archiva.repository.validation.ValidationError; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.inject.Inject; +import javax.inject.Named; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import static org.apache.archiva.repository.validation.ErrorKeys.ISEMPTY; +import static org.junit.jupiter.api.Assertions.*; + +/** + * @author Martin Stockhammer + */ +@ExtendWith( {MockitoExtension.class, SpringExtension.class} ) +@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-remote.xml"} ) +class RemoteRepositoryHandlerTest +{ + static { + initialize(); + } + + @Inject + @Named( "repositoryRegistry" ) + ArchivaRepositoryRegistry repositoryRegistry; + + @Inject + @Named( "repositoryContentFactory#default" ) + RepositoryContentFactory repositoryContentFactory; + + @Inject + IndexManagerFactory indexManagerFactory; + + @Inject + ConfigurationHandler configurationHandler; + + @SuppressWarnings( "unused" ) + @Inject + List> repositoryValidatorList; + + @Inject + ArchivaConfiguration archivaConfiguration; + + Path repoBaseDir; + + + private static void initialize() { + Path baseDir = Paths.get( FileUtils.getBasedir( ) ); + Path config = baseDir.resolve( "src/test/resources/archiva-remote.xml" ); + if ( Files.exists( config ) ) + { + Path destConfig = baseDir.resolve( "target/test-classes/archiva-remote.xml" ); + try + { + Files.copy( config, destConfig ); + } + catch ( IOException e ) + { + System.err.println( "Could not copy file: " + e.getMessage( ) ); + } + } + } + + // Helper method that removes a repo from the configuration + private void removeRepositoryFromConfig( String id) { + Configuration configuration = configurationHandler.getBaseConfiguration( ); + Iterator iter = configuration.getRemoteRepositories().iterator(); + while(iter.hasNext()) { + RemoteRepositoryConfiguration repo = iter.next( ); + if (id.equals(repo.getId())) { + iter.remove(); + break; + } + } + try + { + configurationHandler.save( configuration ); + } + catch ( Throwable e ) + { + System.err.println( "Could not remove repo from config "+id ); + } + } + + private boolean hasRepositoryInConfig( String id) { + assertNotNull( configurationHandler.getBaseConfiguration( ).getRemoteRepositories() ); + return configurationHandler.getBaseConfiguration( ).getRemoteRepositories( ).stream( ).anyMatch( g -> g != null && id.equals( g.getId( ) ) ) ; + } + + + private RemoteRepositoryHandler createHandler( ) + { + RemoteRepositoryHandler repositoryHandler = new RemoteRepositoryHandler( repositoryRegistry, configurationHandler, indexManagerFactory, repositoryContentFactory ); + repositoryHandler.init( ); + return repositoryHandler; + } + + private Path getRepoBaseDir() throws IOException + { + if (repoBaseDir==null) { + this.repoBaseDir = archivaConfiguration.getRepositoryBaseDir( ).resolve( "remote" ); + Files.createDirectories( this.repoBaseDir ); + } + return repoBaseDir; + } + + protected EditableRemoteRepository createRepository( String id, String name, Path location ) throws IOException + { + FileLockManager lockManager = new DefaultFileLockManager(); + FilesystemStorage storage = new FilesystemStorage(location.toAbsolutePath(), lockManager); + BasicRemoteRepository repo = new BasicRemoteRepository(id, name, storage); + repo.setLocation( location.toAbsolutePath().toUri()); + return repo; + } + + protected EditableRemoteRepository createRepository( String id, String name) throws IOException + { + Path dir = getRepoBaseDir( ).resolve( id ); + Files.createDirectories( dir ); + return createRepository( id, name, dir ); + } + + + + + @Test + void initializeFromConfig( ) + { + RemoteRepositoryHandler repoHandler = createHandler( ); + repoHandler.initializeFromConfig( ); + assertEquals( 2, repoHandler.getAll( ).size( ) ); + assertNotNull( repoHandler.get( "test-repo-01" ) ); + assertEquals( "Test Remote Repository", repoHandler.get( "test-repo-01" ).getName() ); + } + + @Test + void activateRepository( ) throws RepositoryException + { + String id = "test-repo-02"; + RemoteRepositoryHandler repoHandler = createHandler( ); + RemoteRepository repo = repoHandler.newInstance( RepositoryType.MAVEN, id ); + repoHandler.activateRepository( repo ); + assertFalse( hasRepositoryInConfig( id )); + assertNull( repoHandler.get( id ) ); + } + + @Test + void newInstancesFromConfig( ) throws RepositoryException + { + final String id = "test-repo-01"; + RemoteRepositoryHandler repoHandler = createHandler( ); + Configuration configuration = new Configuration( ); + repoHandler.remove( "test-repo-01", configuration ); + Map instances = repoHandler.newInstancesFromConfig( ); + assertFalse( repoHandler.hasRepository( id ) ); + assertTrue( instances.containsKey( id ) ); + assertEquals( RepositoryState.REFERENCES_SET, instances.get( id ).getLastState( ) ); + } + + @Test + void newInstance( ) throws RepositoryException + { + String id = "test-repo-03"; + RemoteRepositoryHandler repoHandler = createHandler( ); + RemoteRepository instance = repoHandler.newInstance( RepositoryType.MAVEN, id ); + assertNotNull( instance ); + assertEquals( id, instance.getId( ) ); + assertFalse( repoHandler.hasRepository( id ) ); + assertEquals( RepositoryState.REFERENCES_SET, instance.getLastState( ) ); + assertFalse( hasRepositoryInConfig( id ) ); + } + + + @Test + void put( ) throws IOException, RepositoryException + { + final String id = "test-repo-04"; + try + { + RemoteRepositoryHandler repoHandler = createHandler( ); + EditableRemoteRepository repository = createRepository( id, "n-"+id ); + repoHandler.put( repository ); + RemoteRepository storedRepository = repoHandler.get( id ); + assertNotNull( storedRepository ); + assertEquals( id, storedRepository.getId( ) ); + assertEquals( "n-"+id, storedRepository.getName( ) ); + + EditableRemoteRepository repository2 = createRepository( id, "n2-"+id ); + repoHandler.put( repository2 ); + storedRepository = repoHandler.get( id ); + assertNotNull( storedRepository ); + assertEquals( id, storedRepository.getId( ) ); + assertEquals( "n2-"+id, storedRepository.getName( ) ); + + assertTrue( hasRepositoryInConfig( id )); + } finally { + removeRepositoryFromConfig( id ); + } + } + + @Test + void putWithConfiguration( ) throws RepositoryException + { + String id = "test-repo-05"; + + try + { + RemoteRepositoryHandler repoHandler = createHandler( ); + RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration( ); + configuration.setId( id ); + configuration.setName( "n-" + id ); + repoHandler.put( configuration ); + + RemoteRepository repo = repoHandler.get( id ); + assertNotNull( repo ); + assertEquals( id, repo.getId( ) ); + assertEquals( "n-" + id, repo.getName( ) ); + assertTrue( hasRepositoryInConfig( id ) ); + } + finally + { + removeRepositoryFromConfig( id ); + } + } + + @Test + void testPutWithoutRegister( ) throws RepositoryException + { + final String id = "test-repo-06"; + RemoteRepositoryHandler repoHandler = createHandler( ); + Configuration aCfg = new Configuration( ); + RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration( ); + configuration.setId( id ); + configuration.setName( "n-"+id ); + repoHandler.put( configuration, aCfg ); + + RemoteRepository repo = repoHandler.get( id ); + assertNull( repo ); + assertFalse( hasRepositoryInConfig( id ) ); + assertTrue( aCfg.getRemoteRepositories( ).stream( ).anyMatch( g -> g!=null && id.equals( g.getId( ) ) ) ); + + } + + @Test + void putWithCheck_invalid( ) throws RepositoryException + { + final String id = "test-repo-07"; + final String name = "n-"+id; + try + { + RemoteRepositoryHandler repoHandler = createHandler( ); + BasicRemoteRepositoryValidator checker = new BasicRemoteRepositoryValidator( configurationHandler ); + checker.setRepositoryRegistry( repositoryRegistry ); + RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration(); + configuration.setId( "" ); + configuration.setName( name ); + CheckedResult>> result = repoHandler.putWithCheck( configuration, checker ); + assertNull( repoHandler.get( id ) ); + assertNotNull( result.getResult( ) ); + assertNotNull( result.getResult( ).get( "id" ) ); + assertEquals( 2, result.getResult( ).get( "id" ).size( ) ); + assertEquals( ISEMPTY, result.getResult( ).get( "id" ).get( 0 ).getType( ) ); + assertFalse( hasRepositoryInConfig( id ) ); + assertFalse( hasRepositoryInConfig( "" ) ); + } finally + { + removeRepositoryFromConfig( id ); + } + } + + @Test + void remove( ) throws RepositoryException + { + final String id = "test-repo-08"; + RemoteRepositoryHandler repoHandler = createHandler( ); + RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration( ); + configuration.setId( id ); + configuration.setName( "n-"+id ); + repoHandler.put( configuration ); + assertTrue( hasRepositoryInConfig( id ) ); + assertNotNull( repoHandler.get( id ) ); + repoHandler.remove( id ); + assertNull( repoHandler.get( id ) ); + assertFalse( hasRepositoryInConfig( id ) ); + } + + @Test + void removeWithoutSave( ) throws RepositoryException + { + final String id = "test-repo-09"; + RemoteRepositoryHandler repoHandler = createHandler( ); + Configuration aCfg = new Configuration( ); + RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration( ); + configuration.setId( id ); + configuration.setName( "n-"+id ); + repoHandler.put( configuration, aCfg ); + assertTrue( aCfg.getRemoteRepositories( ).stream( ).anyMatch( g -> g != null && id.equals( g.getId( ) ) ) ); + repoHandler.remove( id, aCfg ); + assertNull( repoHandler.get( id ) ); + assertTrue( aCfg.getRemoteRepositories( ).stream( ).noneMatch( g -> g != null && id.equals( g.getId( ) ) ) ); + assertNull( repoHandler.get( id ) ); + + } + + + @Test + void validateRepository( ) throws IOException + { + final String id = "test-repo-10"; + RemoteRepositoryHandler repoHandler = createHandler( ); + EditableRemoteRepository repository = createRepository( id, "n-"+id ); + CheckedResult>> result = repoHandler.validateRepository( repository ); + assertNotNull( result ); + assertEquals( 0, result.getResult( ).size( ) ); + + repository = createRepository( id, "n-test-repo-10###" ); + result = repoHandler.validateRepository( repository ); + assertNotNull( result ); + assertEquals( 1, result.getResult( ).size( ) ); + assertNotNull( result.getResult().get( "name" ) ); + + } + + @Test + void validateRepositoryIfExisting( ) throws IOException, RepositoryException + { + final String id = "test-repo-11"; + try + { + RemoteRepositoryHandler repoHandler = createHandler( ); + EditableRemoteRepository repository = createRepository( id, "n-" + id ); + repoHandler.put( repository ); + CheckedResult>> result = repoHandler.validateRepository( repository ); + assertNotNull( result ); + assertEquals( 1, result.getResult( ).size( ) ); + } finally + { + removeRepositoryFromConfig( id ); + } + + } + + @Test + void validateRepositoryForUpdate( ) throws IOException, RepositoryException + { + final String id = "test-repo-12"; + try + { + RemoteRepositoryHandler repoHandler = createHandler( ); + EditableRemoteRepository repository = createRepository( id, "n-" + id ); + repoHandler.put( repository ); + CheckedResult>> result = repoHandler.validateRepositoryForUpdate( repository ); + assertNotNull( result ); + assertEquals( 0, result.getResult( ).size( ) ); + } finally + { + removeRepositoryFromConfig( id ); + } + } + + @Test + void has( ) throws IOException, RepositoryException + { + final String id = "test-repo-13"; + try + { + RemoteRepositoryHandler repoHandler = createHandler( ); + EditableRemoteRepository repository = createRepository( id, "n-" + id ); + assertFalse( repoHandler.hasRepository( id ) ); + repoHandler.put( repository ); + assertTrue( repoHandler.hasRepository( id ) ); + } finally + { + removeRepositoryFromConfig( id ); + } + } + +} \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/archiva-remote.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/archiva-remote.xml new file mode 100644 index 000000000..2413cfadd --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/archiva-remote.xml @@ -0,0 +1,219 @@ + + + + 3.0.0 + + + internal + Archiva Managed Internal Repository + This is internal repository. + ${appserver.base}/repositories/internal + ${appserver.base}/repositories/internal/.indexer + default + true + false + true + true + 0 0 * * * ? + 30 + + + staging + Repository with staging + This is repository with staging. + ${appserver.base}/repositories/internal + ${appserver.base}/repositories/internal/.indexer + default + true + false + true + true + 0 0 * * * ? + 30 + true + + + snapshots + Archiva Managed Snapshot Repository + ${appserver.base}/repositories/snapshots + ${appserver.base}/repositories/snapshots/.indexer + default + false + true + false + true + 0 0\,30 * * * ? + 30 + + + + + central + Central Repository + https://repo.maven.apache.org/maven2 + default + 35 + + + test-repo-01 + Test Remote Repository + https://repo.maven.apache.org/maven2 + default + 35 + + + + + test-group-01 + Test Group 01 + MAVEN + + internal + + + + + + + internal + central + + + disabled + once + fix + cached + + + **/* + + + + + + + jaxen/jars/jaxen-1.0-FCS-full.jar + jaxen:jaxen:1.0-FCS:full:jar + + + + + + + artifacts + + **/*.pom + **/*.jar + **/*.ear + **/*.war + **/*.car + **/*.sar + **/*.mar + **/*.rar + **/*.dtd + **/*.tld + **/*.tar.gz + **/*.tar.bz2 + **/*.zip + + + + indexable-content + + **/*.txt + **/*.TXT + **/*.block + **/*.config + **/*.pom + **/*.xml + **/*.xsd + **/*.dtd + **/*.tld + + + + auto-remove + + **/*.bak + **/*~ + **/*- + + + + ignored + + **/.htaccess + **/KEYS + **/*.rb + **/*.sh + **/.svn/** + **/.DAV/** + .index/** + .indexer/** + + + + + create-missing-checksums + validate-checksum + validate-signature + index-content + auto-remove + auto-rename + metadata-updater + create-archiva-metadata + duplicate-artifacts + + + + update-db-bad-content + + + + + + true + true + + + + + + jpa + + + cached + + + + + + + http://download.oracle.com/maven + com/sleepycat/je/license.txt + + + https://download.oracle.com/maven + com/sleepycat/je/license.txt + + + + + diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/spring-context-remote.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/spring-context-remote.xml new file mode 100644 index 000000000..5663d0e97 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/spring-context-remote.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + ]]> + + + + + + + + + + + + \ No newline at end of file diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java index 01215a39d..65a8c2da8 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java @@ -22,10 +22,9 @@ package org.apache.archiva.indexer.maven; import org.apache.archiva.common.utils.FileUtils; import org.apache.archiva.indexer.ArchivaIndexingContext; import org.apache.archiva.indexer.IndexCreationFailedException; -import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; import org.apache.archiva.repository.RepositoryType; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RemoteIndexFeature; import org.apache.archiva.repository.maven.MavenManagedRepository; @@ -65,12 +64,7 @@ public class MavenIndexManagerTest { @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; - - @SuppressWarnings( "unused" ) - @Inject - RepositoryGroupHandler groupHandler; - + RepositoryHandlerDependencies repositoryHandlerDependencies; private Path indexPath; private MavenManagedRepository repository; diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/AbstractMavenRepositorySearch.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/AbstractMavenRepositorySearch.java index e5c38c0d8..7f7c03842 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/AbstractMavenRepositorySearch.java +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/AbstractMavenRepositorySearch.java @@ -29,10 +29,9 @@ import org.apache.archiva.indexer.ArchivaIndexingContext; import org.apache.archiva.indexer.search.SearchResultHit; import org.apache.archiva.indexer.search.SearchResults; import org.apache.archiva.proxy.ProxyRegistry; -import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; import org.apache.archiva.repository.Repository; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.lang3.SystemUtils; @@ -97,12 +96,7 @@ public abstract class AbstractMavenRepositorySearch @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; - - @SuppressWarnings( "unused" ) - @Inject - RepositoryGroupHandler groupHandler; - + RepositoryHandlerDependencies repositoryHandlerDependencies; @Inject ProxyRegistry proxyRegistry; diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchOSGITest.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchOSGITest.java index 416db35c7..79fa98740 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchOSGITest.java +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchOSGITest.java @@ -23,8 +23,7 @@ import org.apache.archiva.indexer.search.SearchFields; import org.apache.archiva.indexer.search.SearchResultHit; import org.apache.archiva.indexer.search.SearchResults; import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.easymock.EasyMock; import org.junit.After; import org.junit.Test; @@ -47,11 +46,7 @@ public class MavenRepositorySearchOSGITest @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; - - @SuppressWarnings( "unused" ) - @Inject - RepositoryGroupHandler groupHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; @After diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchPaginateTest.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchPaginateTest.java index 5f236e462..442b5cdf8 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchPaginateTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchPaginateTest.java @@ -24,8 +24,7 @@ import org.apache.archiva.indexer.search.SearchResultLimits; import org.apache.archiva.indexer.search.SearchResults; import org.apache.archiva.indexer.util.SearchUtil; import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.junit.After; import org.junit.Test; @@ -49,12 +48,7 @@ public class MavenRepositorySearchPaginateTest @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; - - @SuppressWarnings( "unused" ) - @Inject - RepositoryGroupHandler groupHandler; - + RepositoryHandlerDependencies repositoryHandlerDependencies; @After public void endTests() { diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java index 18bc3a3ab..66510e6cd 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java @@ -20,12 +20,25 @@ package org.apache.archiva.proxy; */ import net.sf.ehcache.CacheManager; -import org.apache.archiva.configuration.*; -import org.apache.archiva.policies.*; +import org.apache.archiva.configuration.ArchivaConfiguration; +import org.apache.archiva.configuration.ArchivaRuntimeConfiguration; +import org.apache.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.ProxyConnectorConfiguration; +import org.apache.archiva.configuration.RemoteRepositoryConfiguration; +import org.apache.archiva.policies.CachedFailuresPolicy; +import org.apache.archiva.policies.ChecksumPolicy; +import org.apache.archiva.policies.PolicyOption; +import org.apache.archiva.policies.PropagateErrorsDownloadPolicy; +import org.apache.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy; +import org.apache.archiva.policies.ReleasesPolicy; +import org.apache.archiva.policies.SnapshotsPolicy; import org.apache.archiva.proxy.model.RepositoryProxyHandler; -import org.apache.archiva.repository.*; +import org.apache.archiva.repository.ManagedRepository; +import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.RepositoryType; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.repository.base.managed.BasicManagedRepository; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.maven.wagon.Wagon; @@ -49,7 +62,12 @@ import java.nio.file.Paths; import java.nio.file.attribute.FileTime; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Locale; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -73,8 +91,7 @@ public abstract class AbstractProxyTestCase @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; - + RepositoryHandlerDependencies repositoryHandlerDependencies; protected static final String ID_PROXIED1 = "proxied1"; diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java index 94a04f194..47d7bfe2f 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java @@ -25,9 +25,8 @@ import org.apache.archiva.policies.ChecksumPolicy; import org.apache.archiva.policies.ReleasesPolicy; import org.apache.archiva.policies.SnapshotsPolicy; import org.apache.archiva.policies.urlcache.UrlFailureCache; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; -import org.apache.archiva.repository.content.BaseRepositoryContentLayout; import org.apache.archiva.repository.content.Artifact; +import org.apache.archiva.repository.content.BaseRepositoryContentLayout; import org.apache.archiva.repository.storage.StorageAsset; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.easymock.EasyMock; diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java index f7a4cbf40..a816f858c 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java @@ -30,13 +30,13 @@ import org.apache.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy; import org.apache.archiva.policies.ReleasesPolicy; import org.apache.archiva.policies.SnapshotsPolicy; import org.apache.archiva.proxy.model.RepositoryProxyHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; -import org.apache.archiva.repository.content.BaseRepositoryContentLayout; import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.repository.base.managed.BasicManagedRepository; import org.apache.archiva.repository.content.Artifact; +import org.apache.archiva.repository.content.BaseRepositoryContentLayout; import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; @@ -103,7 +103,7 @@ public class HttpProxyTransferTest @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; private Server server; diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/MavenRepositoryProvider.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/MavenRepositoryProvider.java index 963621fec..f5b2b1ec8 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/MavenRepositoryProvider.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/MavenRepositoryProvider.java @@ -315,10 +315,11 @@ public class MavenRepositoryProvider implements RepositoryProvider { credentials.setPassword(new char[0]); } IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get(); - if (cfg.getIndexDir() != null) { - indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir())); + if ( !StringUtils.isEmpty( cfg.getIndexDir( ) ) ) + { + indexCreationFeature.setIndexPath( getURIFromString( cfg.getIndexDir( ) ) ); } - if (cfg.getPackedIndexDir() != null) { + if (!StringUtils.isEmpty( cfg.getPackedIndexDir() )) { indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir())); } log.debug("Updated remote instance {}", repo); @@ -400,20 +401,26 @@ public class MavenRepositoryProvider implements RepositoryProvider { cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath())); RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get(); - if (remoteIndexFeature.getIndexUri() != null) { + if ( remoteIndexFeature.getIndexUri( ) == null ) + { + cfg.setRemoteIndexUrl( "" ); + } + else + { cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString()); } cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS)); cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup()); cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex()); cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId()); - if (!StringUtils.isEmpty(remoteIndexFeature.getProxyId())) { - cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId()); - } else { + if ( StringUtils.isEmpty( remoteIndexFeature.getProxyId( ) ) ) + { cfg.setRemoteDownloadNetworkProxyId(""); } - - + else + { + cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId()); + } return cfg; diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverMRM1411RepoGroupTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverMRM1411RepoGroupTest.java index 6f53f8815..57ec29ae5 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverMRM1411RepoGroupTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverMRM1411RepoGroupTest.java @@ -36,7 +36,7 @@ import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest; import org.apache.archiva.proxy.maven.WagonFactory; import org.apache.archiva.proxy.maven.WagonFactoryRequest; import org.apache.archiva.repository.RepositoryRegistry; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; import org.apache.maven.wagon.Wagon; @@ -103,7 +103,7 @@ public class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; private WagonFactory wagonFactory; diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverMRM1411Test.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverMRM1411Test.java index 96c448b9a..c7a7bafb7 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverMRM1411Test.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverMRM1411Test.java @@ -37,7 +37,7 @@ import org.apache.archiva.proxy.maven.WagonFactory; import org.apache.archiva.proxy.maven.WagonFactoryRequest; import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryRegistry; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; import org.apache.maven.wagon.Wagon; @@ -100,7 +100,7 @@ public class Maven2RepositoryMetadataResolverMRM1411Test @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; private WagonFactory wagonFactory; diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverManagedReleaseTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverManagedReleaseTest.java index dd29a9a8b..c786302d9 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverManagedReleaseTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverManagedReleaseTest.java @@ -25,7 +25,7 @@ import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest; import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException; import org.apache.archiva.proxy.maven.WagonFactory; import org.apache.archiva.repository.RepositoryRegistry; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.junit.Before; import org.junit.Test; @@ -47,7 +47,7 @@ public class Maven2RepositoryMetadataResolverManagedReleaseTest @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; private static final String TEST_REPO_ID = "test"; diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverManagedSnapshotTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverManagedSnapshotTest.java index 68b8bf4e6..09964e6c3 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverManagedSnapshotTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverManagedSnapshotTest.java @@ -24,7 +24,7 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest; import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException; import org.apache.archiva.repository.RepositoryRegistry; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.junit.Before; import org.junit.Test; @@ -45,7 +45,7 @@ public class Maven2RepositoryMetadataResolverManagedSnapshotTest @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; private static final String TEST_REPO_ID = "test"; diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverTest.java index b91fc6870..ca54e8b49 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryMetadataResolverTest.java @@ -40,7 +40,7 @@ import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataN import org.apache.archiva.proxy.maven.WagonFactory; import org.apache.archiva.proxy.maven.WagonFactoryRequest; import org.apache.archiva.repository.RepositoryRegistry; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; import org.apache.maven.wagon.Wagon; @@ -83,7 +83,7 @@ public class Maven2RepositoryMetadataResolverTest @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; private static final String TEST_REPO_ID = "test"; diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/mock/configuration/MockRepoAdmin.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/mock/configuration/MockRepoAdmin.java index 7fdc16c82..497553d27 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/mock/configuration/MockRepoAdmin.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/mock/configuration/MockRepoAdmin.java @@ -33,7 +33,6 @@ import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.archiva.configuration.ProxyConnectorConfiguration; import org.apache.archiva.configuration.RemoteRepositoryConfiguration; -import org.apache.archiva.indexer.ArchivaIndexingContext; import org.apache.commons.lang3.StringUtils; import org.modelmapper.ModelMapper; import org.springframework.stereotype.Service; @@ -128,13 +127,6 @@ public class MockRepoAdmin return null; //To change body of implemented methods use File | Settings | File Templates. } - @Override - public ArchivaIndexingContext createIndexContext( RemoteRepository repository ) - throws RepositoryAdminException - { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - @Override public List getManagedRepositories() throws RepositoryAdminException diff --git a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java index fe3eb921b..0f8967897 100644 --- a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java @@ -22,14 +22,13 @@ package org.apache.archiva.scheduler.indexing.maven; import junit.framework.TestCase; import org.apache.archiva.indexer.ArchivaIndexingContext; import org.apache.archiva.indexer.UnsupportedBaseContextException; -import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; -import org.apache.archiva.repository.base.managed.BasicManagedRepository; import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.ReleaseScheme; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; -import org.apache.archiva.repository.storage.StorageAsset; +import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; +import org.apache.archiva.repository.base.managed.BasicManagedRepository; import org.apache.archiva.repository.features.IndexCreationFeature; +import org.apache.archiva.repository.storage.StorageAsset; import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.maven.index.ArtifactInfo; @@ -77,11 +76,7 @@ public class ArchivaIndexingTaskExecutorTest @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; - - @SuppressWarnings( "unused" ) - @Inject - RepositoryGroupHandler repositoryGroupHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; @Inject private IndexUpdater indexUpdater; diff --git a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/DownloadRemoteIndexTaskTest.java b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/DownloadRemoteIndexTaskTest.java index bfeb49802..b18261c36 100644 --- a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/DownloadRemoteIndexTaskTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/DownloadRemoteIndexTaskTest.java @@ -29,8 +29,7 @@ import org.apache.archiva.repository.RepositoryProvider; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.UnsupportedURIException; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RemoteIndexFeature; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; @@ -94,12 +93,7 @@ public class DownloadRemoteIndexTaskTest @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; - - @SuppressWarnings( "unused" ) - @Inject - RepositoryGroupHandler repositoryGroupHandler; - + RepositoryHandlerDependencies repositoryHandlerDependencies; @Inject RepositoryProvider repositoryProvider; diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/mock/MockRemoteRepositoryAdmin.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/mock/MockRemoteRepositoryAdmin.java index d5f7c389a..26bc8592e 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/mock/MockRemoteRepositoryAdmin.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/mock/MockRemoteRepositoryAdmin.java @@ -23,7 +23,6 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; import org.apache.archiva.configuration.ArchivaConfiguration; -import org.apache.archiva.indexer.ArchivaIndexingContext; import java.util.List; import java.util.Map; @@ -88,10 +87,4 @@ public class MockRemoteRepositoryAdmin this.archivaConfiguration = archivaConfiguration; } - @Override - public ArchivaIndexingContext createIndexContext( RemoteRepository repository ) - throws RepositoryAdminException - { - return null; - } } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/AbstractArchivaRepositoryScanningTaskExecutorTest.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/AbstractArchivaRepositoryScanningTaskExecutorTest.java index 904a360a4..bbe99bb34 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/AbstractArchivaRepositoryScanningTaskExecutorTest.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/AbstractArchivaRepositoryScanningTaskExecutorTest.java @@ -30,7 +30,7 @@ import org.apache.archiva.components.taskqueue.execution.TaskExecutor; import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.scheduler.repository.model.RepositoryTask; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.junit.After; @@ -69,11 +69,7 @@ public abstract class AbstractArchivaRepositoryScanningTaskExecutorTest @SuppressWarnings( "unused" ) @Inject - ManagedRepositoryHandler managedRepositoryHandler; - - @SuppressWarnings( "unused" ) - @Inject - RepositoryGroupHandler groupHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; @Inject @Named( value = "taskExecutor#test-repository-scanning" ) diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java index 006df7fcf..73f181f39 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java @@ -19,20 +19,21 @@ package org.apache.archiva.webdav; * under the License. */ -import com.gargoylesoftware.htmlunit.*; +import com.gargoylesoftware.htmlunit.HttpMethod; +import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController; +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.WebRequest; +import com.gargoylesoftware.htmlunit.WebResponse; import junit.framework.TestCase; import net.sf.ehcache.CacheManager; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.archiva.configuration.RemoteRepositoryConfiguration; -import org.apache.archiva.indexer.ArchivaIndexingContext; +import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.base.ArchivaRepositoryRegistry; -import org.apache.archiva.repository.ManagedRepository; -import org.apache.archiva.repository.RepositoryType; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.archiva.webdav.httpunit.MkColMethodWebRequest; import org.apache.commons.io.FileUtils; @@ -104,11 +105,7 @@ public abstract class AbstractRepositoryServletTestCase @SuppressWarnings( "unused" ) @Inject - RepositoryGroupHandler repositoryGroupHandler; - - @SuppressWarnings( "unused" ) - @Inject - ManagedRepositoryHandler managedRepositoryHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; @Inject ArchivaRepositoryRegistry repositoryRegistry; diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java index 9b2dd4809..2140e8450 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java @@ -33,13 +33,9 @@ import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.configuration.RepositoryGroupConfiguration; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; -import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.base.group.RepositoryGroupHandler; -import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler; -import org.apache.archiva.repository.maven.content.MavenContentHelper; -import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider; import org.apache.archiva.proxy.ProxyRegistry; import org.apache.archiva.repository.EditableManagedRepository; +import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.RemoteRepository; import org.apache.archiva.repository.RemoteRepositoryContent; import org.apache.archiva.repository.Repository; @@ -49,8 +45,11 @@ import org.apache.archiva.repository.RepositoryContentProvider; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.RepositoryType; +import org.apache.archiva.repository.base.RepositoryHandlerDependencies; import org.apache.archiva.repository.maven.content.ManagedDefaultRepositoryContent; +import org.apache.archiva.repository.maven.content.MavenContentHelper; import org.apache.archiva.repository.maven.content.MavenRepositoryRequestInfo; +import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.webdav.DavException; @@ -162,11 +161,7 @@ public class ArchivaDavResourceFactoryTest @SuppressWarnings( "unused" ) @Inject - RepositoryGroupHandler repositoryGroupHandler; - - @SuppressWarnings( "unused" ) - @Inject - ManagedRepositoryHandler managedRepositoryHandler; + RepositoryHandlerDependencies repositoryHandlerDependencies; public Path getProjectBase() { if (this.projectBase.get()==null) { -- 2.39.5