Search in sources :

Example 21 with ProxyConnectorConfiguration

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);
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration)

Example 22 with ProxyConnectorConfiguration

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);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Properties(java.util.Properties)

Example 23 with ProxyConnectorConfiguration

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);
}
Also used : ProxyConnectorConfigurationOrderComparator(org.apache.archiva.configuration.model.functors.ProxyConnectorConfigurationOrderComparator) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Test(org.junit.Test)

Example 24 with ProxyConnectorConfiguration

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);
}
Also used : ProxyConnectorConfigurationOrderComparator(org.apache.archiva.configuration.model.functors.ProxyConnectorConfigurationOrderComparator) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Test(org.junit.Test)

Example 25 with ProxyConnectorConfiguration

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);
}
Also used : WagonFactoryRequest(org.apache.archiva.maven.common.proxy.WagonFactoryRequest) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) WagonFactory(org.apache.archiva.maven.common.proxy.WagonFactory) Wagon(org.apache.maven.wagon.Wagon) Before(org.junit.Before)

Aggregations

ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)35 ArrayList (java.util.ArrayList)11 Configuration (org.apache.archiva.configuration.model.Configuration)11 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)9 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)9 Path (java.nio.file.Path)6 ProxyConnectorRuleConfiguration (org.apache.archiva.configuration.model.ProxyConnectorRuleConfiguration)6 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)5 Iterator (java.util.Iterator)4 List (java.util.List)4 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)4 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)4 Wagon (org.apache.maven.wagon.Wagon)4 Before (org.junit.Before)4 ContextConfiguration (org.springframework.test.context.ContextConfiguration)4 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)3 LegacyArtifactPath (org.apache.archiva.configuration.model.LegacyArtifactPath)3 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)3 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)3 WagonFactory (org.apache.archiva.maven.common.proxy.WagonFactory)3