use of org.apache.archiva.repository.event.LifecycleEvent in project archiva by apache.
the class RepositoryGroupHandler method put.
/**
* Adds a new repository group to the current list, or replaces the repository group definition with
* the same id, if it exists already.
* The change is saved to the configuration immediately.
*
* @param repositoryGroup the new repository group.
* @throws RepositoryException if the new repository group could not be saved to the configuration.
*/
@Override
public RepositoryGroup put(final RepositoryGroup repositoryGroup) throws RepositoryException {
final String id = repositoryGroup.getId();
RepositoryGroup originRepoGroup = getRepositories().remove(id);
try {
if (originRepoGroup != null && originRepoGroup != repositoryGroup) {
deactivateRepository(originRepoGroup);
pushEvent(new LifecycleEvent(LifecycleEvent.UNREGISTERED, this, originRepoGroup));
}
RepositoryProvider provider = getProvider(repositoryGroup.getType());
RepositoryGroupConfiguration newCfg = provider.getRepositoryGroupConfiguration(repositoryGroup);
ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
configLock.lock();
try {
Configuration configuration = this.getConfigurationHandler().getBaseConfiguration();
updateReferences(repositoryGroup, newCfg);
RepositoryGroupConfiguration oldCfg = configuration.findRepositoryGroupById(id);
if (oldCfg != null) {
configuration.removeRepositoryGroup(oldCfg);
}
configuration.addRepositoryGroup(newCfg);
getConfigurationHandler().save(configuration, ConfigurationHandler.REGISTRY_EVENT_TAG);
setLastState(repositoryGroup, RepositoryState.SAVED);
activateRepository(repositoryGroup);
} finally {
configLock.unlock();
}
getRepositories().put(id, repositoryGroup);
setLastState(repositoryGroup, RepositoryState.REGISTERED);
return repositoryGroup;
} catch (Exception e) {
// Rollback
if (originRepoGroup != null) {
getRepositories().put(id, originRepoGroup);
} 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()), e);
}
}
use of org.apache.archiva.repository.event.LifecycleEvent in project archiva by apache.
the class ManagedRepositoryHandler method updateReferences.
@Override
public void updateReferences(ManagedRepository repo, ManagedRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
log.debug("Updating references of repo {}", repo.getId());
if (repo.supportsFeature(StagingRepositoryFeature.class)) {
Configuration configuration = getConfigurationHandler().getBaseConfiguration();
RepositoryProvider provider = getProvider(repo.getType());
StagingRepositoryFeature feature = repo.getFeature(StagingRepositoryFeature.class);
if (feature.isStageRepoNeeded() && feature.getStagingRepository() == null) {
ManagedRepository stageRepo = get(getStagingId(repo.getId()));
if (stageRepo == null) {
stageRepo = getStagingRepository(repo);
getRepositories().put(stageRepo.getId(), stageRepo);
if (configuration != null) {
replaceOrAddRepositoryConfig(provider.getManagedConfiguration(stageRepo), configuration);
}
pushEvent(new LifecycleEvent(LifecycleEvent.REGISTERED, this, stageRepo));
}
feature.setStagingRepository(stageRepo);
}
}
if (repo instanceof EditableManagedRepository) {
EditableManagedRepository editableRepo = (EditableManagedRepository) repo;
if (repo.getContent() == null) {
editableRepo.setContent(repositoryContentFactory.getManagedRepositoryContent(repo));
editableRepo.getContent().setRepository(editableRepo);
}
log.debug("Index repo: " + repo.hasIndex());
if (repo.hasIndex() && (repo.getIndexingContext() == null || !repo.getIndexingContext().isOpen())) {
log.debug("Creating indexing context for {}", repo.getId());
createIndexingContext(editableRepo);
}
}
repo.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
}
Aggregations