use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class RepositoryRegistry method removeRepository.
/**
* Removes a managed repository from the registry and configuration, if it exists.
* The change is saved to the configuration immediately.
*
* @param managedRepository the managed repository to remove
* @throws RepositoryException if a error occurs during configuration save
*/
public void removeRepository(ManagedRepository managedRepository) throws RepositoryException {
final String id = managedRepository.getId();
ManagedRepository repo = getManagedRepository(id);
if (repo != null) {
rwLock.writeLock().lock();
try {
repo = managedRepositories.remove(id);
if (repo != null) {
repo.close();
Configuration configuration = getArchivaConfiguration().getConfiguration();
ManagedRepositoryConfiguration cfg = configuration.findManagedRepositoryById(id);
if (cfg != null) {
configuration.removeManagedRepository(cfg);
}
getArchivaConfiguration().save(configuration);
}
} catch (RegistryException | IndeterminateConfigurationException e) {
// Rollback
log.error("Could not save config after repository removal: {}", e.getMessage(), e);
managedRepositories.put(repo.getId(), repo);
throw new RepositoryException("Could not save configuration after repository removal: " + e.getMessage());
} finally {
rwLock.writeLock().unlock();
}
}
}
use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class RepositoryRegistry method getStagingRepository.
private ManagedRepository getStagingRepository(RepositoryProvider provider, ManagedRepositoryConfiguration baseRepoCfg, Configuration configuration) throws RepositoryException {
ManagedRepository stageRepo = getManagedRepository(baseRepoCfg.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
if (stageRepo == null) {
stageRepo = provider.createStagingInstance(baseRepoCfg);
if (stageRepo.supportsFeature(StagingRepositoryFeature.class)) {
stageRepo.getFeature(StagingRepositoryFeature.class).get().setStageRepoNeeded(false);
}
ManagedRepositoryConfiguration stageCfg = provider.getManagedConfiguration(stageRepo);
updateRepositoryReferences(provider, stageRepo, stageCfg, configuration);
}
return stageRepo;
}
use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class RepositoryRegistry method clone.
/**
* Creates a new repository instance with the same settings as this one. The cloned repository is not
* registered or saved to the configuration.
*
* @param repo The origin repository
* @return The cloned repository.
*/
public ManagedRepository clone(ManagedRepository repo, String newId) throws RepositoryException {
if (managedRepositories.containsKey(newId) || remoteRepositories.containsKey(newId)) {
throw new RepositoryException("The given id exists already " + newId);
}
RepositoryProvider provider = getProvider(repo.getType());
ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration(repo);
cfg.setId(newId);
ManagedRepository cloned = provider.createManagedInstance(cfg);
cloned.addListener(this);
return cloned;
}
use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class MockManagedRepositoryAdmin method getManagedRepositories.
@Override
public List<ManagedRepository> getManagedRepositories() throws RepositoryAdminException {
List<ManagedRepositoryConfiguration> managedRepoConfigs = getArchivaConfiguration().getConfiguration().getManagedRepositories();
List<ManagedRepository> managedRepos = new ArrayList<>(managedRepoConfigs.size());
for (ManagedRepositoryConfiguration repoConfig : managedRepoConfigs) {
// TODO add staging repo information back too
ManagedRepository repo = new ManagedRepository(Locale.getDefault(), repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(), repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(), repoConfig.isBlockRedeployments(), repoConfig.getRefreshCronExpression(), repoConfig.getIndexDir(), repoConfig.isScanned(), repoConfig.getRetentionPeriod(), repoConfig.getRetentionCount(), repoConfig.isDeleteReleasedSnapshots(), true);
managedRepos.add(repo);
}
return managedRepos;
}
use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class RepositoryRegistryTest method putManagedRepositoryFromConfigWithoutSave.
@Test
public void putManagedRepositoryFromConfigWithoutSave() throws Exception {
Configuration configuration = archivaConfiguration.getConfiguration();
ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
cfg.setId("test002");
cfg.setName("This is test 002");
ManagedRepository repo = repositoryRegistry.putRepository(cfg, configuration);
assertNotNull(repo);
assertEquals("test002", repo.getId());
assertEquals("This is test 002", repo.getName());
assertNotNull(repo.getContent());
archivaConfiguration.reload();
assertEquals(3, archivaConfiguration.getConfiguration().getManagedRepositories().size());
Collection<ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
assertEquals(5, repos.size());
ManagedRepository internalRepo = repositoryRegistry.getManagedRepository("internal");
cfg = new ManagedRepositoryConfiguration();
cfg.setId("internal");
cfg.setName("This is internal test 002");
repo = repositoryRegistry.putRepository(cfg, configuration);
assertTrue(internalRepo == repo);
assertEquals("This is internal test 002", repo.getName());
assertEquals(5, repositoryRegistry.getManagedRepositories().size());
repositoryRegistry.reload();
assertEquals(4, repositoryRegistry.getManagedRepositories().size());
}
Aggregations