Search in sources :

Example 1 with StagingRepositoryFeature

use of org.apache.archiva.repository.features.StagingRepositoryFeature in project archiva by apache.

the class MavenRepositoryProviderTest method getManagedConfiguration.

@Test
public void getManagedConfiguration() throws Exception {
    MavenManagedRepository repo = new MavenManagedRepository("test01", "My Test repo", Paths.get("target/repositories"));
    repo.setLocation(new URI("file:///this.is/a/test"));
    repo.setScanned(true);
    repo.setDescription(repo.getPrimaryLocale(), "This is a description");
    repo.setLayout("maven2");
    repo.setBlocksRedeployment(true);
    repo.setName(repo.getPrimaryLocale(), "test0002");
    repo.setSchedulingDefinition("0 0 05 ? * WED");
    repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
    repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
    StagingRepositoryFeature stagingFeat = repo.getFeature(StagingRepositoryFeature.class).get();
    stagingFeat.setStageRepoNeeded(true);
    IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
    indexCreationFeature.setIndexPath(new URI("test/.indexes"));
    indexCreationFeature.setSkipPackedIndexCreation(true);
    ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get();
    artifactCleanupFeature.setRetentionPeriod(Period.ofDays(5));
    artifactCleanupFeature.setRetentionCount(7);
    artifactCleanupFeature.setDeleteReleasedSnapshots(true);
    ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration(repo);
    assertEquals("/this.is/a/test", cfg.getLocation());
    assertTrue(cfg.isScanned());
    assertEquals("This is a description", cfg.getDescription());
    assertEquals("maven2", cfg.getLayout());
    assertTrue(cfg.isBlockRedeployments());
    assertEquals("test0002", cfg.getName());
    assertEquals("0 0 05 ? * WED", cfg.getRefreshCronExpression());
    assertTrue(cfg.isStageRepoNeeded());
    assertEquals("test/.indexes", cfg.getIndexDir());
    assertTrue(cfg.isSkipPackedIndexCreation());
    assertEquals(5, cfg.getRetentionPeriod());
    assertEquals(7, cfg.getRetentionCount());
    assertTrue(cfg.isDeleteReleasedSnapshots());
    assertTrue(cfg.isReleases());
    assertTrue(cfg.isSnapshots());
    assertTrue(cfg.isScanned());
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) URI(java.net.URI) Test(org.junit.Test)

Example 2 with StagingRepositoryFeature

use of org.apache.archiva.repository.features.StagingRepositoryFeature in project archiva by apache.

the class MavenRepositoryProviderTest method createManagedInstance.

@Test
public void createManagedInstance() throws Exception {
    ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
    repo.setId("testm001");
    repo.setName("Managed Test Repo 001");
    repo.setDescription("This is a managed test");
    repo.setRetentionPeriod(37);
    repoLocation = Files.createTempDirectory("test-repo-001");
    repo.setLocation(repoLocation.toAbsolutePath().toString());
    repo.setSnapshots(true);
    repo.setReleases(true);
    repo.setRefreshCronExpression("4 0 0 ? * TUE");
    repo.setScanned(true);
    repo.setBlockRedeployments(true);
    repo.setDeleteReleasedSnapshots(true);
    repo.setRetentionCount(33);
    repo.setSkipPackedIndexCreation(true);
    repo.setStageRepoNeeded(true);
    repo.setIndexDir("testmanaged/.index");
    repo.setLayout("maven2");
    repo.setType(RepositoryType.MAVEN.toString());
    ManagedRepository mr = provider.createManagedInstance(repo);
    assertNotNull(mr.getLocation());
    String repoUri = repoLocation.toUri().toString();
    assertTrue(Files.exists(repoLocation));
    repoUri = repoUri.substring(0, repoUri.length() - 1);
    assertEquals(repoUri, mr.getLocation().toString());
    assertEquals("This is a managed test", mr.getDescription());
    assertEquals("Managed Test Repo 001", mr.getName());
    assertEquals(2, mr.getActiveReleaseSchemes().size());
    assertTrue(mr.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE));
    assertTrue(mr.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT));
    assertEquals("testm001", mr.getId());
    assertTrue(mr.blocksRedeployments());
    assertEquals("4 0 0 ? * TUE", mr.getSchedulingDefinition());
    assertTrue(mr.isScanned());
    ArtifactCleanupFeature artifactCleanupFeature = mr.getFeature(ArtifactCleanupFeature.class).get();
    assertEquals(Period.ofDays(37), artifactCleanupFeature.getRetentionPeriod());
    assertTrue(artifactCleanupFeature.isDeleteReleasedSnapshots());
    assertEquals(33, artifactCleanupFeature.getRetentionCount());
    IndexCreationFeature indexCreationFeature = mr.getFeature(IndexCreationFeature.class).get();
    assertNotNull(indexCreationFeature.getIndexPath());
    assertEquals("testmanaged/.index", indexCreationFeature.getIndexPath().toString());
    assertFalse(indexCreationFeature.getIndexPath().isAbsolute());
    assertTrue(indexCreationFeature.isSkipPackedIndexCreation());
    StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature(StagingRepositoryFeature.class).get();
    assertTrue(stagingRepositoryFeature.isStageRepoNeeded());
    assertNull(stagingRepositoryFeature.getStagingRepository());
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepository(org.apache.archiva.repository.ManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) Test(org.junit.Test)

Example 3 with StagingRepositoryFeature

use of org.apache.archiva.repository.features.StagingRepositoryFeature in project archiva by apache.

the class MavenRepositoryProvider method updateManagedInstance.

