Search in sources :

Example 56 with ManagedRepositoryConfiguration

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

the class DefaultManagedRepositoryAdmin method deleteManagedRepository.

@Override
public Boolean deleteManagedRepository(String repositoryId, AuditInformation auditInformation, boolean deleteContent) throws RepositoryAdminException {
    Configuration config = getArchivaConfiguration().getConfiguration();
    ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById(repositoryId);
    if (repoConfig != null) {
        log.debug("Repo location " + repoConfig.getLocation());
        org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository(repositoryId);
        org.apache.archiva.repository.ManagedRepository stagingRepository = null;
        if (repo != null) {
            if (repo.supportsFeature(StagingRepositoryFeature.class)) {
                stagingRepository = repo.getFeature(StagingRepositoryFeature.class).getStagingRepository();
            }
        } else {
            throw new RepositoryAdminException("A repository with that id does not exist");
        }
        triggerAuditEvent(repositoryId, null, AuditEvent.DELETE_MANAGED_REPO, auditInformation);
        if (repoConfig != null) {
            deleteManagedRepository(repoConfig, deleteContent, config, false);
        }
        // stage repo exists ?
        if (stagingRepository != null) {
            // do not trigger event when deleting the staged one
            ManagedRepositoryConfiguration stagingRepositoryConfig = config.findManagedRepositoryById(stagingRepository.getId());
            if (stagingRepositoryConfig != null) {
                deleteManagedRepository(stagingRepositoryConfig, deleteContent, config, true);
            }
        }
        try {
            saveConfiguration(config);
        } catch (Exception e) {
            throw new RepositoryAdminException("Error saving configuration for delete action" + e.getMessage(), e);
        }
        return Boolean.TRUE;
    } else {
        return Boolean.FALSE;
    }
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataSessionException(org.apache.archiva.metadata.repository.MetadataSessionException) IOException(java.io.IOException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) TaskQueueException(org.apache.archiva.components.taskqueue.TaskQueueException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException)

Example 57 with ManagedRepositoryConfiguration

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

the class ManagedRepositoryHandler method clone.

@Override
public ManagedRepository clone(ManagedRepository repo, String id) throws RepositoryException {
    RepositoryProvider provider = getProvider(repo.getType());
    ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration(repo);
    cfg.setId(id);
    ManagedRepository cloned = provider.createManagedInstance(cfg);
    cloned.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
    setLastState(cloned, RepositoryState.CREATED);
    return cloned;
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

Example 58 with ManagedRepositoryConfiguration

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

the class ManagedRepositoryHandler method newOrUpdateInstancesFromConfig.

public Map<String, ManagedRepository> newOrUpdateInstancesFromConfig(Map<String, ManagedRepository> currentInstances) {
    try {
        List<ManagedRepositoryConfiguration> managedRepoConfigs = new ArrayList<>(getConfigurationHandler().getBaseConfiguration().getManagedRepositories());
        if (managedRepoConfigs == null) {
            return Collections.emptyMap();
        }
        Map<String, ManagedRepository> result = new HashMap<>();
        for (ManagedRepositoryConfiguration repoConfig : managedRepoConfigs) {
            String id = repoConfig.getId();
            if (result.containsKey(id)) {
                log.error("There are repositories with the same id in the configuration: {}", id);
                continue;
            }
            ManagedRepository repo;
            if (currentInstances.containsKey(id)) {
                repo = currentInstances.remove(id);
                getProvider(repo.getType()).updateManagedInstance((EditableManagedRepository) repo, repoConfig);
                updateReferences(repo, repoConfig);
            } else {
                repo = newInstance(repoConfig);
            }
            result.put(id, repo);
            if (repo.supportsFeature(StagingRepositoryFeature.class)) {
                StagingRepositoryFeature stagF = repo.getFeature(StagingRepositoryFeature.class);
                if (stagF.getStagingRepository() != null) {
                    String stagingId = getStagingId(id);
                    ManagedRepository stagingRepo;
                    if (currentInstances.containsKey(stagingId)) {
                        stagingRepo = currentInstances.remove(stagingId);
                        managedRepoConfigs.stream().filter(cfg -> stagingId.equals(cfg.getId())).findFirst().ifPresent(stagingRepoConfig -> {
                            try {
                                getProvider(stagingRepo.getType()).updateManagedInstance((EditableManagedRepository) stagingRepo, stagingRepoConfig);
                                updateReferences(stagingRepo, stagingRepoConfig);
                            } catch (RepositoryException e) {
                                log.error("Could not update staging repo {}: {}", stagingId, e.getMessage());
                            }
                        });
                    } else {
                        stagingRepo = getStagingRepository(repo);
                    }
                    if (stagingRepo != null) {
                        result.put(stagingRepo.getId(), stagingRepo);
                    }
                }
            }
        }
        return result;
    } catch (Throwable e) {
        log.error("Could not initialize repositories from config: {}", e.getMessage(), e);
        return new HashMap<>();
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RepositoryException(org.apache.archiva.repository.RepositoryException) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Example 59 with ManagedRepositoryConfiguration

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

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

the class ArchivaRepositoryRegistryTest method putManagedRepositoryFromConfig.

@Test
public void putManagedRepositoryFromConfig() throws Exception {
    ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
    cfg.setId("test002");
    cfg.setName("This is test 002");
    ManagedRepository repo = repositoryRegistry.putRepository(cfg);
    assertNotNull(repo);
    assertEquals("test002", repo.getId());
    assertEquals("This is test 002", repo.getName());
    assertNotNull(repo.getContent());
    archivaConfiguration.reload();
    Collection<ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
    assertEquals(5, repos.size());
    ManagedRepository internalRepo = repositoryRegistry.getManagedRepository("internal");
    cfg = new ManagedRepositoryConfiguration();
    cfg.setId("internal");
    cfg.setName("This is internal test 002");
    repo = repositoryRegistry.putRepository(cfg);
    assertSame(internalRepo, repo);
    assertEquals("This is internal test 002", repo.getName());
    assertEquals(5, repositoryRegistry.getManagedRepositories().size());
    repositoryRegistry.reload();
    assertEquals(5, repositoryRegistry.getManagedRepositories().size());
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)72 Configuration (org.apache.archiva.configuration.model.Configuration)27 ManagedRepository (org.apache.archiva.repository.ManagedRepository)18 ContextConfiguration (org.springframework.test.context.ContextConfiguration)18 Path (java.nio.file.Path)17 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)14 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)14 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)14 Test (org.junit.Test)14 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)13 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)11 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)10 Test (org.junit.jupiter.api.Test)10 ArrayList (java.util.ArrayList)9 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)9 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)9 RepositoryException (org.apache.archiva.repository.RepositoryException)9 Before (org.junit.Before)8 IOException (java.io.IOException)7 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)7