Search in sources :

Example 1 with RepositoryGroupConfiguration

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

the class ArchivaDavResourceFactoryTest method testRepositoryGroupLastRepositoryRequiresAuthentication.

@Test
public void testRepositoryGroupLastRepositoryRequiresAuthentication() throws Exception {
    DavResourceLocator locator = new ArchivaDavResourceLocator("", "/repository/" + LOCAL_REPO_GROUP + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP, new ArchivaDavLocatorFactory());
    List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
    RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
    repoGroup.setId(LOCAL_REPO_GROUP);
    repoGroup.addRepository(INTERNAL_REPO);
    repoGroup.addRepository(RELEASES_REPO);
    repoGroups.add(repoGroup);
    config.setRepositoryGroups(repoGroups);
    ManagedRepositoryContent internalRepo = createManagedRepositoryContent(INTERNAL_REPO);
    ManagedRepositoryContent releasesRepo = createManagedRepositoryContent(RELEASES_REPO);
    try {
        reset(archivaConfiguration);
        reset(request);
        reset(repoFactory);
        when(archivaConfiguration.getConfiguration()).thenReturn(config);
        when(request.getMethod()).thenReturn("GET");
        when(request.getPathInfo()).thenReturn("org/apache/archiva");
        when(repoFactory.getManagedRepositoryContent(INTERNAL_REPO)).thenReturn(internalRepo);
        when(repoFactory.getManagedRepositoryContent(RELEASES_REPO)).thenReturn(releasesRepo);
        when(request.getRemoteAddr()).thenReturn("http://localhost:8080");
        when(request.getDavSession()).thenReturn(new ArchivaDavSession());
        when(request.getContextPath()).thenReturn("");
        when(repoRequest.isSupportFile("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).thenReturn(false);
        when(repoRequest.getLayout("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).thenReturn("legacy");
        when(repoRequest.toItemSelector("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).thenReturn(null);
        when(repoRequest.toNativePath("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).thenReturn(Paths.get(config.findManagedRepositoryById(INTERNAL_REPO).getLocation(), "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar").toString());
        when(repoRequest.isArchetypeCatalog("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).thenReturn(false);
        resourceFactory.createResource(locator, request, response);
        verify(archivaConfiguration, times(3)).getConfiguration();
        verify(request, times(3)).getMethod();
        verify(request, atMost(2)).getPathInfo();
        verify(request, times(2)).getRemoteAddr();
        verify(request, times(2)).getDavSession();
        verify(request, times(2)).getContextPath();
        fail("A DavException with 401 error code should have been thrown.");
    } catch (DavException e) {
        assertEquals(401, e.getErrorCode());
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) DavException(org.apache.jackrabbit.webdav.DavException) ArrayList(java.util.ArrayList) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator) Test(org.junit.Test)

Example 2 with RepositoryGroupConfiguration

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

the class MavenRepositoryProvider method getRepositoryGroupConfiguration.

@Override
public RepositoryGroupConfiguration getRepositoryGroupConfiguration(RepositoryGroup repositoryGroup) throws RepositoryException {
    if (repositoryGroup.getType() != RepositoryType.MAVEN) {
        throw new RepositoryException("The given repository group is not of MAVEN type");
    }
    RepositoryGroupConfiguration cfg = new RepositoryGroupConfiguration();
    cfg.setId(repositoryGroup.getId());
    cfg.setName(repositoryGroup.getName());
    if (repositoryGroup.supportsFeature(IndexCreationFeature.class)) {
        IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature(IndexCreationFeature.class);
        cfg.setMergedIndexPath(indexCreationFeature.getIndexPath().toString());
    }
    cfg.setMergedIndexTtl(repositoryGroup.getMergedIndexTTL());
    cfg.setRepositories(repositoryGroup.getRepositories().stream().map(Repository::getId).collect(Collectors.toList()));
    cfg.setCronExpression(repositoryGroup.getSchedulingDefinition());
    return cfg;
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) EditableRepository(org.apache.archiva.repository.EditableRepository) BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) Repository(org.apache.archiva.repository.Repository) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 3 with RepositoryGroupConfiguration

use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration 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 4 with RepositoryGroupConfiguration

use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration 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 5 with RepositoryGroupConfiguration

use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration 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)

Aggregations

RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)28 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)11 RepositoryException (org.apache.archiva.repository.RepositoryException)10 Configuration (org.apache.archiva.configuration.model.Configuration)9 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)9 RepositoryGroup (org.apache.archiva.repository.RepositoryGroup)9 ArrayList (java.util.ArrayList)8 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)7 Map (java.util.Map)5 ValidationError (org.apache.archiva.repository.validation.ValidationError)5 Test (org.junit.Test)5 Test (org.junit.jupiter.api.Test)5 ContextConfiguration (org.springframework.test.context.ContextConfiguration)5 IOException (java.io.IOException)4 Iterator (java.util.Iterator)4 List (java.util.List)4 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)4 RepositoryProvider (org.apache.archiva.repository.RepositoryProvider)4 RepositoryType (org.apache.archiva.repository.RepositoryType)4 Path (java.nio.file.Path)3