@Override
public void updateManagedInstance(EditableManagedRepository repo, ManagedRepositoryConfiguration cfg) throws RepositoryException {
    try {
        repo.setLocation(getURIFromString(cfg.getLocation()));
    } catch (UnsupportedURIException e) {
        throw new RepositoryException("The location entry is not a valid uri: " + cfg.getLocation());
    }
    setBaseConfig(repo, cfg);
    Path repoDir = repo.getLocalPath();
    if (!Files.exists(repoDir)) {
        log.debug("Creating repo directory {}", repoDir);
        try {
            Files.createDirectories(repoDir);
        } catch (IOException e) {
            log.error("Could not create directory {} for repository {}", repo.getLocalPath(), repo.getId(), e);
            throw new RepositoryException("Could not create directory for repository " + repo.getLocalPath());
        }
    }
    repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
    repo.setBlocksRedeployment(cfg.isBlockRedeployments());
    repo.setScanned(cfg.isScanned());
    if (cfg.isReleases()) {
        repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
    }
    if (cfg.isSnapshots()) {
        repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
    }
    StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature(StagingRepositoryFeature.class).get();
    stagingRepositoryFeature.setStageRepoNeeded(cfg.isStageRepoNeeded());
    IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
    indexCreationFeature.setSkipPackedIndexCreation(cfg.isSkipPackedIndexCreation());
    indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
    indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir()));
    /* -> Should be created by MavenIndexProvider

        Path indexPath;
        if (indexCreationFeature.getIndexPath().getScheme() == null) {
            indexPath = Paths.get(indexCreationFeature.getIndexPath().getPath());
        } else {
            indexPath = Paths.get(indexCreationFeature.getIndexPath());
        }
        Path absoluteIndexPath;
        if (indexPath.isAbsolute()) {
            absoluteIndexPath = indexPath;
        } else {
            absoluteIndexPath = PathUtil.getPathFromUri(repo.getLocation()).resolve(indexCreationFeature.getIndexPath().getPath());
        }
        try {
            Files.createDirectories(absoluteIndexPath);
        } catch (IOException e) {
            log.error("Could not create index directory {}", absoluteIndexPath);
            throw new RepositoryException("Could not create index directory " + absoluteIndexPath);
        }*/
    ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get();
    artifactCleanupFeature.setDeleteReleasedSnapshots(cfg.isDeleteReleasedSnapshots());
    artifactCleanupFeature.setRetentionCount(cfg.getRetentionCount());
    artifactCleanupFeature.setRetentionPeriod(Period.ofDays(cfg.getRetentionPeriod()));
}
Also used : Path(java.nio.file.Path) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) UnsupportedURIException(org.apache.archiva.repository.UnsupportedURIException) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Example 4 with StagingRepositoryFeature

use of org.apache.archiva.repository.features.StagingRepositoryFeature 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).get();
    configuration.setRetentionPeriod(acf.getRetentionPeriod().getDays());
    configuration.setDeleteReleasedSnapshots(acf.isDeleteReleasedSnapshots());
    configuration.setRetentionCount(acf.getRetentionCount());
    IndexCreationFeature icf = managedRepository.getFeature(IndexCreationFeature.class).get();
    configuration.setSkipPackedIndexCreation(icf.isSkipPackedIndexCreation());
    configuration.setIndexDir(icf.getIndexPath() == null ? "" : icf.getIndexPath().toString());
    StagingRepositoryFeature srf = managedRepository.getFeature(StagingRepositoryFeature.class).get();
    configuration.setStageRepoNeeded(srf.isStageRepoNeeded());
    return configuration;
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Example 5 with StagingRepositoryFeature

use of org.apache.archiva.repository.features.StagingRepositoryFeature in project archiva by apache.

the class RepositoryRegistry method updateRepositoryReferences.

private void updateRepositoryReferences(RepositoryProvider provider, ManagedRepository repo, ManagedRepositoryConfiguration cfg, Configuration configuration) throws RepositoryException {
    log.debug("Updating references of repo {}", repo.getId());
    if (repo.supportsFeature(StagingRepositoryFeature.class)) {
        StagingRepositoryFeature feature = repo.getFeature(StagingRepositoryFeature.class).get();
        if (feature.isStageRepoNeeded() && feature.getStagingRepository() == null) {
            ManagedRepository stageRepo = getStagingRepository(provider, cfg, configuration);
            managedRepositories.put(stageRepo.getId(), stageRepo);
            feature.setStagingRepository(stageRepo);
            if (configuration != null) {
                replaceOrAddRepositoryConfig(provider.getManagedConfiguration(stageRepo), configuration);
            }
        }
    }
    if (repo instanceof EditableManagedRepository) {
        EditableManagedRepository editableRepo = (EditableManagedRepository) repo;
        if (repo.getContent() == null) {
            editableRepo.setContent(repositoryContentFactory.getManagedRepositoryContent(repo));
        }
        log.debug("Index repo: " + repo.hasIndex());
        if (repo.hasIndex() && repo.getIndexingContext() == null) {
            log.debug("Creating indexing context for {}", repo.getId());
            createIndexingContext(editableRepo);
        }
    }
}
Also used : StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Aggregations

StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)13 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)10 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)10 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)6 RepositoryException (org.apache.archiva.repository.RepositoryException)5 IOException (java.io.IOException)3 URI (java.net.URI)3 Test (org.junit.Test)3 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)1 Configuration (org.apache.archiva.configuration.Configuration)1 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)1 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)1 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)1 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)1 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)1 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1