Search in sources :

Example 26 with RemoteRepositoryConfiguration

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

the class DefaultArchivaConfiguration method updateCheckPathDefaults.

/*
     * Updates the checkpath list for repositories.
     *
     * We are replacing existing ones and adding new ones. This allows to update the list with new releases.
     *
     * We are also updating existing remote repositories, if they exist already.
     *
     * This update method should only be called, if the config version changes to avoid overwriting
     * user repository settings all the time.
     */
private void updateCheckPathDefaults(Configuration config, Registry defaultConfiguration) {
    List<RepositoryCheckPath> existingCheckPathList = config.getArchivaDefaultConfiguration().getDefaultCheckPaths();
    HashMap<String, RepositoryCheckPath> existingCheckPaths = new HashMap<>();
    HashMap<String, RepositoryCheckPath> newCheckPaths = new HashMap<>();
    for (RepositoryCheckPath path : config.getArchivaDefaultConfiguration().getDefaultCheckPaths()) {
        existingCheckPaths.put(path.getUrl(), path);
    }
    List defaultCheckPathsSubsets = defaultConfiguration.getSubsetList("archivaDefaultConfiguration.defaultCheckPaths.defaultCheckPath");
    for (Iterator i = defaultCheckPathsSubsets.iterator(); i.hasNext(); ) {
        RepositoryCheckPath v = readRepositoryCheckPath((Registry) i.next());
        if (existingCheckPaths.containsKey(v.getUrl())) {
            existingCheckPathList.remove(existingCheckPaths.get(v.getUrl()));
        }
        existingCheckPathList.add(v);
        newCheckPaths.put(v.getUrl(), v);
    }
    // Remote repositories update
    for (RemoteRepositoryConfiguration remoteRepositoryConfiguration : config.getRemoteRepositories()) {
        String url = remoteRepositoryConfiguration.getUrl().toLowerCase();
        if (newCheckPaths.containsKey(url)) {
            String currentPath = remoteRepositoryConfiguration.getCheckPath();
            String newPath = newCheckPaths.get(url).getPath();
            log.info("Updating connection check path for repository {}, from '{}' to '{}'.", remoteRepositoryConfiguration.getId(), currentPath, newPath);
            remoteRepositoryConfiguration.setCheckPath(newPath);
        }
    }
}
Also used : RepositoryCheckPath(org.apache.archiva.configuration.model.RepositoryCheckPath) HashMap(java.util.HashMap) Iterator(java.util.Iterator) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ArrayList(java.util.ArrayList) List(java.util.List)

Example 27 with RemoteRepositoryConfiguration

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

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

the class RemoteRepositoryHandlerTest method remove.

@Test
void remove() throws RepositoryException {
    final String id = "test-repo-08";
    RemoteRepositoryHandler repoHandler = createHandler();
    RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
    configuration.setId(id);
    configuration.setName("n-" + id);
    repoHandler.put(configuration);
    assertTrue(hasRepositoryInConfig(id));
    assertNotNull(repoHandler.get(id));
    repoHandler.remove(id);
    assertNull(repoHandler.get(id));
    assertFalse(hasRepositoryInConfig(id));
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) Test(org.junit.jupiter.api.Test)

Example 29 with RemoteRepositoryConfiguration

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

the class RemoteRepositoryHandlerTest method testPutWithoutRegister.

@Test
void testPutWithoutRegister() throws RepositoryException {
    final String id = "test-repo-06";
    RemoteRepositoryHandler repoHandler = createHandler();
    Configuration aCfg = new Configuration();
    RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
    configuration.setId(id);
    configuration.setName("n-" + id);
    repoHandler.put(configuration, aCfg);
    RemoteRepository repo = repoHandler.get(id);
    assertNull(repo);
    assertFalse(hasRepositoryInConfig(id));
    assertTrue(aCfg.getRemoteRepositories().stream().anyMatch(g -> g != null && id.equals(g.getId())));
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) CheckedResult(org.apache.archiva.repository.validation.CheckedResult) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) ArchivaRepositoryRegistry(org.apache.archiva.repository.base.ArchivaRepositoryRegistry) Inject(javax.inject.Inject) Repository(org.apache.archiva.repository.Repository) RepositoryContentFactory(org.apache.archiva.repository.RepositoryContentFactory) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ISEMPTY(org.apache.archiva.repository.validation.ErrorKeys.ISEMPTY) IndexManagerFactory(org.apache.archiva.indexer.IndexManagerFactory) Map(java.util.Map) FileUtils(org.apache.archiva.common.utils.FileUtils) Named(javax.inject.Named) ConfigurationHandler(org.apache.archiva.repository.base.ConfigurationHandler) ValidationError(org.apache.archiva.repository.validation.ValidationError) Path(java.nio.file.Path) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryValidator(org.apache.archiva.repository.validation.RepositoryValidator) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) Iterator(java.util.Iterator) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Files(java.nio.file.Files) FileLockManager(org.apache.archiva.common.filelock.FileLockManager) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) RepositoryType(org.apache.archiva.repository.RepositoryType) Test(org.junit.jupiter.api.Test) List(java.util.List) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Assertions(org.junit.jupiter.api.Assertions) RepositoryState(org.apache.archiva.repository.RepositoryState) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) Test(org.junit.jupiter.api.Test)

Example 30 with RemoteRepositoryConfiguration

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

the class RemoteRepositoryHandlerTest method putWithCheck_invalid.

@Test
void putWithCheck_invalid() throws RepositoryException {
    final String id = "test-repo-07";
    final String name = "n-" + id;
    try {
        RemoteRepositoryHandler repoHandler = createHandler();
        BasicRemoteRepositoryValidator checker = new BasicRemoteRepositoryValidator(configurationHandler);
        checker.setRepositoryRegistry(repositoryRegistry);
        RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
        configuration.setId("");
        configuration.setName(name);
        CheckedResult<RemoteRepository, Map<String, List<ValidationError>>> result = repoHandler.putWithCheck(configuration, checker);
        assertNull(repoHandler.get(id));
        assertNotNull(result.getResult());
        assertNotNull(result.getResult().get("id"));
        assertEquals(2, result.getResult().get("id").size());
        assertEquals(ISEMPTY, result.getResult().get("id").get(0).getType());
        assertFalse(hasRepositoryInConfig(id));
        assertFalse(hasRepositoryInConfig(""));
    } finally {
        removeRepositoryFromConfig(id);
    }
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

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