use of org.apache.archiva.repository.RepositoryProvider in project archiva by apache.
the class RemoteRepositoryHandler method put.
@Override
public RemoteRepository put(RemoteRepository repository) throws RepositoryException {
final String id = repository.getId();
RemoteRepository originRepo = getRepositories().remove(id);
if (originRepo == null && repositoryHandlerManager.isRegisteredId(id)) {
throw new RepositoryException("There exists a repository with id " + id + ". Could not update with managed repository.");
}
try {
if (originRepo != null && repository != originRepo) {
deactivateRepository(originRepo);
pushEvent(LifecycleEvent.UNREGISTERED, originRepo);
}
RepositoryProvider provider = getProvider(repository.getType());
RemoteRepositoryConfiguration newCfg = provider.getRemoteConfiguration(repository);
getConfigurationHandler().getLock().writeLock().lock();
try {
Configuration configuration = getConfigurationHandler().getBaseConfiguration();
updateReferences(repository, newCfg);
RemoteRepositoryConfiguration oldCfg = configuration.findRemoteRepositoryById(id);
if (oldCfg != null) {
configuration.removeRemoteRepository(oldCfg);
}
configuration.addRemoteRepository(newCfg);
getConfigurationHandler().save(configuration, ConfigurationHandler.REGISTRY_EVENT_TAG);
setLastState(repository, RepositoryState.SAVED);
activateRepository(repository);
} finally {
getConfigurationHandler().getLock().writeLock().unlock();
}
getRepositories().put(id, repository);
setLastState(repository, RepositoryState.REGISTERED);
return repository;
} catch (Exception e) {
// Rollback only partly, because repository is closed already
if (originRepo != null) {
getRepositories().put(id, originRepo);
} else {
getRepositories().remove(id);
}
log.error("Exception during configuration update {}", e.getMessage(), e);
throw new RepositoryException("Could not save the configuration" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
}
}
use of org.apache.archiva.repository.RepositoryProvider in project archiva by apache.
the class RemoteRepositoryHandler method newInstance.
@Override
public RemoteRepository newInstance(RepositoryType type, String id) throws RepositoryException {
log.debug("Creating repo {}", id);
RepositoryProvider provider = getProvider(type);
EditableRemoteRepository repo;
repo = provider.createRemoteInstance(id, id);
repo.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
updateReferences(repo, null);
repo.setLastState(RepositoryState.REFERENCES_SET);
return repo;
}
use of org.apache.archiva.repository.RepositoryProvider 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);
}
Aggregations