use of org.apache.archiva.consumers.KnownRepositoryContentConsumer in project archiva by apache.
the class RepositoryScannerTest method testTimestampRepositoryScannerProcessUnmodified.
@Test
public void testTimestampRepositoryScannerProcessUnmodified() throws Exception {
ManagedRepository repository = createSimpleRepository();
List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>();
KnownScanConsumer consumer = new KnownScanConsumer();
consumer.setProcessUnmodified(true);
consumer.setIncludes(ARTIFACT_PATTERNS);
knownConsumers.add(consumer);
List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<>();
InvalidScanConsumer badconsumer = new InvalidScanConsumer();
invalidConsumers.add(badconsumer);
RepositoryScanner scanner = lookupRepositoryScanner();
RepositoryScanStatistics stats = scanner.scan(repository, knownConsumers, invalidConsumers, getIgnoreList(), getTimestampAsMillis("20061101.000000"));
assertNotNull("Stats should not be null.", stats);
assertEquals("Stats.totalFileCount", 4, stats.getTotalFileCount());
assertEquals("Stats.newFileCount", 3, stats.getNewFileCount());
assertEquals("Processed Count", 3, consumer.getProcessCount());
assertEquals("Processed Count (of invalid items)", 1, badconsumer.getProcessCount());
}
use of org.apache.archiva.consumers.KnownRepositoryContentConsumer in project archiva by apache.
the class ArchivaCli method dumpAvailableConsumers.
private void dumpAvailableConsumers() {
Map<String, KnownRepositoryContentConsumer> availableConsumers = getConsumers();
LOGGER.info(".\\ Available Consumer List \\.______________________________");
for (Map.Entry<String, KnownRepositoryContentConsumer> entry : availableConsumers.entrySet()) {
String consumerHint = entry.getKey();
RepositoryContentConsumer consumer = entry.getValue();
//
LOGGER.info(//
" {} : {} ({})", consumerHint, consumer.getDescription(), consumer.getClass().getName());
}
}
use of org.apache.archiva.consumers.KnownRepositoryContentConsumer in project archiva by apache.
the class ArchivaCli method doScan.
private void doScan(String path, String[] consumers) throws ConsumerException, MalformedURLException {
BasicManagedRepository repo = new BasicManagedRepository(Paths.get(path).getFileName().toString(), "Archiva CLI Provided Repo", Paths.get(path).getParent());
repo.setLocation(Paths.get(path).toUri());
List<KnownRepositoryContentConsumer> knownConsumerList = new ArrayList<>();
knownConsumerList.addAll(getConsumerList(consumers));
List<InvalidRepositoryContentConsumer> invalidConsumerList = Collections.emptyList();
List<String> ignoredContent = new ArrayList<>();
ignoredContent.addAll(Arrays.asList(RepositoryScanner.IGNORABLE_CONTENT));
RepositoryScanner scanner = applicationContext.getBean(RepositoryScanner.class);
try {
RepositoryScanStatistics stats = scanner.scan(repo, knownConsumerList, invalidConsumerList, ignoredContent, RepositoryScanner.FRESH_SCAN);
LOGGER.info(stats.toDump(repo));
} catch (RepositoryScannerException e) {
LOGGER.error(e.getMessage(), e);
}
}
use of org.apache.archiva.consumers.KnownRepositoryContentConsumer in project archiva by apache.
the class RepositoryPurgeConsumerTest method assertNotConsumed.
@SuppressWarnings("deprecation")
private void assertNotConsumed(String path) throws Exception {
ArchivaConfiguration archivaConfiguration = applicationContext.getBean("archivaConfiguration#default", ArchivaConfiguration.class);
FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get(0);
assertEquals(FileTypes.ARTIFACTS, fileType.getId());
fileType.addPattern("**/*.xml");
// FileTypes fileTypes = applicationContext.getBean( FileTypes.class );
for (FileTypes fileTypes : applicationContext.getBeansOfType(FileTypes.class).values()) {
fileTypes.afterConfigurationChange(null, "repositoryScanning.fileTypes", null);
}
KnownRepositoryContentConsumer repoPurgeConsumer = applicationContext.getBean("knownRepositoryContentConsumer#repository-purge", KnownRepositoryContentConsumer.class);
Path repoLocation = Paths.get("target/test-" + getName() + "/test-repo");
Path localFile = repoLocation.resolve(path);
ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
BaseFile baseFile = new BaseFile(repoLocation.toFile(), localFile.toFile());
predicate.setBasefile(baseFile);
assertFalse(predicate.evaluate(repoPurgeConsumer));
}
use of org.apache.archiva.consumers.KnownRepositoryContentConsumer 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);
}
Aggregations