Search in sources :

Example 1 with EditableRemoteRepository

use of org.apache.archiva.repository.EditableRemoteRepository 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 2 with EditableRemoteRepository

use of org.apache.archiva.repository.EditableRemoteRepository in project archiva by apache.

the class RemoteRepositoryHandler method updateReferences.

@Override
public void updateReferences(RemoteRepository repo, RemoteRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
    if (repo instanceof EditableRemoteRepository && repo.getContent() == null) {
        EditableRemoteRepository editableRepo = (EditableRemoteRepository) repo;
        editableRepo.setContent(repositoryContentFactory.getRemoteRepositoryContent(repo));
        if (repo.supportsFeature(IndexCreationFeature.class) && repo.getIndexingContext() == null) {
            createIndexingContext(editableRepo);
        }
    }
    repo.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository)

Example 3 with EditableRemoteRepository

use of org.apache.archiva.repository.EditableRemoteRepository in project archiva by apache.

the class BasicRemoteRepositoryValidatorTest method apply.

@Test
void apply() throws IOException {
    BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator(configurationHandler);
    validator.setRepositoryRegistry(repositoryRegistry);
    Path repoDir = getRepoBaseDir().resolve("test");
    EditableRemoteRepository repo = createRepository("test", "test", repoDir);
    ValidationResponse<RemoteRepository> result = validator.apply(repo);
    assertTrue(result.isValid());
}
Also used : Path(java.nio.file.Path) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) Test(org.junit.jupiter.api.Test)

Example 4 with EditableRemoteRepository

use of org.apache.archiva.repository.EditableRemoteRepository in project archiva by apache.

the class BasicRemoteRepositoryValidatorTest method applyUpdateWithExistingRepo.

@Test
void applyUpdateWithExistingRepo() throws IOException, RepositoryException {
    BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator(configurationHandler);
    validator.setRepositoryRegistry(repositoryRegistry);
    Path repoDir = getRepoBaseDir().resolve("test");
    EditableRemoteRepository repo = createRepository("test", "test", repoDir);
    Path repoDir2 = getRepoBaseDir().resolve("test2");
    EditableRemoteRepository repo2 = createRepository("test", "test", repoDir2);
    repositoryRegistry.putRepository(repo);
    ValidationResponse<RemoteRepository> result = validator.applyForUpdate(repo);
    assertTrue(result.isValid());
    assertEquals(0, result.getResult().size());
}
Also used : Path(java.nio.file.Path) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) Test(org.junit.jupiter.api.Test)

Example 5 with EditableRemoteRepository

use of org.apache.archiva.repository.EditableRemoteRepository in project archiva by apache.

the class BasicRemoteRepositoryValidatorTest method applyWithBadSchedulingExpression.

@Test
void applyWithBadSchedulingExpression() throws IOException {
    BasicRemoteRepositoryValidator validator = new BasicRemoteRepositoryValidator(configurationHandler);
    validator.setRepositoryRegistry(repositoryRegistry);
    Path repoDir = getRepoBaseDir().resolve("test");
    EditableRemoteRepository repo = createRepository("test", "test", repoDir);
    repo.setSchedulingDefinition("xxxxx");
    ValidationResponse<RemoteRepository> result = validator.apply(repo);
    assertFalse(result.isValid());
    assertEquals(1, result.getResult().size());
    assertEquals("invalid_scheduling_exp", result.getResult().get("scheduling_definition").get(0).getType());
}
Also used : Path(java.nio.file.Path) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) Test(org.junit.jupiter.api.Test)

Aggregations

EditableRemoteRepository (org.apache.archiva.repository.EditableRemoteRepository)17 RemoteRepository (org.apache.archiva.repository.RemoteRepository)13 Test (org.junit.jupiter.api.Test)11 Path (java.nio.file.Path)7 Map (java.util.Map)3 ValidationError (org.apache.archiva.repository.validation.ValidationError)3 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)2 RepositoryException (org.apache.archiva.repository.RepositoryException)2 RepositoryProvider (org.apache.archiva.repository.RepositoryProvider)2 RepositoryType (org.apache.archiva.repository.RepositoryType)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 RegistryException (org.apache.archiva.components.registry.RegistryException)1 Configuration (org.apache.archiva.configuration.model.Configuration)1 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)1 IndeterminateConfigurationException (org.apache.archiva.configuration.provider.IndeterminateConfigurationException)1 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)1 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)1