Search in sources :

Example 11 with RemoteRepositoryConfiguration

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

the class RemoteRepositoryHandler method newOrUpdateInstancesFromConfig.

public Map<String, RemoteRepository> newOrUpdateInstancesFromConfig(Map<String, RemoteRepository> currentInstances) {
    try {
        List<RemoteRepositoryConfiguration> remoteRepoConfigs = new ArrayList<>(getConfigurationHandler().getBaseConfiguration().getRemoteRepositories());
        if (remoteRepoConfigs == null) {
            return Collections.emptyMap();
        }
        Map<String, RemoteRepository> result = new HashMap<>();
        for (RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs) {
            String id = repoConfig.getId();
            if (result.containsKey(id)) {
                log.error("There are repositories with the same id in the configuration: {}", id);
                continue;
            }
            RemoteRepository repo;
            if (currentInstances.containsKey(id)) {
                repo = currentInstances.remove(id);
                getProvider(repo.getType()).updateRemoteInstance((EditableRemoteRepository) repo, repoConfig);
                updateReferences(repo, repoConfig);
            } else {
                repo = newInstance(repoConfig);
            }
            result.put(id, repo);
        }
        return result;
    } catch (Throwable e) {
        log.error("Could not initialize repositories from config: {}", e.getMessage(), e);
        return new HashMap<>();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository)

Example 12 with RemoteRepositoryConfiguration

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;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.base.PasswordCredentials) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature)

Example 13 with RemoteRepositoryConfiguration

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

the class ArchivaConfigurationTest method testGetConfigurationFixEmptyRemoteRepoUsernamePassword.

/**
 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
 */
@Test
public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword() throws Exception {
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-configuration");
    Configuration configuration = archivaConfiguration.getConfiguration();
    assertConfiguration(configuration, 2, 2, 2);
    assertEquals("check remote repositories", 2, configuration.getRemoteRepositories().size());
    RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get("maven2-repository.dev.java.net");
    assertEquals("remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository", repository.getUrl());
    assertEquals("remote repository.name", "Java.net Repository for Maven 2", repository.getName());
    assertEquals("remote repository.id", "maven2-repository.dev.java.net", repository.getId());
    assertEquals("remote repository.layout", "default", repository.getLayout());
    assertNull("remote repository.username == null", repository.getUsername());
    assertNull("remote repository.password == null", repository.getPassword());
}
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) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) Test(org.junit.Test)

Example 14 with RemoteRepositoryConfiguration

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

the class ArchivaConfigurationTest method testRemoveLastElements.

@Test
public void testRemoveLastElements() throws Exception {
    Path baseFile = getTestFile("target/test/test-file.xml");
    Files.deleteIfExists(baseFile);
    assertFalse(Files.exists(baseFile));
    Path userFile = getTestFile("target/test/test-file-user.xml");
    Files.deleteIfExists(userFile);
    assertFalse(Files.exists(userFile));
    Files.createDirectories(baseFile.getParent());
    FileUtils.copyFile(getTestFile("src/test/conf/conf-single-list-elements.xml").toFile(), baseFile.toFile());
    Files.createDirectories(userFile.getParent());
    FileUtils.writeStringToFile(userFile.toFile(), "<configuration/>", Charset.forName("UTF-8"));
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-remove-central");
    archivaConfiguration.reload();
    Configuration configuration = archivaConfiguration.getConfiguration();
    RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get(0);
    assertNotNull(repositoryGroup);
    configuration.removeRepositoryGroup(repositoryGroup);
    assertTrue(configuration.getRepositoryGroups().isEmpty());
    RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get("central");
    assertNotNull(repository);
    configuration.removeRemoteRepository(repository);
    assertTrue(configuration.getRemoteRepositories().isEmpty());
    ManagedRepositoryConfiguration managedRepository = configuration.getManagedRepositoriesAsMap().get("snapshots");
    assertNotNull(managedRepository);
    configuration.removeManagedRepository(managedRepository);
    assertTrue(configuration.getManagedRepositories().isEmpty());
    ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get(0);
    assertNotNull(proxyConnector);
    configuration.removeProxyConnector(proxyConnector);
    assertTrue(configuration.getProxyConnectors().isEmpty());
    NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get("proxy");
    assertNotNull(networkProxy);
    configuration.removeNetworkProxy(networkProxy);
    assertTrue(configuration.getNetworkProxies().isEmpty());
    LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get(0);
    assertNotNull(path);
    configuration.removeLegacyArtifactPath(path);
    assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
    RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
    String consumer = scanning.getKnownContentConsumers().get(0);
    assertNotNull(consumer);
    scanning.removeKnownContentConsumer(consumer);
    // default values
    assertFalse(scanning.getKnownContentConsumers().isEmpty());
    consumer = scanning.getInvalidContentConsumers().get(0);
    assertNotNull(consumer);
    scanning.removeInvalidContentConsumer(consumer);
    assertTrue(scanning.getInvalidContentConsumers().isEmpty());
    archivaConfiguration.save(configuration);
    archivaConfiguration = lookup(ArchivaConfiguration.class, "test-read-saved");
    configuration = archivaConfiguration.getConfiguration();
    assertNull(configuration.getRemoteRepositoriesAsMap().get("central"));
    assertTrue(configuration.getRepositoryGroups().isEmpty());
    assertNull(configuration.getManagedRepositoriesAsMap().get("snapshots"));
    assertTrue(configuration.getProxyConnectors().isEmpty());
    assertNull(configuration.getNetworkProxiesAsMap().get("proxy"));
    assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
    scanning = configuration.getRepositoryScanning();
    assertFalse(scanning.getKnownContentConsumers().isEmpty());
    assertTrue(scanning.getInvalidContentConsumers().isEmpty());
}
Also used : Path(java.nio.file.Path) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) 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) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Test(org.junit.Test)

Example 15 with RemoteRepositoryConfiguration

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

the class RepositoryProviderMock method getRemoteConfiguration.

@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) {
    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;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.base.PasswordCredentials) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature)

Aggregations

RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)46 Configuration (org.apache.archiva.configuration.model.Configuration)17 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)14 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)14 RemoteRepository (org.apache.archiva.repository.RemoteRepository)12 ContextConfiguration (org.springframework.test.context.ContextConfiguration)11 ArrayList (java.util.ArrayList)9 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)9 EditableRemoteRepository (org.apache.archiva.repository.EditableRemoteRepository)9 RepositoryException (org.apache.archiva.repository.RepositoryException)8 Test (org.junit.Test)8 Path (java.nio.file.Path)7 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)7 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)7 Test (org.junit.jupiter.api.Test)7 HashMap (java.util.HashMap)6 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)6 PasswordCredentials (org.apache.archiva.repository.base.PasswordCredentials)6 Iterator (java.util.Iterator)5 List (java.util.List)5