Search in sources :

Example 6 with Configuration

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

the class RepositoryServletTest method testGetRepositoryAfterAdd.

@Test
public void testGetRepositoryAfterAdd() throws Exception {
    RepositoryServlet servlet = RepositoryServlet.class.cast(findServlet("repository"));
    assertNotNull(servlet);
    ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
    Configuration c = archivaConfiguration.getConfiguration();
    ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
    repo.setId(NEW_REPOSITORY_ID);
    repo.setName(NEW_REPOSITORY_NAME);
    Path repoRoot = Paths.get("target/test-repository-root");
    if (!Files.exists(repoRoot)) {
        Files.createDirectories(repoRoot);
    }
    repo.setLocation(repoRoot.toAbsolutePath().toString());
    c.addManagedRepository(repo);
    saveConfiguration(archivaConfiguration);
    ManagedRepository repository = servlet.getRepository(NEW_REPOSITORY_ID);
    assertNotNull(repository);
    assertEquals(NEW_REPOSITORY_NAME, repository.getName());
    // check other is still intact
    assertRepositoryValid(servlet, REPOID_INTERNAL);
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.repository.ManagedRepository) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) Test(org.junit.Test)

Example 7 with Configuration

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

the class RepositoryGroupHandler method put.

/**
 * Adds a new repository group to the current list, or replaces the repository group definition with
 * the same id, if it exists already.
 * The change is saved to the configuration immediately.
 *
 * @param repositoryGroup the new repository group.
 * @throws RepositoryException if the new repository group could not be saved to the configuration.
 */
@Override
public RepositoryGroup put(final RepositoryGroup repositoryGroup) throws RepositoryException {
    final String id = repositoryGroup.getId();
    RepositoryGroup originRepoGroup = getRepositories().remove(id);
    try {
        if (originRepoGroup != null && originRepoGroup != repositoryGroup) {
            deactivateRepository(originRepoGroup);
            pushEvent(new LifecycleEvent(LifecycleEvent.UNREGISTERED, this, originRepoGroup));
        }
        RepositoryProvider provider = getProvider(repositoryGroup.getType());
        RepositoryGroupConfiguration newCfg = provider.getRepositoryGroupConfiguration(repositoryGroup);
        ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
        configLock.lock();
        try {
            Configuration configuration = this.getConfigurationHandler().getBaseConfiguration();
            updateReferences(repositoryGroup, newCfg);
            RepositoryGroupConfiguration oldCfg = configuration.findRepositoryGroupById(id);
            if (oldCfg != null) {
                configuration.removeRepositoryGroup(oldCfg);
            }
            configuration.addRepositoryGroup(newCfg);
            getConfigurationHandler().save(configuration, ConfigurationHandler.REGISTRY_EVENT_TAG);
            setLastState(repositoryGroup, RepositoryState.SAVED);
            activateRepository(repositoryGroup);
        } finally {
            configLock.unlock();
        }
        getRepositories().put(id, repositoryGroup);
        setLastState(repositoryGroup, RepositoryState.REGISTERED);
        return repositoryGroup;
    } catch (Exception e) {
        // Rollback
        if (originRepoGroup != null) {
            getRepositories().put(id, originRepoGroup);
        } 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()), e);
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) LifecycleEvent(org.apache.archiva.repository.event.LifecycleEvent) RepositoryException(org.apache.archiva.repository.RepositoryException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider) RegistryException(org.apache.archiva.components.registry.RegistryException) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException)

Example 8 with Configuration

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

the class ManagedRepositoryHandler method put.

@Override
public ManagedRepository put(ManagedRepository repository) throws RepositoryException {
    final String id = repository.getId();
    ManagedRepository 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());
        ManagedRepositoryConfiguration newCfg = provider.getManagedConfiguration(repository);
        getConfigurationHandler().getLock().writeLock().lock();
        try {
            Configuration configuration = getConfigurationHandler().getBaseConfiguration();
            updateReferences(repository, newCfg);
            ManagedRepositoryConfiguration oldCfg = configuration.findManagedRepositoryById(id);
            if (oldCfg != null) {
                configuration.removeManagedRepository(oldCfg);
            }
            configuration.addManagedRepository(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 : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) 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) IOException(java.io.IOException) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException)

