use of org.apache.archiva.repository.RepositoryProvider in project archiva by apache.
the class ManagedRepositoryHandler method newInstance.
@Override
public ManagedRepository newInstance(RepositoryType type, String id) throws RepositoryException {
log.debug("Creating repo {}", id);
RepositoryProvider provider = getProvider(type);
EditableManagedRepository repo;
try {
repo = provider.createManagedInstance(id, id);
} catch (IOException e) {
throw new RepositoryException("Could not create repository '" + id + "': " + e.getMessage());
}
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 ManagedRepositoryHandler method getStagingRepository.
private ManagedRepository getStagingRepository(ManagedRepository baseRepo) throws RepositoryException {
ManagedRepository stageRepo = get(getStagingId(baseRepo.getId()));
final RepositoryType type = baseRepo.getType();
if (stageRepo == null) {
RepositoryProvider provider = getProvider(type);
ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration(baseRepo);
stageRepo = provider.createStagingInstance(cfg);
if (stageRepo.supportsFeature(StagingRepositoryFeature.class)) {
stageRepo.getFeature(StagingRepositoryFeature.class).setStageRepoNeeded(false);
}
updateReferences(stageRepo, cfg);
}
return stageRepo;
}
use of org.apache.archiva.repository.RepositoryProvider in project archiva by apache.
the class RemoteRepositoryHandler method put.
@Override
public RemoteRepository put(RemoteRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
final String id = repositoryConfiguration.getId();
final RepositoryType repositoryType = RepositoryType.valueOf(repositoryConfiguration.getType());
final RepositoryProvider provider = getProvider(repositoryType);
ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
configLock.lock();
RemoteRepository repo = null;
RemoteRepository oldRepository = null;
Configuration configuration = null;
try {
boolean updated = false;
configuration = getConfigurationHandler().getBaseConfiguration();
repo = getRepositories().get(id);
oldRepository = repo == null ? null : clone(repo, id);
if (repo == null) {
repo = put(repositoryConfiguration, configuration);
} else {
setRepositoryDefaults(repositoryConfiguration);
provider.updateRemoteInstance((EditableRemoteRepository) repo, repositoryConfiguration);
updated = true;
pushEvent(LifecycleEvent.UPDATED, repo);
}
registerNewRepository(repositoryConfiguration, repo, configuration, updated);
} catch (IndeterminateConfigurationException | RegistryException e) {
if (oldRepository != null) {
RemoteRepositoryConfiguration oldCfg = provider.getRemoteConfiguration(oldRepository);
provider.updateRemoteInstance((EditableRemoteRepository) repo, oldCfg);
rollback(configuration, oldRepository, e, oldCfg);
} else {
getRepositories().remove(id);
}
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());
} finally {
configLock.unlock();
}
return repo;
}
use of org.apache.archiva.repository.RepositoryProvider in project archiva by apache.
the class RemoteRepositoryHandler method clone.
@Override
public RemoteRepository clone(RemoteRepository repo, String newId) throws RepositoryException {
RepositoryProvider provider = getProvider(repo.getType());
RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration(repo);
cfg.setId(newId);
RemoteRepository cloned = provider.createRemoteInstance(cfg);
cloned.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
setLastState(cloned, RepositoryState.CREATED);
return cloned;
}
use of org.apache.archiva.repository.RepositoryProvider in project archiva by apache.
the class RemoteRepositoryHandler method newInstance.
@Override
public RemoteRepository newInstance(RemoteRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
RepositoryType type = RepositoryType.valueOf(repositoryConfiguration.getType());
RepositoryProvider provider = getProvider(type);
if (provider == null) {
throw new RepositoryException("Provider not found for repository type: " + repositoryConfiguration.getType());
}
final RemoteRepository repo = provider.createRemoteInstance(repositoryConfiguration);
repo.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
updateReferences(repo, null);
if (repo instanceof EditableRepository) {
((EditableRepository) repo).setLastState(RepositoryState.REFERENCES_SET);
}
return repo;
}
Aggregations