use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class DefaultRepositoryGroupAdmin method updateRepositoryGroup.
private Boolean updateRepositoryGroup(RepositoryGroup repositoryGroup, AuditInformation auditInformation, boolean triggerAuditEvent) throws RepositoryAdminException {
validateRepositoryGroup(repositoryGroup, true);
validateManagedRepositoriesExists(repositoryGroup.getRepositories());
Configuration configuration = getArchivaConfiguration().getConfiguration();
RepositoryGroupConfiguration repositoryGroupConfiguration = configuration.getRepositoryGroupsAsMap().get(repositoryGroup.getId());
repositoryGroupConfiguration.setRepositories(repositoryGroup.getRepositories());
repositoryGroupConfiguration.setMergedIndexPath(repositoryGroup.getMergedIndexPath());
repositoryGroupConfiguration.setMergedIndexTtl(repositoryGroup.getMergedIndexTtl());
repositoryGroupConfiguration.setCronExpression(repositoryGroup.getCronExpression());
try {
repositoryRegistry.putRepositoryGroup(repositoryGroupConfiguration);
} catch (RepositoryException e) {
log.error("Could not update the repository group in the registry: {}", e.getMessage(), e);
throw RepositoryAdminException.ofKey("repository_group.registry.update_error", e, repositoryGroup.getId(), e.getMessage());
}
org.apache.archiva.repository.RepositoryGroup rg = repositoryRegistry.getRepositoryGroup(repositoryGroup.getId());
triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.MODIFY_REPO_GROUP, auditInformation);
return Boolean.TRUE;
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class DefaultRepositoryGroupAdmin method addRepositoryGroup.
@Override
public Boolean addRepositoryGroup(RepositoryGroup repositoryGroup, AuditInformation auditInformation) throws RepositoryAdminException {
validateRepositoryGroup(repositoryGroup, false);
validateManagedRepositoriesExists(repositoryGroup.getRepositories());
RepositoryGroupConfiguration repositoryGroupConfiguration = new RepositoryGroupConfiguration();
repositoryGroupConfiguration.setId(repositoryGroup.getId());
repositoryGroupConfiguration.setRepositories(repositoryGroup.getRepositories());
repositoryGroupConfiguration.setMergedIndexPath(repositoryGroup.getMergedIndexPath());
repositoryGroupConfiguration.setMergedIndexTtl(repositoryGroup.getMergedIndexTtl());
repositoryGroupConfiguration.setCronExpression(StringUtils.isEmpty(repositoryGroup.getCronExpression()) ? "0 0 03 ? * MON" : repositoryGroup.getCronExpression());
try {
repositoryRegistry.putRepositoryGroup(repositoryGroupConfiguration);
} catch (RepositoryException e) {
log.error("Could not add the repository group to the registry: {}", e.getMessage(), e);
throw RepositoryAdminException.ofKey("repository_group.registry.add_error", e, repositoryGroup.getId(), e.getMessage());
}
triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.ADD_REPO_GROUP, auditInformation);
return Boolean.TRUE;
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class RepositoryGroupHandler method put.
/**
* Adds a new repository group or updates the repository with the same id, if it exists already.
* The configuration is saved immediately.
*
* @param repositoryGroupConfiguration the repository configuration
* @return the updated or created repository
* @throws RepositoryException if an error occurs, or the configuration is not valid.
*/
@Override
public RepositoryGroup put(RepositoryGroupConfiguration repositoryGroupConfiguration) throws RepositoryException {
final String id = repositoryGroupConfiguration.getId();
final RepositoryType repositoryType = RepositoryType.valueOf(repositoryGroupConfiguration.getType());
final RepositoryProvider provider = getProvider(repositoryType);
RepositoryGroup currentRepository;
ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
configLock.lock();
try {
Configuration configuration = this.getConfigurationHandler().getBaseConfiguration();
currentRepository = getRepositories().get(id);
RepositoryGroup oldRepository = currentRepository == null ? null : clone(currentRepository, id);
try {
boolean updated = false;
if (currentRepository == null) {
currentRepository = put(repositoryGroupConfiguration, configuration);
} else {
setRepositoryGroupDefaults(repositoryGroupConfiguration);
provider.updateRepositoryGroupInstance((EditableRepositoryGroup) currentRepository, repositoryGroupConfiguration);
updated = true;
pushEvent(LifecycleEvent.UPDATED, currentRepository);
}
registerNewRepository(repositoryGroupConfiguration, currentRepository, configuration, updated);
} catch (IndeterminateConfigurationException | RegistryException | RepositoryException e) {
// Trying a rollback
if (oldRepository != null) {
RepositoryGroupConfiguration oldCfg = provider.getRepositoryGroupConfiguration(oldRepository);
provider.updateRepositoryGroupInstance((EditableRepositoryGroup) currentRepository, oldCfg);
rollback(configuration, oldRepository, e, oldCfg);
} else {
getRepositories().remove(id);
}
log.error("Could not save the configuration for repository group {}: {}", id, e.getMessage(), e);
if (e instanceof RepositoryException) {
throw (RepositoryException) e;
} else {
throw new RepositoryException("Could not save the configuration for repository group " + id + ": " + e.getMessage());
}
}
} finally {
configLock.unlock();
}
return currentRepository;
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration 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);
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
c = new Configuration();
testRepo = new ManagedRepositoryConfiguration();
testRepo.setId(TEST_REPO_ID);
testRepo.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
testRepo.setReleases(true);
testRepo.setSnapshots(false);
c.addManagedRepository(testRepo);
testRepoS = new ManagedRepositoryConfiguration();
testRepoS.setId(TEST_SNAP_REPO_ID);
testRepoS.setLocation(Paths.get("target/test-repositorys").toAbsolutePath().toString());
testRepoS.setReleases(false);
testRepoS.setSnapshots(true);
c.addManagedRepository(testRepoS);
RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
testRemoteRepo.setId(TEST_REMOTE_REPO_ID);
testRemoteRepo.setLayout("default");
testRemoteRepo.setName("Central Repository");
testRemoteRepo.setUrl("http://central.repo.com/maven2");
testRemoteRepo.setTimeout(10);
c.addRemoteRepository(testRemoteRepo);
ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
proxyConnector.setSourceRepoId(TEST_REPO_ID);
proxyConnector.setTargetRepoId(TEST_REMOTE_REPO_ID);
proxyConnector.setDisabled(false);
c.addProxyConnector(proxyConnector);
ProxyConnectorConfiguration proxyConnectors = new ProxyConnectorConfiguration();
proxyConnectors.setSourceRepoId(TEST_SNAP_REPO_ID);
proxyConnectors.setTargetRepoId(TEST_REMOTE_REPO_ID);
proxyConnectors.setDisabled(false);
c.addProxyConnector(proxyConnectors);
List<String> repos = new ArrayList<>();
repos.add(TEST_REPO_ID);
repos.add(TEST_SNAP_REPO_ID);
RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
repoGroup.setId(TEST_REPO_GROUP_ID);
repoGroup.setRepositories(repos);
c.addRepositoryGroup(repoGroup);
configuration.save(c);
repositoryRegistry.reload();
assertFalse(c.getManagedRepositories().get(0).isSnapshots());
assertTrue(c.getManagedRepositories().get(0).isReleases());
assertTrue(c.getManagedRepositories().get(1).isSnapshots());
assertFalse(c.getManagedRepositories().get(1).isReleases());
wagonFactory = mock(WagonFactory.class);
storage.setWagonFactory(wagonFactory);
Wagon wagon = new MockWagon();
when(wagonFactory.getWagon(new WagonFactoryRequest().protocol("wagon#http"))).thenReturn(wagon);
}
Aggregations