use of org.apache.archiva.repository.features.ArtifactCleanupFeature 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());
}
use of org.apache.archiva.repository.features.ArtifactCleanupFeature 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());
}
use of org.apache.archiva.repository.features.ArtifactCleanupFeature 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()));
}
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;
}
use of org.apache.archiva.repository.features.ArtifactCleanupFeature in project archiva by apache.
the class RepositoryPurgeConsumerTest method testConsumerByRetentionCount.
@Test
public void testConsumerByRetentionCount() 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 atf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
// force days older off to allow retention count purge to execute.
atf.setRetentionPeriod(Period.ofDays(0));
atf.setRetentionCount(TEST_RETENTION_COUNT);
addRepoToConfiguration("retention-count", repoConfiguration);
repoPurgeConsumer.beginScan(repoConfiguration, null);
String repoRoot = prepareTestRepos();
String projectNs = "org.jruby.plugins";
String projectPath = projectNs.replaceAll("\\.", "/");
String projectName = "jruby-rake-plugin";
String projectVersion = "1.0RC1-SNAPSHOT";
String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
String versionRoot = 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("1.0RC1-20070504.153317-1");
deletedVersions.add("1.0RC1-20070504.160758-2");
repoPurgeConsumer.processFile(PATH_TO_BY_RETENTION_COUNT_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()));
}
// assert if removed from repo
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.jar");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.jar");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.zip");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5");
assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1");
// assert if not removed from repo
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3-javadoc.jar");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3-javadoc.zip");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5");
assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1");
removeRepoFromConfiguration("retention-count", repoConfiguration);
}
Aggregations