Search in sources :

Example 31 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class DefaultProxyConnectorRuleAdmin method addProxyConnectorRule.

@Override
public void addProxyConnectorRule(ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation) throws RepositoryAdminException {
    ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration = new ProxyConnectorRuleConfiguration();
    proxyConnectorRuleConfiguration.setPattern(proxyConnectorRule.getPattern());
    proxyConnectorRuleConfiguration.setRuleType(proxyConnectorRule.getProxyConnectorRuleType().getRuleType());
    for (ProxyConnector proxyConnector : proxyConnectorRule.getProxyConnectors()) {
        ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
        proxyConnectorConfiguration.setSourceRepoId(proxyConnector.getSourceRepoId());
        proxyConnectorConfiguration.setTargetRepoId(proxyConnector.getTargetRepoId());
        proxyConnectorRuleConfiguration.getProxyConnectors().add(proxyConnectorConfiguration);
    }
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    configuration.getProxyConnectorRuleConfigurations().add(proxyConnectorRuleConfiguration);
    saveConfiguration(configuration);
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.model.ProxyConnectorRuleConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.model.ProxyConnectorRuleConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector)

Example 32 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class DefaultRepositoryCommonValidator method basicValidation.

/**
 * @param abstractRepository
 * @param update             in update mode if yes already exists won't be check
 * @throws RepositoryAdminException
 */
@Override
public void basicValidation(AbstractRepository abstractRepository, boolean update) throws RepositoryAdminException {
    Configuration config = archivaConfiguration.getConfiguration();
    String repoId = abstractRepository.getId();
    if (!update) {
        if (config.getManagedRepositoriesAsMap().containsKey(repoId)) {
            throw new RepositoryAdminException("Unable to add new repository with id [" + repoId + "], that id already exists as a managed repository.");
        } else if (config.getRepositoryGroupsAsMap().containsKey(repoId)) {
            throw new RepositoryAdminException("Unable to add new repository with id [" + repoId + "], that id already exists as a repository group.");
        } else if (config.getRemoteRepositoriesAsMap().containsKey(repoId)) {
            throw new RepositoryAdminException("Unable to add new repository with id [" + repoId + "], that id already exists as a remote repository.");
        }
    }
    if (StringUtils.isBlank(repoId)) {
        throw new RepositoryAdminException("Repository ID cannot be empty.");
    }
    if (!REPOSITORY_ID_VALID_EXPRESSION_PATTERN.matcher(repoId).matches()) {
        throw new RepositoryAdminException("Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-).");
    }
    String name = abstractRepository.getName();
    if (StringUtils.isBlank(name)) {
        throw new RepositoryAdminException("repository name cannot be empty");
    }
    if (!REPOSITORY_NAME_VALID_EXPRESSION_PATTERN.matcher(name).matches()) {
        throw new RepositoryAdminException("Invalid repository name. Repository Name must only contain alphanumeric characters, white-spaces(' '), " + "forward-slashes(/), open-parenthesis('('), close-parenthesis(')'),  underscores(_), dots(.), and dashes(-).");
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 33 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class ArchivaRepositoryRegistryTest method putManagedRepositoryFromConfigWithoutSave.

@Test
public void putManagedRepositoryFromConfigWithoutSave() throws Exception {
    Configuration configuration = archivaConfiguration.getConfiguration();
    int actualSize = configuration.getManagedRepositories().size();
    Configuration newConfiguration = new Configuration();
    ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
    cfg.setId("test002");
    cfg.setName("This is test 002");
    ManagedRepository repo = repositoryRegistry.putRepository(cfg, newConfiguration);
    assertNotNull(repo);
    assertEquals("test002", repo.getId());
    assertEquals("This is test 002", repo.getName());
    assertNotNull(repo.getContent());
    archivaConfiguration.reload();
    assertEquals(actualSize, configuration.getManagedRepositories().size());
    List<ManagedRepositoryConfiguration> repos = newConfiguration.getManagedRepositories();
    assertEquals(1, repos.size());
    ManagedRepository internalRepo = repositoryRegistry.getManagedRepository("internal");
    cfg = new ManagedRepositoryConfiguration();
    cfg.setId("internal");
    cfg.setName("This is internal test 002");
    repo = repositoryRegistry.putRepository(cfg, newConfiguration);
    assertEquals("This is internal test 002", repo.getName());
    assertEquals(2, newConfiguration.getManagedRepositories().size());
    repositoryRegistry.reload();
    assertEquals(actualSize, configuration.getManagedRepositories().size());
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.jupiter.api.Test)

Example 34 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class RepositoryGroupHandlerTest method removeWithoutSave.

@Test
void removeWithoutSave() throws RepositoryException {
    RepositoryGroupHandler groupHandler = createHandler();
    Configuration aCfg = new Configuration();
    RepositoryGroupConfiguration configuration = new RepositoryGroupConfiguration();
    final String id = "test-group-09";
    configuration.setId(id);
    configuration.setName("n-" + id);
    ArrayList<String> repos = new ArrayList<>();
    repos.add("internal");
    configuration.setRepositories(repos);
    groupHandler.put(configuration, aCfg);
    assertTrue(aCfg.getRepositoryGroups().stream().anyMatch(g -> g != null && id.equals(g.getId())));
    groupHandler.remove(id, aCfg);
    assertNull(groupHandler.get(id));
    assertTrue(aCfg.getRepositoryGroups().stream().noneMatch(g -> g != null && id.equals(g.getId())));
    assertNull(groupHandler.get(id));
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArgumentMatchers(org.mockito.ArgumentMatchers) CheckedResult(org.apache.archiva.repository.validation.CheckedResult) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) ArchivaRepositoryRegistry(org.apache.archiva.repository.base.ArchivaRepositoryRegistry) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) RemoteRepository(org.apache.archiva.repository.RemoteRepository) RepositoryHandler(org.apache.archiva.repository.RepositoryHandler) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ISEMPTY(org.apache.archiva.repository.validation.ErrorKeys.ISEMPTY) Map(java.util.Map) FileUtils(org.apache.archiva.common.utils.FileUtils) Named(javax.inject.Named) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) ConfigurationHandler(org.apache.archiva.repository.base.ConfigurationHandler) ValidationError(org.apache.archiva.repository.validation.ValidationError) Path(java.nio.file.Path) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Iterator(java.util.Iterator) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Files(java.nio.file.Files) FileLockManager(org.apache.archiva.common.filelock.FileLockManager) RepositoryException(org.apache.archiva.repository.RepositoryException) MergedRemoteIndexesScheduler(org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) IOException(java.io.IOException) RepositoryType(org.apache.archiva.repository.RepositoryType) ManagedRepository(org.apache.archiva.repository.ManagedRepository) Mockito.verify(org.mockito.Mockito.verify) BasicRemoteRepository(org.apache.archiva.repository.base.remote.BasicRemoteRepository) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Assertions(org.junit.jupiter.api.Assertions) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) RepositoryState(org.apache.archiva.repository.RepositoryState) BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 35 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class ManagedRepositoryHandlerTest method removeWithoutSave.

