use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class RemoteRepositoryHandlerTest method removeRepositoryFromConfig.
// Helper method that removes a repo from the configuration
private void removeRepositoryFromConfig(String id) {
Configuration configuration = configurationHandler.getBaseConfiguration();
Iterator<RemoteRepositoryConfiguration> iter = configuration.getRemoteRepositories().iterator();
while (iter.hasNext()) {
RemoteRepositoryConfiguration repo = iter.next();
if (id.equals(repo.getId())) {
iter.remove();
break;
}
}
try {
configurationHandler.save(configuration);
} catch (Throwable e) {
System.err.println("Could not remove repo from config " + id);
}
}
use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class RepositoryProviderMock method getRemoteConfiguration.
@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
configuration.setId(remoteRepository.getId());
configuration.setName(remoteRepository.getName());
configuration.setDescription(remoteRepository.getDescription());
configuration.setLayout(remoteRepository.getLayout());
configuration.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
configuration.setCheckPath(remoteRepository.getCheckPath());
configuration.setExtraHeaders(remoteRepository.getExtraHeaders());
configuration.setExtraParameters(remoteRepository.getExtraParameters());
configuration.setTimeout((int) remoteRepository.getTimeout().getSeconds());
RepositoryCredentials creds = remoteRepository.getLoginCredentials();
if (creds != null) {
PasswordCredentials pwdCreds = (PasswordCredentials) creds;
configuration.setUsername(pwdCreds.getUsername());
configuration.setPassword(new String(pwdCreds.getPassword()));
}
configuration.setUrl(remoteRepository.getLocation() == null ? "" : remoteRepository.getLocation().toString());
RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class);
configuration.setDownloadRemoteIndex(rif.isDownloadRemoteIndex());
configuration.setDownloadRemoteIndexOnStartup(rif.isDownloadRemoteIndexOnStartup());
configuration.setIndexDir(rif.getIndexUri() == null ? "" : rif.getIndexUri().toString());
configuration.setRemoteDownloadNetworkProxyId(rif.getProxyId());
return configuration;
}
use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class Maven2RepositoryMetadataResolverTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
c = new Configuration();
c.setVersion("2.0");
testRepo = new ManagedRepositoryConfiguration();
testRepo.setId(TEST_REPO_ID);
testRepo.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
testRepo.setReleases(true);
testRepo.setSnapshots(true);
c.addManagedRepository(testRepo);
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);
RepositoryScanningConfiguration scCfg = new RepositoryScanningConfiguration();
c.setRepositoryScanning(scCfg);
configuration.save(c);
assertFalse(configuration.isDefaulted());
repositoryRegistry.reload();
assertTrue(c.getManagedRepositories().get(0).isSnapshots());
assertTrue(c.getManagedRepositories().get(0).isReleases());
wagonFactory = mock(WagonFactory.class);
storage.setWagonFactory(wagonFactory);
Wagon wagon = new MockWagon();
when(wagonFactory.getWagon(new WagonFactoryRequest().protocol("wagon#http"))).thenReturn(wagon);
}
use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration 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.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class RemoteRepositoryHandler method clone.
@Override
public RemoteRepository clone(RemoteRepository repo, String newId) throws RepositoryException {
RepositoryProvider provider = getProvider(repo.getType());
RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration(repo);
cfg.setId(newId);
RemoteRepository cloned = provider.createRemoteInstance(cfg);
cloned.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
setLastState(cloned, RepositoryState.CREATED);
return cloned;
}
Aggregations