Search in sources :

Example 11 with ManagedRepositoryConfiguration

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

the class ManagedRepositoryHandler method newInstancesFromConfig.

@Override
public Map<String, ManagedRepository> newInstancesFromConfig() {
    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) {
            ManagedRepository repo = newInstance(repoConfig);
            result.put(repo.getId(), repo);
            if (repo.supportsFeature(StagingRepositoryFeature.class)) {
                StagingRepositoryFeature stagF = repo.getFeature(StagingRepositoryFeature.class);
                if (stagF.getStagingRepository() != null) {
                    ManagedRepository 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) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Example 12 with ManagedRepositoryConfiguration

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

Example 13 with ManagedRepositoryConfiguration

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

the class MavenRepositoryMapperTest method map.

@Test
void map() {
    MavenRepositoryMapper mapper = new MavenRepositoryMapper();
    MavenManagedRepository repo = new MavenManagedRepository();
    repo.setId("repo01");
    repo.setName("Repo 01");
    repo.setDescription("This is repo 01");
    repo.setLocation("/data/repo01");
    repo.setHasStagingRepository(true);
    repo.setSchedulingDefinition("0,1,2 * * * *");
    repo.setPackedIndexPath(".index");
    repo.setIndexPath(".indexer");
    repo.setIndex(true);
    repo.setDeleteSnapshotsOfRelease(false);
    repo.setBlocksRedeployments(false);
    repo.setReleaseSchemes(Arrays.asList(ReleaseScheme.RELEASE.name(), ReleaseScheme.SNAPSHOT.name()));
    repo.setCharacteristic(Repository.CHARACTERISTIC_MANAGED);
    repo.setScanned(true);
    repo.setRetentionPeriod(Period.ofDays(10));
    repo.setRetentionCount(15);
    repo.setSkipPackedIndexCreation(false);
    repo.setStagingRepository("stage-repo01");
    ManagedRepositoryConfiguration result = mapper.map(repo);
    assertNotNull(result);
    assertEquals("repo01", result.getId());
    assertEquals("Repo 01", result.getName());
    assertEquals("This is repo 01", result.getDescription());
    assertEquals("/data/repo01", result.getLocation());
    assertTrue(result.isStageRepoNeeded());
    assertEquals("0,1,2 * * * *", result.getRefreshCronExpression());
    assertEquals(".indexer", result.getIndexDir());
    assertEquals(".index", result.getPackedIndexDir());
    assertFalse(result.isDeleteReleasedSnapshots());
    assertFalse(result.isBlockRedeployments());
    assertTrue(result.isSnapshots());
    assertTrue(result.isReleases());
    assertTrue(result.isScanned());
    assertEquals(10, result.getRetentionPeriod());
    assertEquals(15, result.getRetentionCount());
    assertFalse(result.isSkipPackedIndexCreation());
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) MavenManagedRepository(org.apache.archiva.rest.api.v2.model.MavenManagedRepository) Test(org.junit.jupiter.api.Test)

Example 14 with ManagedRepositoryConfiguration

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

the class MavenRepositoryMapper method map.

@Override
public ManagedRepositoryConfiguration map(MavenManagedRepository source) {
    ManagedRepositoryConfiguration target = new ManagedRepositoryConfiguration();
    update(source, target);
    return target;
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)

Example 15 with ManagedRepositoryConfiguration

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

the class RepositoryProviderMock method getManagedConfiguration.

@Override
public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException {
    ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration();
    configuration.setId(managedRepository.getId());
    configuration.setName(managedRepository.getName());
    configuration.setLocation(managedRepository.getLocation() == null ? "" : managedRepository.getLocation().toString());
    configuration.setBlockRedeployments(managedRepository.blocksRedeployments());
    configuration.setDescription(managedRepository.getDescription());
    configuration.setLayout(managedRepository.getLayout());
    configuration.setScanned(managedRepository.isScanned());
    configuration.setRefreshCronExpression(managedRepository.getSchedulingDefinition());
    configuration.setReleases(managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE));
    configuration.setSnapshots(managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT));
    ArtifactCleanupFeature acf = managedRepository.getFeature(ArtifactCleanupFeature.class);
    configuration.setRetentionPeriod(acf.getRetentionPeriod().getDays());
    configuration.setDeleteReleasedSnapshots(acf.isDeleteReleasedSnapshots());
    configuration.setRetentionCount(acf.getRetentionCount());
    IndexCreationFeature icf = managedRepository.getFeature(IndexCreationFeature.class);
    configuration.setSkipPackedIndexCreation(icf.isSkipPackedIndexCreation());
    configuration.setIndexDir(icf.getIndexPath() == null ? "" : icf.getIndexPath().toString());
    StagingRepositoryFeature srf = managedRepository.getFeature(StagingRepositoryFeature.class);
    configuration.setStageRepoNeeded(srf.isStageRepoNeeded());
    return configuration;
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

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