use of org.apache.archiva.metadata.model.ArtifactMetadata 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);
}
use of org.apache.archiva.metadata.model.ArtifactMetadata 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);
}
use of org.apache.archiva.metadata.model.ArtifactMetadata 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");
}
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class RetentionCountRepositoryPurgeTest method testIfAJarWasFound.
/**
* Test if the artifact to be processed was a jar.
*/
@Test
public void testIfAJarWasFound() throws Exception {
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;
Path repo = getTestRepoRootPath();
Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
Set<String> deletedVersions = new HashSet<>();
deletedVersions.add("1.0RC1-20070504.153317-1");
deletedVersions.add("1.0RC1-20070504.160758-2");
String versionRoot = projectRoot + "/" + projectVersion;
// test listeners for the correct artifacts
String[] exts = { ".md5", ".sha1", "" };
for (int i = 0; i < exts.length; i++) {
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" + exts[i]);
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" + exts[i]);
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" + exts[i]);
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" + exts[i]);
}
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.jar");
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.zip");
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.jar");
listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip");
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_RETENTION_COUNT_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()));
}
// 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.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.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.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");
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class CassandraMetadataRepository method mapArtifactMetadataLongColumnSlice.
protected ArtifactMetadata mapArtifactMetadataLongColumnSlice(ColumnSlice<String, Long> columnSlice) {
ArtifactMetadata artifactMetadata = new ArtifactMetadata();
artifactMetadata.setNamespace(getAsStringValue(columnSlice, NAMESPACE_ID.toString()));
artifactMetadata.setSize(getLongValue(columnSlice, SIZE.toString()));
artifactMetadata.setId(getAsStringValue(columnSlice, ID.toString()));
artifactMetadata.setFileLastModified(getLongValue(columnSlice, FILE_LAST_MODIFIED.toString()));
artifactMetadata.setMd5(getAsStringValue(columnSlice, MD5.toString()));
artifactMetadata.setProject(getAsStringValue(columnSlice, PROJECT.toString()));
artifactMetadata.setProjectVersion(getAsStringValue(columnSlice, PROJECT_VERSION.toString()));
artifactMetadata.setRepositoryId(getAsStringValue(columnSlice, REPOSITORY_NAME.toString()));
artifactMetadata.setSha1(getAsStringValue(columnSlice, SHA1.toString()));
artifactMetadata.setVersion(getAsStringValue(columnSlice, VERSION.toString()));
Long whenGathered = getLongValue(columnSlice, WHEN_GATHERED.toString());
if (whenGathered != null) {
artifactMetadata.setWhenGathered(new Date(whenGathered));
}
return artifactMetadata;
}
Aggregations