Search in sources :

Example 26 with Configuration

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

the class RepositoryRegistry method putRepository.

/**
 * Adds a new repository or updates the repository with the same id, if it exists already.
 * The configuration is saved immediately.
 *
 * @param managedRepositoryConfiguration the repository configuration
 * @return the updated or created repository
 * @throws RepositoryException if an error occurs, or the configuration is not valid.
 */
public ManagedRepository putRepository(ManagedRepositoryConfiguration managedRepositoryConfiguration) throws RepositoryException {
    rwLock.writeLock().lock();
    try {
        final String id = managedRepositoryConfiguration.getId();
        final RepositoryType repositoryType = RepositoryType.valueOf(managedRepositoryConfiguration.getType());
        Configuration configuration = getArchivaConfiguration().getConfiguration();
        ManagedRepository repo = managedRepositories.get(id);
        ManagedRepositoryConfiguration oldCfg = repo != null ? getProvider(repositoryType).getManagedConfiguration(repo) : null;
        repo = putRepository(managedRepositoryConfiguration, configuration);
        try {
            getArchivaConfiguration().save(configuration);
        } catch (IndeterminateConfigurationException | RegistryException e) {
            if (oldCfg != null) {
                getProvider(repositoryType).updateManagedInstance((EditableManagedRepository) 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;
    } finally {
        rwLock.writeLock().unlock();
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 27 with Configuration

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

the class RepositoryRegistry method putRepository.

/**
 * Adds a new repository or updates the repository with the same id, if it exists already.
 * The configuration is saved immediately.
 *
 * @param remoteRepositoryConfiguration the repository configuration
 * @return the updated or created repository
 * @throws RepositoryException if an error occurs, or the configuration is not valid.
 */
public RemoteRepository putRepository(RemoteRepositoryConfiguration remoteRepositoryConfiguration) throws RepositoryException {
    rwLock.writeLock().lock();
    try {
        final String id = remoteRepositoryConfiguration.getId();
        final RepositoryType repositoryType = RepositoryType.valueOf(remoteRepositoryConfiguration.getType());
        Configuration configuration = getArchivaConfiguration().getConfiguration();
        RemoteRepository repo = remoteRepositories.get(id);
        RemoteRepositoryConfiguration oldCfg = repo != null ? getProvider(repositoryType).getRemoteConfiguration(repo) : null;
        repo = putRepository(remoteRepositoryConfiguration, configuration);
        try {
            getArchivaConfiguration().save(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;
    } finally {
        rwLock.writeLock().unlock();
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 28 with Configuration

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

the class RepositoryRegistry method removeRepository.

/**
 * Removes the remote repository from the registry and configuration.
 * The change is saved to the configuration immediately.
 *
 * @param remoteRepository the remote repository to remove
 * @throws RepositoryException if a error occurs during configuration save
 */
public void removeRepository(RemoteRepository remoteRepository) throws RepositoryException {
    final String id = remoteRepository.getId();
    RemoteRepository repo = getRemoteRepository(id);
    if (repo != null) {
        rwLock.writeLock().lock();
        try {
            repo = remoteRepositories.remove(id);
            if (repo != null) {
                Configuration configuration = getArchivaConfiguration().getConfiguration();
                doRemoveRepo(repo, configuration);
                getArchivaConfiguration().save(configuration);
            }
        } 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());
        } finally {
            rwLock.writeLock().unlock();
        }
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 29 with Configuration

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

the class RepositoryRegistry method removeRepository.

/**
 * Removes a managed repository from the registry and configuration, if it exists.
 * The change is saved to the configuration immediately.
 *
 * @param managedRepository the managed repository to remove
 * @throws RepositoryException if a error occurs during configuration save
 */
public void removeRepository(ManagedRepository managedRepository) throws RepositoryException {
    final String id = managedRepository.getId();
    ManagedRepository repo = getManagedRepository(id);
    if (repo != null) {
        rwLock.writeLock().lock();
        try {
            repo = managedRepositories.remove(id);
            if (repo != null) {
                repo.close();
                Configuration configuration = getArchivaConfiguration().getConfiguration();
                ManagedRepositoryConfiguration cfg = configuration.findManagedRepositoryById(id);
                if (cfg != null) {
                    configuration.removeManagedRepository(cfg);
                }
                getArchivaConfiguration().save(configuration);
            }
        } catch (RegistryException | IndeterminateConfigurationException e) {
            // Rollback
            log.error("Could not save config after repository removal: {}", e.getMessage(), e);
            managedRepositories.put(repo.getId(), repo);
            throw new RepositoryException("Could not save configuration after repository removal: " + e.getMessage());
        } finally {
            rwLock.writeLock().unlock();
        }
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 30 with Configuration

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

the class RepositoryRegistryTest method putRemoteRepositoryFromConfigWithoutSave.

@Test
public void putRemoteRepositoryFromConfigWithoutSave() throws Exception {
    Configuration configuration = archivaConfiguration.getConfiguration();
    RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
    cfg.setId("test002");
    cfg.setName("This is test 002");
    RemoteRepository repo = repositoryRegistry.putRepository(cfg, configuration);
    assertNotNull(repo);
    assertEquals("test002", repo.getId());
    assertEquals("This is test 002", repo.getName());
    assertNotNull(repo.getContent());
    archivaConfiguration.reload();
    assertEquals(1, archivaConfiguration.getConfiguration().getRemoteRepositories().size());
    Collection<RemoteRepository> repos = repositoryRegistry.getRemoteRepositories();
    assertEquals(2, repos.size());
    RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository("central");
    cfg = new RemoteRepositoryConfiguration();
    cfg.setId("central");
    cfg.setName("This is central test 002");
    repo = repositoryRegistry.putRepository(cfg, configuration);
    assertTrue(internalRepo == repo);
    assertEquals("This is central test 002", repo.getName());
    assertEquals(2, repositoryRegistry.getRemoteRepositories().size());
    repositoryRegistry.reload();
    assertEquals(1, repositoryRegistry.getRemoteRepositories().size());
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Test(org.junit.Test)

Aggregations

Configuration (org.apache.archiva.configuration.Configuration)63 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)30 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)29 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)21 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)19 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)18 ContextConfiguration (org.springframework.test.context.ContextConfiguration)16 NetworkConfiguration (org.apache.archiva.admin.model.beans.NetworkConfiguration)13 UiConfiguration (org.apache.archiva.admin.model.beans.UiConfiguration)13 WebappConfiguration (org.apache.archiva.configuration.WebappConfiguration)13 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)11 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)11 RegistryException (org.apache.archiva.redback.components.registry.RegistryException)11 Before (org.junit.Before)11 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 Path (java.nio.file.Path)8 RepositoryException (org.apache.archiva.repository.RepositoryException)7 IOException (java.io.IOException)4 NetworkProxyConfiguration (org.apache.archiva.configuration.NetworkProxyConfiguration)4