@Test
void removeWithoutSave() throws RepositoryException {
    final String id = "test-repo-09";
    ManagedRepositoryHandler repoHandler = createHandler();
    Configuration aCfg = new Configuration();
    ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration();
    configuration.setId(id);
    configuration.setName("n-" + id);
    repoHandler.put(configuration, aCfg);
    assertTrue(aCfg.getManagedRepositories().stream().anyMatch(g -> g != null && id.equals(g.getId())));
    repoHandler.remove(id, aCfg);
    assertNull(repoHandler.get(id));
    assertTrue(aCfg.getManagedRepositories().stream().noneMatch(g -> g != null && id.equals(g.getId())));
    assertNull(repoHandler.get(id));
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) CheckedResult(org.apache.archiva.repository.validation.CheckedResult) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) ArchivaRepositoryRegistry(org.apache.archiva.repository.base.ArchivaRepositoryRegistry) Inject(javax.inject.Inject) Repository(org.apache.archiva.repository.Repository) RepositoryContentFactory(org.apache.archiva.repository.RepositoryContentFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ISEMPTY(org.apache.archiva.repository.validation.ErrorKeys.ISEMPTY) IndexManagerFactory(org.apache.archiva.indexer.IndexManagerFactory) Map(java.util.Map) FileUtils(org.apache.archiva.common.utils.FileUtils) Named(javax.inject.Named) ConfigurationHandler(org.apache.archiva.repository.base.ConfigurationHandler) ValidationError(org.apache.archiva.repository.validation.ValidationError) Path(java.nio.file.Path) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryValidator(org.apache.archiva.repository.validation.RepositoryValidator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Iterator(java.util.Iterator) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Files(java.nio.file.Files) FileLockManager(org.apache.archiva.common.filelock.FileLockManager) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) RepositoryType(org.apache.archiva.repository.RepositoryType) ManagedRepository(org.apache.archiva.repository.ManagedRepository) Test(org.junit.jupiter.api.Test) List(java.util.List) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Assertions(org.junit.jupiter.api.Assertions) RepositoryState(org.apache.archiva.repository.RepositoryState) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

Configuration (org.apache.archiva.configuration.model.Configuration)94 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)56 ContextConfiguration (org.springframework.test.context.ContextConfiguration)45 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)42 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)34 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)34 WebappConfiguration (org.apache.archiva.configuration.model.WebappConfiguration)32 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)29 Path (java.nio.file.Path)27 Test (org.junit.Test)26 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)23 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)23 RepositoryException (org.apache.archiva.repository.RepositoryException)22 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)14 ManagedRepository (org.apache.archiva.repository.ManagedRepository)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 RemoteRepository (org.apache.archiva.repository.RemoteRepository)12 Test (org.junit.jupiter.api.Test)12 LegacyArtifactPath (org.apache.archiva.configuration.model.LegacyArtifactPath)11