use of org.apache.archiva.repository.RepositoryGroup 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.RepositoryGroup in project archiva by apache.
the class RepositoryGroupHandler method initializeFromConfig.
@Override
public void initializeFromConfig() {
getRepositories().clear();
getRepositories().putAll(newInstancesFromConfig());
for (RepositoryGroup group : getRepositories().values()) {
activateRepository(group);
}
}
use of org.apache.archiva.repository.RepositoryGroup in project archiva by apache.
the class RepositoryGroupHandler method newInstancesFromConfig.
@Override
public Map<String, RepositoryGroup> newInstancesFromConfig() {
try {
List<RepositoryGroupConfiguration> repositoryGroupConfigurations = this.getConfigurationHandler().getBaseConfiguration().getRepositoryGroups();
if (repositoryGroupConfigurations == null) {
return Collections.emptyMap();
}
Map<String, RepositoryGroup> repositoryGroupMap = new LinkedHashMap<>(repositoryGroupConfigurations.size());
for (RepositoryGroupConfiguration repoConfig : repositoryGroupConfigurations) {
RepositoryType repositoryType = RepositoryType.valueOf(repoConfig.getType());
if (super.providerMap.containsKey(repositoryType)) {
try {
RepositoryGroup repo = createNewRepositoryGroup(providerMap.get(repositoryType), repoConfig);
repositoryGroupMap.put(repo.getId(), repo);
} catch (Exception e) {
log.error("Could not create repository group {}: {}", repoConfig.getId(), e.getMessage(), e);
}
}
}
return repositoryGroupMap;
} catch (Throwable e) {
log.error("Could not initialize repositories from config: {}", e.getMessage(), e);
return Collections.emptyMap();
}
}
use of org.apache.archiva.repository.RepositoryGroup in project archiva by apache.
the class RepositoryGroupHandler method clone.
@Override
public RepositoryGroup clone(RepositoryGroup repo, String newId) throws RepositoryException {
RepositoryProvider provider = getProvider(repo.getType());
RepositoryGroupConfiguration cfg = provider.getRepositoryGroupConfiguration(repo);
cfg.setId(newId);
RepositoryGroup cloned = provider.createRepositoryGroup(cfg);
cloned.registerEventHandler(RepositoryEvent.ANY, repositoryRegistry);
setLastState(cloned, RepositoryState.CREATED);
return cloned;
}
use of org.apache.archiva.repository.RepositoryGroup in project archiva by apache.
the class RepositoryGroupHandlerTest method put.
@Test
void put() throws IOException, RepositoryException {
final String id = "test-group-04";
try {
RepositoryGroupHandler groupHandler = createHandler();
EditableRepositoryGroup repositoryGroup = createRepository(id, "n-" + id);
groupHandler.put(repositoryGroup);
RepositoryGroup storedGroup = groupHandler.get(id);
assertNotNull(storedGroup);
assertEquals(id, storedGroup.getId());
assertEquals("n-" + id, storedGroup.getName());
EditableRepositoryGroup repositoryGroup2 = createRepository(id, "n2-" + id);
groupHandler.put(repositoryGroup2);
storedGroup = groupHandler.get(id);
assertNotNull(storedGroup);
assertEquals(id, storedGroup.getId());
assertEquals("n2-" + id, storedGroup.getName());
assertTrue(hasGroupInConfig(id));
} finally {
removeGroupFromConfig(id);
}
}
Aggregations