use of org.apache.archiva.repository.EditableRemoteRepository in project archiva by apache.
the class DownloadRemoteIndexTaskTest method getRemoteRepository.
protected RemoteRepository getRemoteRepository(Path repoDirectory) throws IOException, URISyntaxException, UnsupportedURIException, RepositoryException {
EditableRemoteRepository remoteRepository = repositoryProvider.createRemoteInstance("test-repo-re", "foo");
Path indexDirectory = repoDirectory.resolve("index");
Files.createDirectories(indexDirectory);
remoteRepository.setLocation(new URI("http://localhost:" + port));
repoDirectory.toFile().deleteOnExit();
RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class);
rif.setDownloadRemoteIndex(true);
rif.setIndexUri(new URI("http://localhost:" + port + "/index-updates/"));
createIndexingContext(remoteRepository);
// icf.setLocalIndexPath( remoteRepository.getAsset( "index" ) );
return remoteRepository;
}
use of org.apache.archiva.repository.EditableRemoteRepository 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.EditableRemoteRepository in project archiva by apache.
the class RemoteRepositoryHandler method put.
@Override
public RemoteRepository put(RemoteRepositoryConfiguration repositoryConfiguration, Configuration configuration) throws RepositoryException {
final String id = repositoryConfiguration.getId();
final RepositoryType repoType = RepositoryType.valueOf(repositoryConfiguration.getType());
RemoteRepository repo;
setRepositoryDefaults(repositoryConfiguration);
if (getRepositories().containsKey(id)) {
repo = clone(getRepositories().get(id), id);
if (repo instanceof EditableRemoteRepository) {
getProvider(repoType).updateRemoteInstance((EditableRemoteRepository) repo, repositoryConfiguration);
} else {
throw new RepositoryException("The repository is not editable " + id);
}
} else {
repo = getProvider(repoType).createRemoteInstance(repositoryConfiguration);
setLastState(repo, RepositoryState.CREATED);
}
if (configuration != null) {
replaceOrAddRepositoryConfig(repositoryConfiguration, configuration);
}
updateReferences(repo, repositoryConfiguration);
setLastState(repo, RepositoryState.REFERENCES_SET);
return repo;
}
use of org.apache.archiva.repository.EditableRemoteRepository in project archiva by apache.
the class RemoteRepositoryHandler method newInstance.
@Override
public RemoteRepository newInstance(RepositoryType type, String id) throws RepositoryException {
log.debug("Creating repo {}", id);
RepositoryProvider provider = getProvider(type);
EditableRemoteRepository repo;
repo = provider.createRemoteInstance(id, id);
repo.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
updateReferences(repo, null);
repo.setLastState(RepositoryState.REFERENCES_SET);
return repo;
}
use of org.apache.archiva.repository.EditableRemoteRepository in project archiva by apache.
the class BasicRemoteRepositoryValidatorTest method applyWithExistingRepo.
@Test
void applyWithExistingRepo() throws IOException, RepositoryException {
BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator(configurationHandler);
validator.setRepositoryRegistry(repositoryRegistry);
Path repoDir = getRepoBaseDir().resolve("test");
EditableRemoteRepository repo = createRepository("test", "test", repoDir);
Path repoDir2 = getRepoBaseDir().resolve("test2");
EditableRemoteRepository repo2 = createRepository("test", "test", repoDir2);
repositoryRegistry.putRepository(repo);
ValidationResponse<RemoteRepository> result = validator.apply(repo);
assertFalse(result.isValid());
assertEquals(1, result.getResult().size());
assertTrue(result.getResult().containsKey("id"));
assertEquals("remote_repository", result.getResult().get("id").get(0).getCategory());
assertEquals("remote_repo_exists", result.getResult().get("id").get(0).getType());
assertEquals("id", result.getResult().get("id").get(0).getAttribute());
}
Aggregations