Search in sources :

Example 21 with RepositoryGroupConfiguration

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

the class DefaultRepositoryGroupAdmin method updateRepositoryGroup.

private Boolean updateRepositoryGroup(RepositoryGroup repositoryGroup, AuditInformation auditInformation, boolean triggerAuditEvent) throws RepositoryAdminException {
    validateRepositoryGroup(repositoryGroup, true);
    validateManagedRepositoriesExists(repositoryGroup.getRepositories());
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    RepositoryGroupConfiguration repositoryGroupConfiguration = configuration.getRepositoryGroupsAsMap().get(repositoryGroup.getId());
    repositoryGroupConfiguration.setRepositories(repositoryGroup.getRepositories());
    repositoryGroupConfiguration.setMergedIndexPath(repositoryGroup.getMergedIndexPath());
    repositoryGroupConfiguration.setMergedIndexTtl(repositoryGroup.getMergedIndexTtl());
    repositoryGroupConfiguration.setCronExpression(repositoryGroup.getCronExpression());
    try {
        repositoryRegistry.putRepositoryGroup(repositoryGroupConfiguration);
    } catch (RepositoryException e) {
        log.error("Could not update the repository group in the registry: {}", e.getMessage(), e);
        throw RepositoryAdminException.ofKey("repository_group.registry.update_error", e, repositoryGroup.getId(), e.getMessage());
    }
    org.apache.archiva.repository.RepositoryGroup rg = repositoryRegistry.getRepositoryGroup(repositoryGroup.getId());
    triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.MODIFY_REPO_GROUP, auditInformation);
    return Boolean.TRUE;
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 22 with RepositoryGroupConfiguration

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

the class DefaultRepositoryGroupAdmin method addRepositoryGroup.

@Override
public Boolean addRepositoryGroup(RepositoryGroup repositoryGroup, AuditInformation auditInformation) throws RepositoryAdminException {
    validateRepositoryGroup(repositoryGroup, false);
    validateManagedRepositoriesExists(repositoryGroup.getRepositories());
    RepositoryGroupConfiguration repositoryGroupConfiguration = new RepositoryGroupConfiguration();
    repositoryGroupConfiguration.setId(repositoryGroup.getId());
    repositoryGroupConfiguration.setRepositories(repositoryGroup.getRepositories());
    repositoryGroupConfiguration.setMergedIndexPath(repositoryGroup.getMergedIndexPath());
    repositoryGroupConfiguration.setMergedIndexTtl(repositoryGroup.getMergedIndexTtl());
    repositoryGroupConfiguration.setCronExpression(StringUtils.isEmpty(repositoryGroup.getCronExpression()) ? "0 0 03 ? * MON" : repositoryGroup.getCronExpression());
    try {
        repositoryRegistry.putRepositoryGroup(repositoryGroupConfiguration);
    } catch (RepositoryException e) {
        log.error("Could not add the repository group to the registry: {}", e.getMessage(), e);
        throw RepositoryAdminException.ofKey("repository_group.registry.add_error", e, repositoryGroup.getId(), e.getMessage());
    }
    triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.ADD_REPO_GROUP, auditInformation);
    return Boolean.TRUE;
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 23 with RepositoryGroupConfiguration

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

the class RepositoryGroupHandler method put.

/**
 * Adds a new repository group or updates the repository with the same id, if it exists already.
 * The configuration is saved immediately.
 *
 * @param repositoryGroupConfiguration the repository configuration
 * @return the updated or created repository
 * @throws RepositoryException if an error occurs, or the configuration is not valid.
 */
