Search in sources :

Example 11 with ArtifactCleanupFeature

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

the class RepositoryProviderMock method updateManagedInstance.

@Override
public void updateManagedInstance(EditableManagedRepository managedRepository, ManagedRepositoryConfiguration configuration) throws RepositoryException {
    try {
        managedRepository.setName(managedRepository.getPrimaryLocale(), configuration.getName());
        managedRepository.setLocation(new URI(configuration.getLocation() == null ? "" : configuration.getLocation()));
        managedRepository.setBaseUri(new URI(""));
        managedRepository.setBlocksRedeployment(configuration.isBlockRedeployments());
        managedRepository.setDescription(managedRepository.getPrimaryLocale(), configuration.getDescription());
        managedRepository.setLayout(configuration.getLayout());
        managedRepository.setScanned(configuration.isScanned());
        managedRepository.setSchedulingDefinition(configuration.getRefreshCronExpression());
        if (configuration.isReleases()) {
            managedRepository.addActiveReleaseScheme(ReleaseScheme.RELEASE);
        }
        if (configuration.isSnapshots()) {
            managedRepository.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
        }
        ArtifactCleanupFeature acf = managedRepository.getFeature(ArtifactCleanupFeature.class).get();
        acf.setRetentionPeriod(Period.ofDays(configuration.getRetentionPeriod()));
        acf.setDeleteReleasedSnapshots(configuration.isDeleteReleasedSnapshots());
        acf.setRetentionCount(configuration.getRetentionCount());
        IndexCreationFeature icf = managedRepository.getFeature(IndexCreationFeature.class).get();
        icf.setIndexPath(new URI(configuration.getIndexDir()));
        icf.setSkipPackedIndexCreation(configuration.isSkipPackedIndexCreation());
        StagingRepositoryFeature srf = managedRepository.getFeature(StagingRepositoryFeature.class).get();
        srf.setStageRepoNeeded(configuration.isStageRepoNeeded());
    } catch (Exception e) {
        throw new RepositoryException("Error", e);
    }
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) RepositoryException(org.apache.archiva.repository.RepositoryException) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) URI(java.net.URI) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 12 with ArtifactCleanupFeature

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

the class RepositoryProviderMock method updateManagedInstance.

@Override
public void updateManagedInstance(EditableManagedRepository managedRepository, ManagedRepositoryConfiguration configuration) throws RepositoryException {
    try {
        managedRepository.setName(managedRepository.getPrimaryLocale(), configuration.getName());
        managedRepository.setLocation(new URI(configuration.getLocation() == null ? "" : configuration.getLocation()));
        managedRepository.setBaseUri(new URI(""));
        managedRepository.setBlocksRedeployment(configuration.isBlockRedeployments());
        managedRepository.setDescription(managedRepository.getPrimaryLocale(), configuration.getDescription());
        managedRepository.setLayout(configuration.getLayout());
        managedRepository.setScanned(configuration.isScanned());
        managedRepository.setSchedulingDefinition(configuration.getRefreshCronExpression());
        if (configuration.isReleases()) {
            managedRepository.addActiveReleaseScheme(ReleaseScheme.RELEASE);
        }
        if (configuration.isSnapshots()) {
            managedRepository.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
        }
        ArtifactCleanupFeature acf = managedRepository.getFeature(ArtifactCleanupFeature.class).get();
        acf.setRetentionPeriod(Period.ofDays(configuration.getRetentionPeriod()));
        acf.setDeleteReleasedSnapshots(configuration.isDeleteReleasedSnapshots());
        acf.setRetentionCount(configuration.getRetentionCount());
        IndexCreationFeature icf = managedRepository.getFeature(IndexCreationFeature.class).get();
        icf.setIndexPath(new URI(configuration.getIndexDir()));
        icf.setSkipPackedIndexCreation(configuration.isSkipPackedIndexCreation());
        StagingRepositoryFeature srf = managedRepository.getFeature(StagingRepositoryFeature.class).get();
        srf.setStageRepoNeeded(configuration.isStageRepoNeeded());
    } catch (Exception e) {
        throw new RepositoryException("Error", e);
    }
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) RepositoryException(org.apache.archiva.repository.RepositoryException) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) URI(java.net.URI) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 13 with ArtifactCleanupFeature

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

the class RepositoryPurgeConsumerTest method testReleasedSnapshotsWereCleaned.

@Test
public void testReleasedSnapshotsWereCleaned() throws Exception {
    KnownRepositoryContentConsumer repoPurgeConsumer = applicationContext.getBean("knownRepositoryContentConsumer#repo-purge-consumer-by-days-old", KnownRepositoryContentConsumer.class);
    org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME);
    ArtifactCleanupFeature acf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
    acf.setDeleteReleasedSnapshots(true);
    addRepoToConfiguration("days-old", repoConfiguration);
    repoPurgeConsumer.beginScan(repoConfiguration, null);
    String repoRoot = prepareTestRepos();
    String projectNs = "org.apache.maven.plugins";
    String projectPath = projectNs.replaceAll("\\.", "/");
    String projectName = "maven-plugin-plugin";
    String projectVersion = "2.3-SNAPSHOT";
    String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
    Path repo = getTestRepoRootPath();
    Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
    // Provide the metadata list
    List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
    repoPurgeConsumer.processFile(CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO);
    verify(metadataRepository, times(1)).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
    ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
    verify(metadataRepository, never()).removeArtifact(any(), any());
    // check if the snapshot was removed
    assertDeleted(projectRoot + "/2.3-SNAPSHOT");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1");
    // check if metadata file was updated
    Path artifactMetadataFile = Paths.get(projectRoot + "/maven-metadata.xml");
    String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString(artifactMetadataFile, Charset.defaultCharset());
    String expectedVersions = "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
    XMLAssert.assertXpathEvaluatesTo("2.3", "//metadata/versioning/latest", metadataXml);
    XMLAssert.assertXpathsEqual("//expected/versions/version", expectedVersions, "//metadata/versioning/versions/version", metadataXml);
    XMLAssert.assertXpathEvaluatesTo("20070315032817", "//metadata/versioning/lastUpdated", metadataXml);
    removeRepoFromConfiguration("days-old", repoConfiguration);
}
Also used : Path(java.nio.file.Path) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 14 with ArtifactCleanupFeature

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

