Search in sources :

Example 6 with RepositoryGroupConfiguration

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

the class ArchivaConfigurationTest method testRemoveLastElements.

@Test
public void testRemoveLastElements() throws Exception {
    Path baseFile = getTestFile("target/test/test-file.xml");
    Files.deleteIfExists(baseFile);
    assertFalse(Files.exists(baseFile));
    Path userFile = getTestFile("target/test/test-file-user.xml");
    Files.deleteIfExists(userFile);
    assertFalse(Files.exists(userFile));
    Files.createDirectories(baseFile.getParent());
    FileUtils.copyFile(getTestFile("src/test/conf/conf-single-list-elements.xml").toFile(), baseFile.toFile());
    Files.createDirectories(userFile.getParent());
    FileUtils.writeStringToFile(userFile.toFile(), "<configuration/>", Charset.forName("UTF-8"));
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-remove-central");
    archivaConfiguration.reload();
    Configuration configuration = archivaConfiguration.getConfiguration();
    RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get(0);
    assertNotNull(repositoryGroup);
    configuration.removeRepositoryGroup(repositoryGroup);
    assertTrue(configuration.getRepositoryGroups().isEmpty());
    RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get("central");
    assertNotNull(repository);
    configuration.removeRemoteRepository(repository);
    assertTrue(configuration.getRemoteRepositories().isEmpty());
    ManagedRepositoryConfiguration managedRepository = configuration.getManagedRepositoriesAsMap().get("snapshots");
    assertNotNull(managedRepository);
    configuration.removeManagedRepository(managedRepository);
    assertTrue(configuration.getManagedRepositories().isEmpty());
    ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get(0);
    assertNotNull(proxyConnector);
    configuration.removeProxyConnector(proxyConnector);
    assertTrue(configuration.getProxyConnectors().isEmpty());
    NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get("proxy");
    assertNotNull(networkProxy);
    configuration.removeNetworkProxy(networkProxy);
    assertTrue(configuration.getNetworkProxies().isEmpty());
    LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get(0);
    assertNotNull(path);
    configuration.removeLegacyArtifactPath(path);
    assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
    RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
    String consumer = scanning.getKnownContentConsumers().get(0);
    assertNotNull(consumer);
    scanning.removeKnownContentConsumer(consumer);
    // default values
    assertFalse(scanning.getKnownContentConsumers().isEmpty());
    consumer = scanning.getInvalidContentConsumers().get(0);
    assertNotNull(consumer);
    scanning.removeInvalidContentConsumer(consumer);
    assertTrue(scanning.getInvalidContentConsumers().isEmpty());
    archivaConfiguration.save(configuration);
    archivaConfiguration = lookup(ArchivaConfiguration.class, "test-read-saved");
    configuration = archivaConfiguration.getConfiguration();
    assertNull(configuration.getRemoteRepositoriesAsMap().get("central"));
    assertTrue(configuration.getRepositoryGroups().isEmpty());
    assertNull(configuration.getManagedRepositoriesAsMap().get("snapshots"));
    assertTrue(configuration.getProxyConnectors().isEmpty());
    assertNull(configuration.getNetworkProxiesAsMap().get("proxy"));
    assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
    scanning = configuration.getRepositoryScanning();
    assertFalse(scanning.getKnownContentConsumers().isEmpty());
    assertTrue(scanning.getInvalidContentConsumers().isEmpty());
}
Also used : Path(java.nio.file.Path) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Test(org.junit.Test)

Example 7 with RepositoryGroupConfiguration

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

the class DefaultRepositoryGroupService method updateRepositoryGroup.

@Override
public RepositoryGroup updateRepositoryGroup(final String repositoryGroupId, final RepositoryGroup repositoryGroup) throws ArchivaRestServiceException {
    if (StringUtils.isEmpty(repositoryGroupId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
    }
    if (!repositoryRegistry.hasRepositoryGroup(repositoryGroupId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND), 404);
    }
    repositoryGroup.setId(repositoryGroupId);
    try {
        RepositoryGroupConfiguration configuration = toConfig(repositoryGroup);
        CheckedResult<org.apache.archiva.repository.RepositoryGroup, Map<String, List<ValidationError>>> validationResult = repositoryRegistry.putRepositoryGroupAndValidate(configuration);
        if (validationResult.isValid()) {
            httpServletResponse.setStatus(201);
            return RepositoryGroup.of(validationResult.getRepository());
        } else {
            throw ValidationException.of(validationResult.getResult());
        }
    } catch (RepositoryException e) {
        log.error("Exception during repository group update: {}", e.getMessage(), e);
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, e.getMessage()));
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.rest.api.v2.model.RepositoryGroup) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RepositoryException(org.apache.archiva.repository.RepositoryException) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map)

Example 8 with RepositoryGroupConfiguration

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

the class DefaultRepositoryGroupService method toConfig.

private RepositoryGroupConfiguration toConfig(RepositoryGroup group) {
    RepositoryGroupConfiguration result = new RepositoryGroupConfiguration();
    result.setId(group.getId());
    result.setName(group.getName());
    result.setLocation(group.getLocation());
    result.setRepositories(group.getRepositories());
    MergeConfiguration mergeConfig = group.getMergeConfiguration();
    if (mergeConfig != null) {
        result.setMergedIndexPath(mergeConfig.getMergedIndexPath());
        result.setMergedIndexTtl(mergeConfig.getMergedIndexTtlMinutes());
        result.setCronExpression(mergeConfig.getIndexMergeSchedule());
    }
    return result;
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) MergeConfiguration(org.apache.archiva.rest.api.v2.model.MergeConfiguration)

Example 9 with RepositoryGroupConfiguration

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

the class RepositoryGroupHandlerTest method putWithConfiguration.

@Test
void putWithConfiguration() throws RepositoryException {
    String id = "test-group-05";
    try {
        RepositoryGroupHandler groupHandler = createHandler();
        RepositoryGroupConfiguration configuration = new RepositoryGroupConfiguration();
        configuration.setId(id);
        configuration.setName("n-" + id);
        ArrayList<String> repos = new ArrayList<>();
        repos.add("internal");
        configuration.setRepositories(repos);
        groupHandler.put(configuration);
        RepositoryGroup repo = groupHandler.get(id);
        assertNotNull(repo);
        assertEquals(id, repo.getId());
        assertEquals("n-" + id, repo.getName());
        assertNotNull(repo.getRepositories());
        assertEquals(1, repo.getRepositories().size());
        assertEquals("internal", repo.getRepositories().get(0).getId());
        assertTrue(hasGroupInConfig(id));
    } finally {
        removeGroupFromConfig(id);
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 10 with RepositoryGroupConfiguration

use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration 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)

Aggregations

RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)28 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)11 RepositoryException (org.apache.archiva.repository.RepositoryException)10 Configuration (org.apache.archiva.configuration.model.Configuration)9 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)9 RepositoryGroup (org.apache.archiva.repository.RepositoryGroup)9 ArrayList (java.util.ArrayList)8 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)7 Map (java.util.Map)5 ValidationError (org.apache.archiva.repository.validation.ValidationError)5 Test (org.junit.Test)5 Test (org.junit.jupiter.api.Test)5 ContextConfiguration (org.springframework.test.context.ContextConfiguration)5 IOException (java.io.IOException)4 Iterator (java.util.Iterator)4 List (java.util.List)4 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)4 RepositoryProvider (org.apache.archiva.repository.RepositoryProvider)4 RepositoryType (org.apache.archiva.repository.RepositoryType)4 Path (java.nio.file.Path)3