Search in sources :

Example 11 with EditableRemoteRepository

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

the class DownloadRemoteIndexTaskTest method getRemoteRepository.

protected RemoteRepository getRemoteRepository(Path repoDirectory) throws IOException, URISyntaxException, UnsupportedURIException, RepositoryException {
    EditableRemoteRepository remoteRepository = repositoryProvider.createRemoteInstance("test-repo-re", "foo");
    Path indexDirectory = repoDirectory.resolve("index");
    Files.createDirectories(indexDirectory);
    remoteRepository.setLocation(new URI("http://localhost:" + port));
    repoDirectory.toFile().deleteOnExit();
    RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class);
    rif.setDownloadRemoteIndex(true);
    rif.setIndexUri(new URI("http://localhost:" + port + "/index-updates/"));
    createIndexingContext(remoteRepository);
    // icf.setLocalIndexPath( remoteRepository.getAsset(  "index" ) );
    return remoteRepository;
}
Also used : Path(java.nio.file.Path) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) URI(java.net.URI) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository)

Example 12 with EditableRemoteRepository

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

the class RemoteRepositoryHandler method put.

@Override
public RemoteRepository put(RemoteRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
    final String id = repositoryConfiguration.getId();
    final RepositoryType repositoryType = RepositoryType.valueOf(repositoryConfiguration.getType());
    final RepositoryProvider provider = getProvider(repositoryType);
    ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
    configLock.lock();
    RemoteRepository repo = null;
    RemoteRepository oldRepository = null;
    Configuration configuration = null;
    try {
        boolean updated = false;
        configuration = getConfigurationHandler().getBaseConfiguration();
        repo = getRepositories().get(id);
        oldRepository = repo == null ? null : clone(repo, id);
        if (repo == null) {
            repo = put(repositoryConfiguration, configuration);
        } else {
            setRepositoryDefaults(repositoryConfiguration);
            provider.updateRemoteInstance((EditableRemoteRepository) repo, repositoryConfiguration);
            updated = true;
            pushEvent(LifecycleEvent.UPDATED, repo);
        }
        registerNewRepository(repositoryConfiguration, repo, configuration, updated);
    } catch (IndeterminateConfigurationException | RegistryException e) {
        if (oldRepository != null) {
            RemoteRepositoryConfiguration oldCfg = provider.getRemoteConfiguration(oldRepository);
            provider.updateRemoteInstance((EditableRemoteRepository) repo, oldCfg);
            rollback(configuration, oldRepository, e, oldCfg);
        } else {
            getRepositories().remove(id);
        }
        log.error("Could not save the configuration for repository {}: {}", id, e.getMessage(), e);
        throw new RepositoryException("Could not save the configuration for repository " + id + ": " + e.getMessage());
    } finally {
        configLock.unlock();
    }
    return repo;
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryType(org.apache.archiva.repository.RepositoryType) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) RegistryException(org.apache.archiva.components.registry.RegistryException) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository)

Example 13 with EditableRemoteRepository

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

the class RemoteRepositoryHandler method put.

@Override
public RemoteRepository put(RemoteRepositoryConfiguration repositoryConfiguration, Configuration configuration) throws RepositoryException {
    final String id = repositoryConfiguration.getId();
    final RepositoryType repoType = RepositoryType.valueOf(repositoryConfiguration.getType());
    RemoteRepository repo;
    setRepositoryDefaults(repositoryConfiguration);
    if (getRepositories().containsKey(id)) {
        repo = clone(getRepositories().get(id), id);
        if (repo instanceof EditableRemoteRepository) {
            getProvider(repoType).updateRemoteInstance((EditableRemoteRepository) repo, repositoryConfiguration);
        } else {
            throw new RepositoryException("The repository is not editable " + id);
        }
    } else {
        repo = getProvider(repoType).createRemoteInstance(repositoryConfiguration);
        setLastState(repo, RepositoryState.CREATED);
    }
    if (configuration != null) {
        replaceOrAddRepositoryConfig(repositoryConfiguration, configuration);
    }
    updateReferences(repo, repositoryConfiguration);
    setLastState(repo, RepositoryState.REFERENCES_SET);
    return repo;
}
Also used : RepositoryType(org.apache.archiva.repository.RepositoryType) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository)

Example 14 with EditableRemoteRepository

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

the class RemoteRepositoryHandler method newInstance.

@Override
public RemoteRepository newInstance(RepositoryType type, String id) throws RepositoryException {
    log.debug("Creating repo {}", id);
    RepositoryProvider provider = getProvider(type);
    EditableRemoteRepository repo;
    repo = provider.createRemoteInstance(id, id);
    repo.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
    updateReferences(repo, null);
    repo.setLastState(RepositoryState.REFERENCES_SET);
    return repo;
}
Also used : RepositoryProvider(org.apache.archiva.repository.RepositoryProvider) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository)

Example 15 with EditableRemoteRepository

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

the class BasicRemoteRepositoryValidatorTest method applyWithExistingRepo.

@Test
void applyWithExistingRepo() 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.apply(repo);
    assertFalse(result.isValid());
    assertEquals(1, result.getResult().size());
    assertTrue(result.getResult().containsKey("id"));
    assertEquals("remote_repository", result.getResult().get("id").get(0).getCategory());
    assertEquals("remote_repo_exists", result.getResult().get("id").get(0).getType());
    assertEquals("id", result.getResult().get("id").get(0).getAttribute());
}
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