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);
}
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;
}
}
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);
}
}
}
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();
}
}
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();
}
}
Aggregations