Search in sources :

Example 1 with RepositoryGroup

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

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

the class RepositoryGroupHandler method initializeFromConfig.

@Override
public void initializeFromConfig() {
    getRepositories().clear();
    getRepositories().putAll(newInstancesFromConfig());
    for (RepositoryGroup group : getRepositories().values()) {
        activateRepository(group);
    }
}
Also used : EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup)

Example 3 with RepositoryGroup

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

the class RepositoryGroupHandler method newInstancesFromConfig.

@Override
public Map<String, RepositoryGroup> newInstancesFromConfig() {
    try {
        List<RepositoryGroupConfiguration> repositoryGroupConfigurations = this.getConfigurationHandler().getBaseConfiguration().getRepositoryGroups();
        if (repositoryGroupConfigurations == null) {
            return Collections.emptyMap();
        }
        Map<String, RepositoryGroup> repositoryGroupMap = new LinkedHashMap<>(repositoryGroupConfigurations.size());
        for (RepositoryGroupConfiguration repoConfig : repositoryGroupConfigurations) {
            RepositoryType repositoryType = RepositoryType.valueOf(repoConfig.getType());
            if (super.providerMap.containsKey(repositoryType)) {
                try {
                    RepositoryGroup repo = createNewRepositoryGroup(providerMap.get(repositoryType), repoConfig);
                    repositoryGroupMap.put(repo.getId(), repo);
                } catch (Exception e) {
                    log.error("Could not create repository group {}: {}", repoConfig.getId(), e.getMessage(), e);
                }
            }
        }
        return repositoryGroupMap;
    } catch (Throwable e) {
        log.error("Could not initialize repositories from config: {}", e.getMessage(), e);
        return Collections.emptyMap();
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) RepositoryType(org.apache.archiva.repository.RepositoryType) RegistryException(org.apache.archiva.components.registry.RegistryException) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with RepositoryGroup

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

the class RepositoryGroupHandler method clone.

@Override
public RepositoryGroup clone(RepositoryGroup repo, String newId) throws RepositoryException {
    RepositoryProvider provider = getProvider(repo.getType());
    RepositoryGroupConfiguration cfg = provider.getRepositoryGroupConfiguration(repo);
    cfg.setId(newId);
    RepositoryGroup cloned = provider.createRepositoryGroup(cfg);
    cloned.registerEventHandler(RepositoryEvent.ANY, repositoryRegistry);
    setLastState(cloned, RepositoryState.CREATED);
    return cloned;
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Example 5 with RepositoryGroup

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

the class RepositoryGroupHandlerTest method put.

@Test
void put() throws IOException, RepositoryException {
    final String id = "test-group-04";
    try {
        RepositoryGroupHandler groupHandler = createHandler();
        EditableRepositoryGroup repositoryGroup = createRepository(id, "n-" + id);
        groupHandler.put(repositoryGroup);
        RepositoryGroup storedGroup = groupHandler.get(id);
        assertNotNull(storedGroup);
        assertEquals(id, storedGroup.getId());
        assertEquals("n-" + id, storedGroup.getName());
        EditableRepositoryGroup repositoryGroup2 = createRepository(id, "n2-" + id);
        groupHandler.put(repositoryGroup2);
        storedGroup = groupHandler.get(id);
        assertNotNull(storedGroup);
        assertEquals(id, storedGroup.getId());
        assertEquals("n2-" + id, storedGroup.getName());
        assertTrue(hasGroupInConfig(id));
    } finally {
        removeGroupFromConfig(id);
    }
}
Also used : EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) Test(org.junit.jupiter.api.Test)

Aggregations

RepositoryGroup (org.apache.archiva.repository.RepositoryGroup)25 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)23 Test (org.junit.jupiter.api.Test)15 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)8 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 RepositoryException (org.apache.archiva.repository.RepositoryException)5 ValidationError (org.apache.archiva.repository.validation.ValidationError)5 IOException (java.io.IOException)4 RepositoryType (org.apache.archiva.repository.RepositoryType)4 Path (java.nio.file.Path)3 RegistryException (org.apache.archiva.components.registry.RegistryException)3 Configuration (org.apache.archiva.configuration.model.Configuration)3 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)3 IndeterminateConfigurationException (org.apache.archiva.configuration.provider.IndeterminateConfigurationException)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 List (java.util.List)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 Inject (javax.inject.Inject)2 Named (javax.inject.Named)2