Search in sources :

Example 16 with RepositoryProvider

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

the class RemoteRepositoryHandler method put.

@Override
public RemoteRepository put(RemoteRepository repository) throws RepositoryException {
    final String id = repository.getId();
    RemoteRepository originRepo = getRepositories().remove(id);
    if (originRepo == null && repositoryHandlerManager.isRegisteredId(id)) {
        throw new RepositoryException("There exists a repository with id " + id + ". Could not update with managed repository.");
    }
    try {
        if (originRepo != null && repository != originRepo) {
            deactivateRepository(originRepo);
            pushEvent(LifecycleEvent.UNREGISTERED, originRepo);
        }
        RepositoryProvider provider = getProvider(repository.getType());
        RemoteRepositoryConfiguration newCfg = provider.getRemoteConfiguration(repository);
        getConfigurationHandler().getLock().writeLock().lock();
        try {
            Configuration configuration = getConfigurationHandler().getBaseConfiguration();
            updateReferences(repository, newCfg);
            RemoteRepositoryConfiguration oldCfg = configuration.findRemoteRepositoryById(id);
            if (oldCfg != null) {
                configuration.removeRemoteRepository(oldCfg);
            }
            configuration.addRemoteRepository(newCfg);
            getConfigurationHandler().save(configuration, ConfigurationHandler.REGISTRY_EVENT_TAG);
            setLastState(repository, RepositoryState.SAVED);
            activateRepository(repository);
        } finally {
            getConfigurationHandler().getLock().writeLock().unlock();
        }
        getRepositories().put(id, repository);
        setLastState(repository, RepositoryState.REGISTERED);
        return repository;
    } catch (Exception e) {
        // Rollback only partly, because repository is closed already
        if (originRepo != null) {
            getRepositories().put(id, originRepo);
        } else {
            getRepositories().remove(id);
        }
        log.error("Exception during configuration update {}", e.getMessage(), e);
        throw new RepositoryException("Could not save the configuration" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
    }
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) RegistryException(org.apache.archiva.components.registry.RegistryException) RepositoryException(org.apache.archiva.repository.RepositoryException) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException)

Example 17 with RepositoryProvider

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

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

the class RepositoryGroupHandler method newInstance.

@Override
public RepositoryGroup newInstance(final RepositoryType type, String id) throws RepositoryException {
    RepositoryProvider provider = getProvider(type);
    RepositoryGroupConfiguration config = new RepositoryGroupConfiguration();
    config.setId(id);
    return createNewRepositoryGroup(provider, config);
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

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