Example 9 with Configuration

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

the class ManagedRepositoryHandler method put.

@Override
public ManagedRepository put(ManagedRepositoryConfiguration 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();
    ManagedRepository repo = null;
    ManagedRepository 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.updateManagedInstance((EditableManagedRepository) repo, repositoryConfiguration);
            updated = true;
            pushEvent(LifecycleEvent.UPDATED, repo);
        }
        registerNewRepository(repositoryConfiguration, repo, configuration, updated);
    } catch (IndeterminateConfigurationException | RegistryException e) {
        if (oldRepository != null) {
            ManagedRepositoryConfiguration oldCfg = provider.getManagedConfiguration(oldRepository);
            provider.updateManagedInstance((EditableManagedRepository) 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 : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryType(org.apache.archiva.repository.RepositoryType) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RepositoryException(org.apache.archiva.repository.RepositoryException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) RegistryException(org.apache.archiva.components.registry.RegistryException) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Example 10 with Configuration

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

the class ManagedRepositoryHandler method updateReferences.

@Override
public void updateReferences(ManagedRepository repo, ManagedRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
    log.debug("Updating references of repo {}", repo.getId());
    if (repo.supportsFeature(StagingRepositoryFeature.class)) {
        Configuration configuration = getConfigurationHandler().getBaseConfiguration();
        RepositoryProvider provider = getProvider(repo.getType());
        StagingRepositoryFeature feature = repo.getFeature(StagingRepositoryFeature.class);
        if (feature.isStageRepoNeeded() && feature.getStagingRepository() == null) {
            ManagedRepository stageRepo = get(getStagingId(repo.getId()));
            if (stageRepo == null) {
                stageRepo = getStagingRepository(repo);
                getRepositories().put(stageRepo.getId(), stageRepo);
                if (configuration != null) {
                    replaceOrAddRepositoryConfig(provider.getManagedConfiguration(stageRepo), configuration);
                }
                pushEvent(new LifecycleEvent(LifecycleEvent.REGISTERED, this, stageRepo));
            }
            feature.setStagingRepository(stageRepo);
        }
    }
    if (repo instanceof EditableManagedRepository) {
        EditableManagedRepository editableRepo = (EditableManagedRepository) repo;
        if (repo.getContent() == null) {
            editableRepo.setContent(repositoryContentFactory.getManagedRepositoryContent(repo));
            editableRepo.getContent().setRepository(editableRepo);
        }
        log.debug("Index repo: " + repo.hasIndex());
        if (repo.hasIndex() && (repo.getIndexingContext() == null || !repo.getIndexingContext().isOpen())) {
            log.debug("Creating indexing context for {}", repo.getId());
            createIndexingContext(editableRepo);
        }
    }
    repo.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) LifecycleEvent(org.apache.archiva.repository.event.LifecycleEvent) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Aggregations

Configuration (org.apache.archiva.configuration.model.Configuration)94 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)56 ContextConfiguration (org.springframework.test.context.ContextConfiguration)45 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)42 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)34 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)34 WebappConfiguration (org.apache.archiva.configuration.model.WebappConfiguration)32 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)29 Path (java.nio.file.Path)27 Test (org.junit.Test)26 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)23 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)23 RepositoryException (org.apache.archiva.repository.RepositoryException)22 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)14 ManagedRepository (org.apache.archiva.repository.ManagedRepository)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 RemoteRepository (org.apache.archiva.repository.RemoteRepository)12 Test (org.junit.jupiter.api.Test)12 LegacyArtifactPath (org.apache.archiva.configuration.model.LegacyArtifactPath)11