use of org.apache.archiva.configuration.ProxyConnectorConfiguration in project archiva by apache.
the class Maven2RepositoryMetadataResolverMRM1411Test 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(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);
configuration.save(c);
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("wagon#http", new HashMap<String, String>()))).thenReturn(wagon);
}
use of org.apache.archiva.configuration.ProxyConnectorConfiguration 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.ProxyConnectorConfiguration in project archiva by apache.
the class ProxyConnectorConfigurationOrderComparatorTest method assertProxyOrder.
private void assertProxyOrder(String[] ids, List<ProxyConnectorConfiguration> proxies) {
assertEquals("Proxies.size() == ids.length", ids.length, proxies.size());
int orderFailedAt = -1;
for (int i = 0; i < ids.length; i++) {
if (!StringUtils.equals(ids[i], proxies.get(i).getProxyId())) {
orderFailedAt = i;
break;
}
}
if (orderFailedAt >= 0) {
StringBuilder msg = new StringBuilder();
msg.append("Failed expected order of the proxies <");
msg.append(StringUtils.join(ids, ", "));
msg.append(">, actual <");
boolean needsComma = false;
for (ProxyConnectorConfiguration proxy : proxies) {
if (needsComma) {
msg.append(", ");
}
msg.append(proxy.getProxyId());
needsComma = true;
}
msg.append("> failure at index <").append(orderFailedAt).append(">.");
fail(msg.toString());
}
}
use of org.apache.archiva.configuration.ProxyConnectorConfiguration in project archiva by apache.
the class AbstractProxyTestCase method saveConnector.
protected void saveConnector(String sourceRepoId, String targetRepoId, String checksumPolicy, String releasePolicy, String snapshotPolicy, String cacheFailuresPolicy, String errorPolicy, String errorOnUpdatePolicy, boolean disabled) {
ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration();
connectorConfig.setSourceRepoId(sourceRepoId);
connectorConfig.setTargetRepoId(targetRepoId);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_CHECKSUM, checksumPolicy);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_RELEASES, releasePolicy);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_SNAPSHOTS, snapshotPolicy);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, cacheFailuresPolicy);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_PROPAGATE_ERRORS, errorPolicy);
connectorConfig.addPolicy(ProxyConnectorConfiguration.POLICY_PROPAGATE_ERRORS_ON_UPDATE, errorOnUpdatePolicy);
connectorConfig.setDisabled(disabled);
int count = config.getConfiguration().getProxyConnectors().size();
config.getConfiguration().addProxyConnector(connectorConfig);
// Proper Triggering ...
String prefix = "proxyConnectors.proxyConnector(" + count + ")";
config.triggerChange(prefix + ".sourceRepoId", connectorConfig.getSourceRepoId());
config.triggerChange(prefix + ".targetRepoId", connectorConfig.getTargetRepoId());
config.triggerChange(prefix + ".proxyId", connectorConfig.getProxyId());
config.triggerChange(prefix + ".policies.releases", connectorConfig.getPolicy("releases", ""));
config.triggerChange(prefix + ".policies.checksum", connectorConfig.getPolicy("checksum", ""));
config.triggerChange(prefix + ".policies.snapshots", connectorConfig.getPolicy("snapshots", ""));
config.triggerChange(prefix + ".policies.cache-failures", connectorConfig.getPolicy("cache-failures", ""));
config.triggerChange(prefix + ".policies.propagate-errors", connectorConfig.getPolicy("propagate-errors", ""));
config.triggerChange(prefix + ".policies.propagate-errors-on-update", connectorConfig.getPolicy("propagate-errors-on-update", ""));
}
use of org.apache.archiva.configuration.ProxyConnectorConfiguration in project archiva by apache.
the class DefaultManagedRepositoryAdmin method deleteManagedRepository.
private Boolean deleteManagedRepository(ManagedRepositoryConfiguration repository, boolean deleteContent, Configuration config, boolean stagedOne) throws RepositoryAdminException {
if (!stagedOne) {
RepositorySession repositorySession = getRepositorySessionFactory().createSession();
try {
MetadataRepository metadataRepository = repositorySession.getRepository();
metadataRepository.removeRepository(repository.getId());
// invalidate cache
namespacesCache.remove(repository.getId());
log.debug("call repositoryStatisticsManager.deleteStatistics");
getRepositoryStatisticsManager().deleteStatistics(metadataRepository, repository.getId());
repositorySession.save();
} catch (MetadataRepositoryException e) {
// throw new RepositoryAdminException( e.getMessage(), e );
log.warn("skip error during removing repository from MetadataRepository:{}", e.getMessage(), e);
} finally {
repositorySession.close();
}
}
if (deleteContent) {
// TODO could be async ? as directory can be huge
Path dir = Paths.get(repository.getLocation());
org.apache.archiva.common.utils.FileUtils.deleteQuietly(dir);
}
// olamy: copy list for reading as a unit test in webapp fail with ConcurrentModificationException
List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>(config.getProxyConnectors());
for (ProxyConnectorConfiguration proxyConnector : proxyConnectors) {
if (StringUtils.equals(proxyConnector.getSourceRepoId(), repository.getId())) {
config.removeProxyConnector(proxyConnector);
}
}
Map<String, List<String>> repoToGroupMap = config.getRepositoryToGroupMap();
if (repoToGroupMap != null) {
if (repoToGroupMap.containsKey(repository.getId())) {
List<String> repoGroups = repoToGroupMap.get(repository.getId());
for (String repoGroup : repoGroups) {
// copy to prevent UnsupportedOperationException
RepositoryGroupConfiguration repositoryGroupConfiguration = config.findRepositoryGroupById(repoGroup);
List<String> repos = new ArrayList<>(repositoryGroupConfiguration.getRepositories());
config.removeRepositoryGroup(repositoryGroupConfiguration);
repos.remove(repository.getId());
repositoryGroupConfiguration.setRepositories(repos);
config.addRepositoryGroup(repositoryGroupConfiguration);
}
}
}
try {
removeRepositoryRoles(repository);
} catch (RoleManagerException e) {
throw new RepositoryAdminException("fail to remove repository roles for repository " + repository.getId() + " : " + e.getMessage(), e);
}
try {
final RepositoryRegistry reg = getRepositoryRegistry();
if (reg.getManagedRepository(repository.getId()) != null) {
reg.removeRepository(reg.getManagedRepository(repository.getId()));
}
} catch (RepositoryException e) {
throw new RepositoryAdminException("Removal of repository " + repository.getId() + " failed: " + e.getMessage());
}
saveConfiguration(config);
return Boolean.TRUE;
}
Aggregations