Search in sources :

Example 11 with RemoteRepositoryConfiguration

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

the class AbstractRepositoryServletProxiedTestCase method setupCentralRemoteRepo.

protected void setupCentralRemoteRepo() throws Exception {
    remoteCentral = createServer("central");
    assertServerSetupCorrectly(remoteCentral);
    RemoteRepositoryConfiguration remoteRepositoryConfiguration = archivaConfiguration.getConfiguration().getRemoteRepositoriesAsMap().get(remoteCentral.id);
    if (remoteRepositoryConfiguration != null) {
        archivaConfiguration.getConfiguration().removeRemoteRepository(remoteRepositoryConfiguration);
    }
    archivaConfiguration.getConfiguration().addRemoteRepository(remoteCentral.config);
    setupCleanRepo(remoteCentral.root);
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration)

Example 12 with RemoteRepositoryConfiguration

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

the class RepositoryRegistry method getRemoteRepositoriesFromConfig.

private Map<String, RemoteRepository> getRemoteRepositoriesFromConfig() {
    try {
        List<RemoteRepositoryConfiguration> remoteRepoConfigs = getArchivaConfiguration().getConfiguration().getRemoteRepositories();
        if (remoteRepoConfigs == null) {
            // noinspection unchecked
            return Collections.EMPTY_MAP;
        }
        Map<String, RemoteRepository> remoteRepos = new LinkedHashMap<>(remoteRepoConfigs.size());
        Map<RepositoryType, RepositoryProvider> providerMap = createProviderMap();
        for (RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs) {
            RepositoryType repositoryType = RepositoryType.valueOf(repoConfig.getType());
            if (providerMap.containsKey(repositoryType)) {
                RepositoryProvider provider = getProvider(repositoryType);
                try {
                    RemoteRepository remoteRepository = createNewRemoteRepository(provider, repoConfig);
                    remoteRepos.put(repoConfig.getId(), remoteRepository);
                } catch (Exception e) {
                    log.error("Could not create repository {} from config: {}", repoConfig.getId(), e.getMessage(), e);
                }
            }
        }
        return remoteRepos;
    } catch (Throwable e) {
        log.error("Could not initialize remote repositories from config: {}", e.getMessage(), e);
        // noinspection unchecked
        return Collections.EMPTY_MAP;
    }
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RegistryException(org.apache.archiva.redback.components.registry.RegistryException) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with RemoteRepositoryConfiguration

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

the class RepositoryRegistry method doRemoveRepo.

private void doRemoveRepo(RemoteRepository repo, Configuration configuration) {
    repo.close();
    RemoteRepositoryConfiguration cfg = configuration.findRemoteRepositoryById(repo.getId());
    if (cfg != null) {
        configuration.removeRemoteRepository(cfg);
    }
    List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>(configuration.getProxyConnectors());
    for (ProxyConnectorConfiguration proxyConnector : proxyConnectors) {
        if (StringUtils.equals(proxyConnector.getTargetRepoId(), repo.getId())) {
            configuration.removeProxyConnector(proxyConnector);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration)

Example 14 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.RemoteRepositoryConfiguration 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 15 with RemoteRepositoryConfiguration

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

the class RepositoryRegistry method putRepository.

public RemoteRepository putRepository(RemoteRepository remoteRepository, Configuration configuration) throws RepositoryException {
    rwLock.writeLock().lock();
    try {
        final String id = remoteRepository.getId();
        if (managedRepositories.containsKey(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.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);
            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();
    }
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RegistryException(org.apache.archiva.redback.components.registry.RegistryException) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException)

Aggregations

RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)26 Configuration (org.apache.archiva.configuration.Configuration)9 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)8 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)7 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)7 Test (org.junit.Test)6 ContextConfiguration (org.springframework.test.context.ContextConfiguration)6 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)5 ArrayList (java.util.ArrayList)4 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)4 Before (org.junit.Before)4 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)3 WagonFactory (org.apache.archiva.proxy.common.WagonFactory)3 WagonFactoryRequest (org.apache.archiva.proxy.common.WagonFactoryRequest)3 RegistryException (org.apache.archiva.redback.components.registry.RegistryException)3 RepositoryCredentials (org.apache.archiva.repository.RepositoryCredentials)3 RepositoryException (org.apache.archiva.repository.RepositoryException)3 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)3 Wagon (org.apache.maven.wagon.Wagon)3 URI (java.net.URI)2