Search in sources :

Example 11 with RepositoryProvider

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

the class ManagedRepositoryHandler method newInstance.

@Override
public ManagedRepository newInstance(RepositoryType type, String id) throws RepositoryException {
    log.debug("Creating repo {}", id);
    RepositoryProvider provider = getProvider(type);
    EditableManagedRepository repo;
    try {
        repo = provider.createManagedInstance(id, id);
    } catch (IOException e) {
        throw new RepositoryException("Could not create repository '" + id + "': " + e.getMessage());
    }
    repo.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
    updateReferences(repo, null);
    repo.setLastState(RepositoryState.REFERENCES_SET);
    return repo;
}
Also used : EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Example 12 with RepositoryProvider

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

the class ManagedRepositoryHandler method getStagingRepository.

private ManagedRepository getStagingRepository(ManagedRepository baseRepo) throws RepositoryException {
    ManagedRepository stageRepo = get(getStagingId(baseRepo.getId()));
    final RepositoryType type = baseRepo.getType();
    if (stageRepo == null) {
        RepositoryProvider provider = getProvider(type);
        ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration(baseRepo);
        stageRepo = provider.createStagingInstance(cfg);
        if (stageRepo.supportsFeature(StagingRepositoryFeature.class)) {
            stageRepo.getFeature(StagingRepositoryFeature.class).setStageRepoNeeded(false);
        }
        updateReferences(stageRepo, cfg);
    }
    return stageRepo;
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryType(org.apache.archiva.repository.RepositoryType) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Example 13 with RepositoryProvider

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

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

the class RemoteRepositoryHandler method clone.

@Override
public RemoteRepository clone(RemoteRepository repo, String newId) throws RepositoryException {
    RepositoryProvider provider = getProvider(repo.getType());
    RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration(repo);
    cfg.setId(newId);
    RemoteRepository cloned = provider.createRemoteInstance(cfg);
    cloned.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
    setLastState(cloned, RepositoryState.CREATED);
    return cloned;
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Example 15 with RepositoryProvider

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

the class RemoteRepositoryHandler method newInstance.

@Override
public RemoteRepository newInstance(RemoteRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
    RepositoryType type = RepositoryType.valueOf(repositoryConfiguration.getType());
    RepositoryProvider provider = getProvider(type);
    if (provider == null) {
        throw new RepositoryException("Provider not found for repository type: " + repositoryConfiguration.getType());
    }
    final RemoteRepository repo = provider.createRemoteInstance(repositoryConfiguration);
    repo.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
    updateReferences(repo, null);
    if (repo instanceof EditableRepository) {
        ((EditableRepository) repo).setLastState(RepositoryState.REFERENCES_SET);
    }
    return repo;
}
Also used : RepositoryType(org.apache.archiva.repository.RepositoryType) RepositoryException(org.apache.archiva.repository.RepositoryException) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider) EditableRepository(org.apache.archiva.repository.EditableRepository)

Aggregations

RepositoryProvider (org.apache.archiva.repository.RepositoryProvider)18 RepositoryException (org.apache.archiva.repository.RepositoryException)9 Configuration (org.apache.archiva.configuration.model.Configuration)7 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)7 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)7 RepositoryType (org.apache.archiva.repository.RepositoryType)7 RegistryException (org.apache.archiva.components.registry.RegistryException)6 IndeterminateConfigurationException (org.apache.archiva.configuration.provider.IndeterminateConfigurationException)6 ManagedRepository (org.apache.archiva.repository.ManagedRepository)6 EditableRemoteRepository (org.apache.archiva.repository.EditableRemoteRepository)5 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)4 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)4 RemoteRepository (org.apache.archiva.repository.RemoteRepository)4 IOException (java.io.IOException)3 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)3 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)3 RepositoryGroup (org.apache.archiva.repository.RepositoryGroup)3 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)2 IndexCreationFailedException (org.apache.archiva.indexer.IndexCreationFailedException)2 EditableRepository (org.apache.archiva.repository.EditableRepository)2