@Override
public RepositoryGroup put(RepositoryGroupConfiguration repositoryGroupConfiguration) throws RepositoryException {
    final String id = repositoryGroupConfiguration.getId();
    final RepositoryType repositoryType = RepositoryType.valueOf(repositoryGroupConfiguration.getType());
    final RepositoryProvider provider = getProvider(repositoryType);
    RepositoryGroup currentRepository;
    ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
    configLock.lock();
    try {
        Configuration configuration = this.getConfigurationHandler().getBaseConfiguration();
        currentRepository = getRepositories().get(id);
        RepositoryGroup oldRepository = currentRepository == null ? null : clone(currentRepository, id);
        try {
            boolean updated = false;
            if (currentRepository == null) {
                currentRepository = put(repositoryGroupConfiguration, configuration);
            } else {
                setRepositoryGroupDefaults(repositoryGroupConfiguration);
                provider.updateRepositoryGroupInstance((EditableRepositoryGroup) currentRepository, repositoryGroupConfiguration);
                updated = true;
                pushEvent(LifecycleEvent.UPDATED, currentRepository);
            }
            registerNewRepository(repositoryGroupConfiguration, currentRepository, configuration, updated);
        } catch (IndeterminateConfigurationException | RegistryException | RepositoryException e) {
            // Trying a rollback
            if (oldRepository != null) {
                RepositoryGroupConfiguration oldCfg = provider.getRepositoryGroupConfiguration(oldRepository);
                provider.updateRepositoryGroupInstance((EditableRepositoryGroup) currentRepository, oldCfg);
                rollback(configuration, oldRepository, e, oldCfg);
            } else {
                getRepositories().remove(id);
            }
            log.error("Could not save the configuration for repository group {}: {}", id, e.getMessage(), e);
            if (e instanceof RepositoryException) {
                throw (RepositoryException) e;
            } else {
                throw new RepositoryException("Could not save the configuration for repository group " + id + ": " + e.getMessage());
            }
        }
    } finally {
        configLock.unlock();
    }
    return currentRepository;
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryType(org.apache.archiva.repository.RepositoryType) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RepositoryException(org.apache.archiva.repository.RepositoryException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) RegistryException(org.apache.archiva.components.registry.RegistryException) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup)

Example 24 with RepositoryGroupConfiguration

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

the class RepositoryGroupHandler method newInstance.

@Override
public RepositoryGroup newInstance(final RepositoryType type, String id) throws RepositoryException {
    RepositoryProvider provider = getProvider(type);
    RepositoryGroupConfiguration config = new RepositoryGroupConfiguration();
    config.setId(id);
    return createNewRepositoryGroup(provider, config);
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Example 25 with RepositoryGroupConfiguration

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

the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    c = new Configuration();
    testRepo = new ManagedRepositoryConfiguration();
    testRepo.setId(TEST_REPO_ID);
    testRepo.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
    testRepo.setReleases(true);
    testRepo.setSnapshots(false);
    c.addManagedRepository(testRepo);
    testRepoS = new ManagedRepositoryConfiguration();
    testRepoS.setId(TEST_SNAP_REPO_ID);
    testRepoS.setLocation(Paths.get("target/test-repositorys").toAbsolutePath().toString());
    testRepoS.setReleases(false);
    testRepoS.setSnapshots(true);
    c.addManagedRepository(testRepoS);
    RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
    testRemoteRepo.setId(TEST_REMOTE_REPO_ID);
    testRemoteRepo.setLayout("default");
    testRemoteRepo.setName("Central Repository");
    testRemoteRepo.setUrl("http://central.repo.com/maven2");
    testRemoteRepo.setTimeout(10);
    c.addRemoteRepository(testRemoteRepo);
    ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
    proxyConnector.setSourceRepoId(TEST_REPO_ID);
    proxyConnector.setTargetRepoId(TEST_REMOTE_REPO_ID);
    proxyConnector.setDisabled(false);
    c.addProxyConnector(proxyConnector);
    ProxyConnectorConfiguration proxyConnectors = new ProxyConnectorConfiguration();
    proxyConnectors.setSourceRepoId(TEST_SNAP_REPO_ID);
    proxyConnectors.setTargetRepoId(TEST_REMOTE_REPO_ID);
    proxyConnectors.setDisabled(false);
    c.addProxyConnector(proxyConnectors);
    List<String> repos = new ArrayList<>();
    repos.add(TEST_REPO_ID);
    repos.add(TEST_SNAP_REPO_ID);
    RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
    repoGroup.setId(TEST_REPO_GROUP_ID);
    repoGroup.setRepositories(repos);
    c.addRepositoryGroup(repoGroup);
    configuration.save(c);
    repositoryRegistry.reload();
    assertFalse(c.getManagedRepositories().get(0).isSnapshots());
    assertTrue(c.getManagedRepositories().get(0).isReleases());
    assertTrue(c.getManagedRepositories().get(1).isSnapshots());
    assertFalse(c.getManagedRepositories().get(1).isReleases());
    wagonFactory = mock(WagonFactory.class);
    storage.setWagonFactory(wagonFactory);
    Wagon wagon = new MockWagon();
    when(wagonFactory.getWagon(new WagonFactoryRequest().protocol("wagon#http"))).thenReturn(wagon);
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) WagonFactoryRequest(org.apache.archiva.maven.common.proxy.WagonFactoryRequest) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) 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) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArrayList(java.util.ArrayList) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) WagonFactory(org.apache.archiva.maven.common.proxy.WagonFactory) Wagon(org.apache.maven.wagon.Wagon) Before(org.junit.Before)

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