use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.
the class ConfigurationRegistryWriter method writeProxyConnectorRuleConfiguration.
private void writeProxyConnectorRuleConfiguration(String prefix, ProxyConnectorRuleConfiguration value, Registry registry) {
if (value != null) {
if (value.getRuleType() != null) {
String ruleType = "ruleType";
registry.setString(prefix + ruleType, value.getRuleType());
}
if (value.getPattern() != null) {
String pattern = "pattern";
registry.setString(prefix + pattern, value.getPattern());
}
if (value.getProxyConnectors() != null && value.getProxyConnectors().size() > 0) {
registry.removeSubset(prefix + "proxyConnectors");
int count = 0;
for (Iterator iter = value.getProxyConnectors().iterator(); iter.hasNext(); count++) {
String name = "proxyConnectors.proxyConnector(" + count + ")";
ProxyConnectorConfiguration o = (ProxyConnectorConfiguration) iter.next();
writeProxyConnectorConfiguration(prefix + name + ".", o, registry);
}
}
}
}
use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.
the class MavenProxyPropertyLoader method load.
public void load(Properties props, Configuration configuration) throws InvalidConfigurationException {
// set up the managed repository
String localCachePath = getMandatoryProperty(props, REPO_LOCAL_STORE);
ManagedRepositoryConfiguration config = new ManagedRepositoryConfiguration();
config.setLocation(localCachePath);
config.setName("Imported Maven-Proxy Cache");
config.setId("maven-proxy");
config.setScanned(false);
config.setReleases(true);
config.setSnapshots(false);
configuration.addManagedRepository(config);
// Add the network proxies.
String propertyList = props.getProperty(PROXY_LIST);
if (propertyList != null) {
StringTokenizer tok = new StringTokenizer(propertyList, ",");
while (tok.hasMoreTokens()) {
String key = tok.nextToken();
if (StringUtils.isNotEmpty(key)) {
NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
proxy.setHost(getMandatoryProperty(props, "proxy." + key + ".host"));
proxy.setPort(Integer.parseInt(getMandatoryProperty(props, "proxy." + key + ".port")));
// the username and password isn't required
proxy.setUsername(props.getProperty("proxy." + key + ".username"));
proxy.setPassword(props.getProperty("proxy." + key + ".password"));
configuration.addNetworkProxy(proxy);
}
}
}
// Add the remote repository list
String repoList = getMandatoryProperty(props, REPO_LIST);
StringTokenizer tok = new StringTokenizer(repoList, ",");
while (tok.hasMoreTokens()) {
String key = tok.nextToken();
Properties repoProps = getSubset(props, "repo." + key + ".");
String url = getMandatoryProperty(props, "repo." + key + ".url");
String proxyKey = repoProps.getProperty("proxy");
// int cachePeriod = Integer.parseInt( repoProps.getProperty( "cache.period", "60" ) );
RemoteRepositoryConfiguration repository = new RemoteRepositoryConfiguration();
repository.setId(key);
repository.setName("Imported Maven-Proxy Remote Proxy");
repository.setUrl(url);
repository.setLayout("legacy");
configuration.addRemoteRepository(repository);
ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
proxyConnector.setSourceRepoId("maven-proxy");
proxyConnector.setTargetRepoId(key);
proxyConnector.setProxyId(proxyKey);
// TODO: convert cachePeriod to closest "daily" or "hourly"
proxyConnector.addPolicy(ProxyConnectorConfiguration.POLICY_SNAPSHOTS, SnapshotsPolicy.DAILY.getId());
proxyConnector.addPolicy(ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.ALWAYS.getId());
configuration.addProxyConnector(proxyConnector);
}
}
use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.
the class ProxyConnectorConfigurationOrderComparatorTest method testSortNormal.
@Test
public void testSortNormal() {
List<ProxyConnectorConfiguration> proxies = new ArrayList<>();
proxies.add(createConnector("corporate", 3));
proxies.add(createConnector("snapshots", 1));
proxies.add(createConnector("3rdparty", 2));
proxies.add(createConnector("sandbox", 4));
Collections.sort(proxies, new ProxyConnectorConfigurationOrderComparator());
assertProxyOrder(new String[] { "snapshots", "3rdparty", "corporate", "sandbox" }, proxies);
}
use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.
the class ProxyConnectorConfigurationOrderComparatorTest method testSortPartial.
@Test
public void testSortPartial() {
List<ProxyConnectorConfiguration> proxies = new ArrayList<>();
proxies.add(createConnector("corporate", 3));
proxies.add(createConnector("snapshots", 0));
proxies.add(createConnector("3rdparty", 2));
proxies.add(createConnector("sandbox", 0));
Collections.sort(proxies, new ProxyConnectorConfigurationOrderComparator());
assertProxyOrder(new String[] { "3rdparty", "corporate", "snapshots", "sandbox" }, proxies);
}
use of org.apache.archiva.configuration.model.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);
}
Aggregations