Search in sources :

Example 16 with ArtifactCleanupFeature

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

the class DaysOldRepositoryPurgeTest method testMetadataDrivenSnapshots.

@Test
public void testMetadataDrivenSnapshots() 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.codehaus.plexus";
    String projectPath = projectNs.replaceAll("\\.", "/");
    String projectName = "plexus-utils";
    String projectVersion = "1.4.3-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.4.3-20070113.163208-4");
    String versionRoot = projectRoot + "/" + projectVersion;
    Calendar currentDate = Calendar.getInstance(DateUtils.UTC_TIME_ZONE);
    setLastModified(versionRoot, currentDate.getTimeInMillis());
    String timestamp = new SimpleDateFormat("yyyyMMdd.HHmmss").format(currentDate.getTime());
    for (int i = 5; i <= 7; i++) {
        Path jarFile = Paths.get(versionRoot, "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".jar");
        Files.createFile(jarFile);
        Path pomFile = Paths.get(versionRoot, "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".pom");
        Files.createFile(pomFile);
        // set timestamp to older than 100 days for the first build, but ensure the filename timestamp is honoured instead
        if (i == 5) {
            Files.setLastModifiedTime(jarFile, FileTime.fromMillis(OLD_TIMESTAMP));
            Files.setLastModifiedTime(pomFile, FileTime.fromMillis(OLD_TIMESTAMP));
        }
    }
    // test listeners for the correct artifacts
    String[] exts = { ".sha1", "" };
    for (int i = 0; i < exts.length; i++) {
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.codehaus.plexus", "plexus-utils", "1.4.3-20070113.163208-4", "plexus-utils-1.4.3-20070113.163208-4.jar" + exts[i]);
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.codehaus.plexus", "plexus-utils", "1.4.3-20070113.163208-4", "plexus-utils-1.4.3-20070113.163208-4.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_METADATA_DRIVEN_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(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()));
    }
    // this should be deleted since the filename version (timestamp) is older than
    // 100 days even if the last modified date was <100 days ago
    assertDeleted(versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar");
    assertDeleted(versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar.sha1");
    assertDeleted(versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom");
    assertDeleted(versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom.sha1");
    // this should not be deleted because last modified date is <100 days ago
    assertExists(versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.jar");
    assertExists(versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.pom");
    for (int i = 5; i <= 7; i++) {
        assertExists(versionRoot + "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".jar");
        assertExists(versionRoot + "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".pom");
    }
}
Also used : RepositoryListener(org.apache.archiva.repository.events.RepositoryListener) Path(java.nio.file.Path) Calendar(java.util.Calendar) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) SimpleDateFormat(java.text.SimpleDateFormat) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with ArtifactCleanupFeature

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

the class DefaultManagedRepositoryAdmin method convertRepo.

/*
     * Conversion between the repository from the registry and the serialized DTO for the admin API
     */
private ManagedRepository convertRepo(org.apache.archiva.repository.ManagedRepository repo) {
    if (repo == null) {
        return null;
    }
    ManagedRepository adminRepo = new ManagedRepository(getArchivaConfiguration().getDefaultLocale());
    setBaseRepoAttributes(adminRepo, repo);
    adminRepo.setLocation(convertUriToString(repo.getLocation()));
    adminRepo.setReleases(repo.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE));
    adminRepo.setSnapshots(repo.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT));
    adminRepo.setBlockRedeployments(repo.blocksRedeployments());
    adminRepo.setCronExpression(repo.getSchedulingDefinition());
    if (repo.supportsFeature(IndexCreationFeature.class)) {
        IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
        adminRepo.setSkipPackedIndexCreation(icf.isSkipPackedIndexCreation());
    }
    adminRepo.setScanned(repo.isScanned());
    if (repo.supportsFeature(ArtifactCleanupFeature.class)) {
        ArtifactCleanupFeature acf = repo.getFeature(ArtifactCleanupFeature.class).get();
        adminRepo.setRetentionPeriod(acf.getRetentionPeriod().getDays());
        adminRepo.setRetentionCount(acf.getRetentionCount());
        adminRepo.setDeleteReleasedSnapshots(acf.isDeleteReleasedSnapshots());
    }
    if (repo.supportsFeature(StagingRepositoryFeature.class)) {
        StagingRepositoryFeature stf = repo.getFeature(StagingRepositoryFeature.class).get();
        adminRepo.setStageRepoNeeded(stf.isStageRepoNeeded());
        if (stf.getStagingRepository() != null) {
            adminRepo.setStagingRepository(convertRepo(stf.getStagingRepository()));
        }
    }
    return adminRepo;
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Example 18 with ArtifactCleanupFeature

use of org.apache.archiva.repository.features.ArtifactCleanupFeature 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 19 with ArtifactCleanupFeature

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

the class MavenRepositoryProviderTest method createRemoteInstance.

@Test
public void createRemoteInstance() throws Exception {
    RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
    repo.setUsername("testuser001");
    repo.setPassword("pwd0000abc");
    repo.setCheckPath("test/check.html");
    repo.setTimeout(50);
    repo.setUrl("https://repo.maven.apache.org/maven2/test");
    repo.setDownloadRemoteIndex(true);
    repo.setDownloadRemoteIndexOnStartup(true);
    Map<String, String> header = new HashMap<>();
    header.put("header1", "value1");
    header.put("header2", "value2");
    repo.setExtraHeaders(header);
    Map<String, String> params = new HashMap<>();
    params.put("param1", "pval1");
    params.put("param2", "pval2");
    repo.setExtraParameters(params);
    repo.setRefreshCronExpression("0 1 07 ? * MON");
    repo.setRemoteDownloadTimeout(333);
    repo.setRemoteIndexUrl("testremote/.index");
    repo.setDescription("This is a test");
    repo.setId("test001");
    repo.setName("Remote Test Repo 001");
    repo.setIndexDir("testindex/.index");
    repo.setLayout("maven2");
    repo.setType(RepositoryType.MAVEN.toString());
    repo.setIndexDir("local/.index");
    RemoteRepository mr = provider.createRemoteInstance(repo);
    assertEquals("test001", mr.getId());
    assertEquals("This is a test", mr.getDescription());
    assertNotNull(mr.getLocation());
    assertEquals("https://repo.maven.apache.org/maven2/test", mr.getLocation().toString());
    assertEquals("Remote Test Repo 001", mr.getName());
    assertEquals("test001", mr.getId());
    assertEquals("0 1 07 ? * MON", mr.getSchedulingDefinition());
    assertEquals(50, mr.getTimeout().get(ChronoUnit.SECONDS));
    assertTrue(mr.isScanned());
    assertNotNull(mr.getLoginCredentials());
    assertTrue(mr.getLoginCredentials() instanceof PasswordCredentials);
    PasswordCredentials creds = (PasswordCredentials) mr.getLoginCredentials();
    assertEquals("testuser001", creds.getUsername());
    assertEquals("pwd0000abc", new String(creds.getPassword()));
    assertEquals("value1", mr.getExtraHeaders().get("header1"));
    assertEquals("pval2", mr.getExtraParameters().get("param2"));
    assertEquals("maven2", mr.getLayout());
    try {
        ArtifactCleanupFeature artifactCleanupFeature = mr.getFeature(ArtifactCleanupFeature.class).get();
        throw new Exception("artifactCleanupFeature should not be available");
    } catch (UnsupportedFeatureException e) {
    // correct
    }
    IndexCreationFeature indexCreationFeature = mr.getFeature(IndexCreationFeature.class).get();
    assertEquals("local/.index", indexCreationFeature.getIndexPath().toString());
    try {
        StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature(StagingRepositoryFeature.class).get();
        throw new Exception("stagingRepositoryFeature should not be available");
    } catch (UnsupportedFeatureException e) {
    // correct
    }
    RemoteIndexFeature remoteIndexFeature = mr.getFeature(RemoteIndexFeature.class).get();
    assertNull(remoteIndexFeature.getProxyId());
}
Also used : PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) UnsupportedFeatureException(org.apache.archiva.repository.UnsupportedFeatureException) HashMap(java.util.HashMap) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) UnsupportedFeatureException(org.apache.archiva.repository.UnsupportedFeatureException) Test(org.junit.Test)

Example 20 with ArtifactCleanupFeature

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

the class MavenRepositoryProvider method getManagedConfiguration.

@Override
public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException {
    if (!(managedRepository instanceof MavenManagedRepository || managedRepository instanceof BasicManagedRepository)) {
        log.error("Wrong remote repository type " + managedRepository.getClass().getName());
        throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + managedRepository.getClass().getName());
    }
    ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
    cfg.setType(managedRepository.getType().toString());
    cfg.setId(managedRepository.getId());
    cfg.setName(managedRepository.getName());
    cfg.setDescription(managedRepository.getDescription());
    cfg.setLocation(convertUriToPath(managedRepository.getLocation()));
    cfg.setLayout(managedRepository.getLayout());
    cfg.setRefreshCronExpression(managedRepository.getSchedulingDefinition());
    cfg.setScanned(managedRepository.isScanned());
    cfg.setBlockRedeployments(managedRepository.blocksRedeployments());
    StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature(StagingRepositoryFeature.class).get();
    cfg.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded());
    IndexCreationFeature indexCreationFeature = managedRepository.getFeature(IndexCreationFeature.class).get();
    cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
    cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
    cfg.setSkipPackedIndexCreation(indexCreationFeature.isSkipPackedIndexCreation());
    ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature(ArtifactCleanupFeature.class).get();
    cfg.setRetentionCount(artifactCleanupFeature.getRetentionCount());
    cfg.setRetentionPeriod(artifactCleanupFeature.getRetentionPeriod().getDays());
    cfg.setDeleteReleasedSnapshots(artifactCleanupFeature.isDeleteReleasedSnapshots());
    if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)) {
        cfg.setReleases(true);
    } else {
        cfg.setReleases(false);
    }
    if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT)) {
        cfg.setSnapshots(true);
    } else {
        cfg.setSnapshots(false);
    }
    return cfg;
}
Also used : BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

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