Search in sources :

Example 36 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.

the class ConfigurationRegistryWriter method writeConfiguration.

private void writeConfiguration(String prefix, Configuration value, Registry registry) {
    if (value != null) {
        if (value.getVersion() != null) {
            String version = "version";
            registry.setString(prefix + version, value.getVersion());
        }
        if (value.getMetadataStore() != null && !value.getMetadataStore().equals("jcr")) {
            String metadataStore = "metadataStore";
            registry.setString(prefix + metadataStore, value.getMetadataStore());
        }
        if (value.getRepositoryGroups() != null && value.getRepositoryGroups().size() > 0) {
            registry.removeSubset(prefix + "repositoryGroups");
            int count = 0;
            for (Iterator iter = value.getRepositoryGroups().iterator(); iter.hasNext(); count++) {
                String name = "repositoryGroups.repositoryGroup(" + count + ")";
                RepositoryGroupConfiguration o = (RepositoryGroupConfiguration) iter.next();
                writeRepositoryGroupConfiguration(prefix + name + ".", o, registry);
            }
        }
        if (value.getManagedRepositories() != null && value.getManagedRepositories().size() > 0) {
            registry.removeSubset(prefix + "managedRepositories");
            int count = 0;
            for (Iterator iter = value.getManagedRepositories().iterator(); iter.hasNext(); count++) {
                String name = "managedRepositories.managedRepository(" + count + ")";
                ManagedRepositoryConfiguration o = (ManagedRepositoryConfiguration) iter.next();
                writeManagedRepositoryConfiguration(prefix + name + ".", o, registry);
            }
        }
        if (value.getRemoteRepositories() != null && value.getRemoteRepositories().size() > 0) {
            registry.removeSubset(prefix + "remoteRepositories");
            int count = 0;
            for (Iterator iter = value.getRemoteRepositories().iterator(); iter.hasNext(); count++) {
                String name = "remoteRepositories.remoteRepository(" + count + ")";
                RemoteRepositoryConfiguration o = (RemoteRepositoryConfiguration) iter.next();
                writeRemoteRepositoryConfiguration(prefix + name + ".", o, registry);
            }
        }
        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);
            }
        }
        if (value.getNetworkProxies() != null && value.getNetworkProxies().size() > 0) {
            registry.removeSubset(prefix + "networkProxies");
            int count = 0;
            for (Iterator iter = value.getNetworkProxies().iterator(); iter.hasNext(); count++) {
                String name = "networkProxies.networkProxy(" + count + ")";
                NetworkProxyConfiguration o = (NetworkProxyConfiguration) iter.next();
                writeNetworkProxyConfiguration(prefix + name + ".", o, registry);
            }
        }
        if (value.getLegacyArtifactPaths() != null && value.getLegacyArtifactPaths().size() > 0) {
            registry.removeSubset(prefix + "legacyArtifactPaths");
            int count = 0;
            for (Iterator iter = value.getLegacyArtifactPaths().iterator(); iter.hasNext(); count++) {
                String name = "legacyArtifactPaths.legacyArtifactPath(" + count + ")";
                LegacyArtifactPath o = (LegacyArtifactPath) iter.next();
                writeLegacyArtifactPath(prefix + name + ".", o, registry);
            }
        }
        if (value.getRepositoryScanning() != null) {
            writeRepositoryScanningConfiguration(prefix + "repositoryScanning.", value.getRepositoryScanning(), registry);
        }
        if (value.getWebapp() != null) {
            writeWebappConfiguration(prefix + "webapp.", value.getWebapp(), registry);
        }
        if (value.getOrganisationInfo() != null) {
            writeOrganisationInformation(prefix + "organisationInfo.", value.getOrganisationInfo(), registry);
        }
        if (value.getNetworkConfiguration() != null) {
            writeNetworkConfiguration(prefix + "networkConfiguration.", value.getNetworkConfiguration(), registry);
        }
        if (value.getRedbackRuntimeConfiguration() != null) {
            writeRedbackRuntimeConfiguration(prefix + "redbackRuntimeConfiguration.", value.getRedbackRuntimeConfiguration(), registry);
        }
        if (value.getArchivaRuntimeConfiguration() != null) {
            writeArchivaRuntimeConfiguration(prefix + "archivaRuntimeConfiguration.", value.getArchivaRuntimeConfiguration(), registry);
        }
        if (value.getProxyConnectorRuleConfigurations() != null && value.getProxyConnectorRuleConfigurations().size() > 0) {
            registry.removeSubset(prefix + "proxyConnectorRuleConfigurations");
            int count = 0;
            for (Iterator iter = value.getProxyConnectorRuleConfigurations().iterator(); iter.hasNext(); count++) {
                String name = "proxyConnectorRuleConfigurations.proxyConnectorRuleConfiguration(" + count + ")";
                ProxyConnectorRuleConfiguration o = (ProxyConnectorRuleConfiguration) iter.next();
                writeProxyConnectorRuleConfiguration(prefix + name + ".", o, registry);
            }
        }
        if (value.getArchivaDefaultConfiguration() != null) {
            writeArchivaDefaultConfiguration(prefix + "archivaDefaultConfiguration.", value.getArchivaDefaultConfiguration(), registry);
        }
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.model.ProxyConnectorRuleConfiguration) Iterator(java.util.Iterator) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration)