the class RepositoryPurgeConsumerTest method testReleasedSnapshotsWereNotCleaned.

/**
 * Test the snapshot clean consumer on a repository set to NOT clean/delete snapshots based on released versions.
 *
 * @throws Exception
 */
@Test
public void testReleasedSnapshotsWereNotCleaned() throws Exception {
    KnownRepositoryContentConsumer repoPurgeConsumer = applicationContext.getBean("knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count", KnownRepositoryContentConsumer.class);
    org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME);
    ArtifactCleanupFeature acf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
    // Set to NOT delete released snapshots.
    acf.setDeleteReleasedSnapshots(false);
    addRepoToConfiguration("retention-count", repoConfiguration);
    repoPurgeConsumer.beginScan(repoConfiguration, null);
    String repoRoot = prepareTestRepos();
    String projectNs = "org.apache.maven.plugins";
    String projectPath = projectNs.replaceAll("\\.", "/");
    String projectName = "maven-plugin-plugin";
    String projectVersion = "2.3-SNAPSHOT";
    String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
    Path repo = getTestRepoRootPath();
    Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
    // Provide the metadata list
    List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo, vDir);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
    repoPurgeConsumer.processFile(CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO);
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
    ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
    verify(metadataRepository, never()).removeArtifact(any(), any());
    verify(metadataRepository, never()).removeArtifact(any(), any(), any(), any(), any(MetadataFacet.class));
    // check if the snapshot wasn't removed
    assertExists(projectRoot + "/2.3-SNAPSHOT");
    assertExists(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar");
    assertExists(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5");
    assertExists(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1");
    assertExists(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom");
    assertExists(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5");
    assertExists(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1");
    // check if metadata file wasn't updated
    Path artifactMetadataFile = Paths.get(projectRoot + "/maven-metadata.xml");
    String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString(artifactMetadataFile, Charset.defaultCharset());
    String expectedVersions = "<expected><versions><version>2.3-SNAPSHOT</version></versions></expected>";
    XMLAssert.assertXpathEvaluatesTo("2.3-SNAPSHOT", "//metadata/versioning/latest", metadataXml);
    XMLAssert.assertXpathsEqual("//expected/versions/version", expectedVersions, "//metadata/versioning/versions/version", metadataXml);
    XMLAssert.assertXpathEvaluatesTo("20070315032817", "//metadata/versioning/lastUpdated", metadataXml);
    removeRepoFromConfiguration("retention-count", repoConfiguration);
}
Also used : Path(java.nio.file.Path) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 15 with ArtifactCleanupFeature

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

the class RepositoryPurgeConsumerTest method testConsumerByDaysOld.

@Test
public void testConsumerByDaysOld() throws Exception {
    KnownRepositoryContentConsumer repoPurgeConsumer = applicationContext.getBean("knownRepositoryContentConsumer#repo-purge-consumer-by-days-old", KnownRepositoryContentConsumer.class);
    org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME);
    ArtifactCleanupFeature atf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
    atf.setRetentionPeriod(Period.ofDays(TEST_DAYS_OLDER));
    addRepoToConfiguration("days-old", repoConfiguration);
    repoPurgeConsumer.beginScan(repoConfiguration, null);
    String repoRoot = prepareTestRepos();
    String projectNs = "org.apache.maven.plugins";
    String projectPath = projectNs.replaceAll("\\.", "/");
    String projectName = "maven-install-plugin";
    String projectVersion = "2.2-SNAPSHOT";
    String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
    setLastModified(projectRoot + "/" + projectVersion);
    Path repo = getTestRepoRootPath();
    Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
    // Provide the metadata list
    List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo, vDir);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
    Set<String> deletedVersions = new HashSet<>();
    deletedVersions.add("2.2-SNAPSHOT");
    deletedVersions.add("2.2-20061118.060401-2");
    repoPurgeConsumer.processFile(PATH_TO_BY_DAYS_OLD_ARTIFACT);
    // Verify the metadataRepository invocations
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
    ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
    verify(metadataRepository, times(2)).removeArtifact(metadataArg.capture(), eq(projectVersion));
    List<ArtifactMetadata> metaL = metadataArg.getAllValues();
    for (ArtifactMetadata meta : metaL) {
        assertTrue(meta.getId().startsWith(projectName));
        assertTrue(deletedVersions.contains(meta.getVersion()));
    }
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1");
    // shouldn't be deleted because even if older than 30 days (because retention count = 2)
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.md5");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.sha1");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1");
    removeRepoFromConfiguration("days-old", repoConfiguration);
}
Also used : Path(java.nio.file.Path) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)20 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)10 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)10 Test (org.junit.Test)10 Path (java.nio.file.Path)9 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)7 HashSet (java.util.HashSet)5 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)5 URI (java.net.URI)4 KnownRepositoryContentConsumer (org.apache.archiva.consumers.KnownRepositoryContentConsumer)4 RepositoryException (org.apache.archiva.repository.RepositoryException)4 RepositoryListener (org.apache.archiva.repository.events.RepositoryListener)3 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)1 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)1 ConsumerException (org.apache.archiva.consumers.ConsumerException)1