Search in sources :

Example 6 with ArtifactCleanupFeature

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

the class RepositoryPurgeConsumer method beginScan.

@Override
public void beginScan(ManagedRepository repository, Date whenGathered) throws ConsumerException {
    ManagedRepositoryContent repositoryContent;
    repositoryContent = repository.getContent();
    repositorySession = repositorySessionFactory.createSession();
    if (repository.supportsFeature(ArtifactCleanupFeature.class)) {
        ArtifactCleanupFeature acf = repository.getFeature(ArtifactCleanupFeature.class).get();
        int retentionPeriodInDays = acf.getRetentionPeriod().getDays();
        int retentionCount = acf.getRetentionCount();
        if (retentionPeriodInDays != 0) {
            repoPurge = new DaysOldRepositoryPurge(repositoryContent, retentionPeriodInDays, retentionCount, repositorySession, listeners);
        } else {
            repoPurge = new RetentionCountRepositoryPurge(repositoryContent, retentionCount, repositorySession, listeners);
        }
        deleteReleasedSnapshots = acf.isDeleteReleasedSnapshots();
    } else {
        throw new ConsumerException("The repository does not support the ArtifactCleanup feature " + repository.getId());
    }
    cleanUp = new CleanupReleasedSnapshotsRepositoryPurge(repositoryContent, metadataTools, repositoryRegistry, repositorySession, listeners);
}
Also used : ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ConsumerException(org.apache.archiva.consumers.ConsumerException) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature)

Example 7 with ArtifactCleanupFeature

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

the class AbstractRepositoryPurgeTest method getRepoConfiguration.

public org.apache.archiva.repository.ManagedRepository getRepoConfiguration(String repoId, String repoName) throws URISyntaxException {
    Path basePath = Paths.get("target/test-" + getName()).toAbsolutePath();
    config = new BasicManagedRepository(repoId, repoName, basePath);
    config.addActiveReleaseScheme(ReleaseScheme.RELEASE);
    config.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
    ArtifactCleanupFeature atf = config.getFeature(ArtifactCleanupFeature.class).get();
    atf.setRetentionPeriod(Period.ofDays(TEST_DAYS_OLDER));
    String path = AbstractRepositoryPurgeTest.fixPath(basePath.resolve(repoId).toAbsolutePath().toString());
    config.setLocation(new URI(path));
    atf.setDeleteReleasedSnapshots(true);
    atf.setRetentionCount(TEST_RETENTION_COUNT);
    return config;
}
Also used : Path(java.nio.file.Path) BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) URI(java.net.URI)

Example 8 with ArtifactCleanupFeature

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

the class DaysOldRepositoryPurgeTest method testOrderOfDeletion.

@Test
public void testOrderOfDeletion() throws Exception {
    org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME);
    ArtifactCleanupFeature atf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
    List<RepositoryListener> listeners = Collections.singletonList(listener);
    repoPurge = new DaysOldRepositoryPurge(getRepository(), atf.getRetentionPeriod().getDays(), atf.getRetentionCount(), repositorySession, listeners);
    String repoRoot = prepareTestRepos();
    String projectNs = "org.apache.maven.plugins";
    String projectPath = projectNs.replaceAll("\\.", "/");
    String projectName = "maven-assembly-plugin";
    String projectVersion = "1.1.2-SNAPSHOT";
    String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
    Path repo = getTestRepoRootPath();
    Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
    Set<String> deletedVersions = new HashSet<>();
    deletedVersions.add("1.1.2-20070427.065136-1");
    setLastModified(projectRoot + "/" + projectVersion + "/", OLD_TIMESTAMP);
    // test listeners for the correct artifacts
    String[] exts = { ".md5", ".sha1", "" };
    for (int i = 0; i < exts.length; i++) {
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" + exts[i]);
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" + exts[i]);
    }
    listenerControl.replay();
    // 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);
    repoPurge.process(PATH_TO_TEST_ORDER_OF_DELETION);
    listenerControl.verify();
    // 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(deletedVersions.size())).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 + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar");
    assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1");
    assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5");
    assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom");
    assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1");
    assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5");
    // the following should not have been deleted
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5");
}
Also used : RepositoryListener(org.apache.archiva.repository.events.RepositoryListener) Path(java.nio.file.Path) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with ArtifactCleanupFeature

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

the class DaysOldRepositoryPurgeTest method testByLastModified.

@Test
public void testByLastModified() throws Exception {
    org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME);
    ArtifactCleanupFeature atf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
    repoPurge = new DaysOldRepositoryPurge(getRepository(), atf.getRetentionPeriod().getDays(), atf.getRetentionCount(), repositorySession, Collections.singletonList(listener));
    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;
    Path repo = getTestRepoRootPath();
    Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
    Set<String> deletedVersions = new HashSet<>();
    deletedVersions.add("2.2-SNAPSHOT");
    deletedVersions.add("2.2-20061118.060401-2");
    setLastModified(projectRoot + "/" + projectVersion + "/", OLD_TIMESTAMP);
    // test listeners for the correct artifacts
    String[] exts = { ".md5", ".sha1", "" };
    for (int i = 0; i < exts.length; i++) {
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin", "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.jar" + exts[i]);
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin", "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.pom" + exts[i]);
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin", "2.2-20061118.060401-2", "maven-install-plugin-2.2-20061118.060401-2.jar" + exts[i]);
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin", "2.2-20061118.060401-2", "maven-install-plugin-2.2-20061118.060401-2.pom" + exts[i]);
    }
    listenerControl.replay();
    // 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);
    repoPurge.process(PATH_TO_BY_DAYS_OLD_ARTIFACT);
    listenerControl.verify();
    // 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");
}
Also used : Path(java.nio.file.Path) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with ArtifactCleanupFeature

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

the class RetentionCountRepositoryPurgeTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME);
    List<RepositoryListener> listeners = Collections.singletonList(listener);
    ArtifactCleanupFeature acf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
    repoPurge = new RetentionCountRepositoryPurge(getRepository(), acf.getRetentionCount(), repositorySession, listeners);
}
Also used : RepositoryListener(org.apache.archiva.repository.events.RepositoryListener) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) Before(org.junit.Before)

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