Example 37 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.

the class ConfigurationTest method testManagedRepositoryRetrieval.

@Test
public void testManagedRepositoryRetrieval() {
    ManagedRepositoryConfiguration repo1 = createManagedRepository("id1", "name 1", "path 1", false);
    configuration.addManagedRepository(repo1);
    ManagedRepositoryConfiguration repo2 = createManagedRepository("id2", "name 2", "path 2", true);
    configuration.addManagedRepository(repo2);
    Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
    assertNotNull(map);
    assertEquals(2, map.size());
    assertEquals(new HashSet<String>(Arrays.asList("id1", "id2")), map.keySet());
    assertEquals(new HashSet<ManagedRepositoryConfiguration>(Arrays.asList(repo1, repo2)), new HashSet<ManagedRepositoryConfiguration>(map.values()));
    assertEquals(repo1, configuration.findManagedRepositoryById("id1"));
    assertEquals(repo2, configuration.findManagedRepositoryById("id2"));
    assertNull(configuration.findManagedRepositoryById("id3"));
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.Test)

Example 38 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.

the class DefaultArchivaConfiguration method unescapeExpressions.

private Configuration unescapeExpressions(Configuration config) {
    // TODO: for commons-configuration 1.3 only
    for (ManagedRepositoryConfiguration c : config.getManagedRepositories()) {
        c.setLocation(removeExpressions(c.getLocation()));
        c.setRefreshCronExpression(unescapeCronExpression(c.getRefreshCronExpression()));
    }
    return config;
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)

Example 39 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration 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 40 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.

the class ArchivaConfigurationTest method testGetConfigurationFromDefaults.

@Test
public void testGetConfigurationFromDefaults() throws Exception {
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-defaults");
    Configuration configuration = archivaConfiguration.getConfiguration();
    assertConfiguration(configuration, 2, 1, 1);
    assertEquals("check network proxies", 0, configuration.getNetworkProxies().size());
    ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get(0);
    assertEquals("check managed repositories", "${appserver.base}/repositories/internal", repository.getLocation());
    assertEquals("check managed repositories", "Archiva Managed Internal Repository", repository.getName());
    assertEquals("check managed repositories", "internal", repository.getId());
    assertEquals("check managed repositories", "default", repository.getLayout());
    assertTrue("check managed repositories", repository.isScanned());
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.Test)

Aggregations

ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)72 Configuration (org.apache.archiva.configuration.model.Configuration)27 ManagedRepository (org.apache.archiva.repository.ManagedRepository)18 ContextConfiguration (org.springframework.test.context.ContextConfiguration)18 Path (java.nio.file.Path)17 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)14 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)14 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)14 Test (org.junit.Test)14 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)13 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)11 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)10 Test (org.junit.jupiter.api.Test)10 ArrayList (java.util.ArrayList)9 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)9 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)9 RepositoryException (org.apache.archiva.repository.RepositoryException)9 Before (org.junit.Before)8 IOException (java.io.IOException)7 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)7