Search in sources :

Example 6 with KnownRepositoryContentConsumer

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());
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) ArrayList(java.util.ArrayList) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer) Test(org.junit.Test)

Example 7 with KnownRepositoryContentConsumer

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());
    }
}
Also used : KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) RepositoryContentConsumer(org.apache.archiva.consumers.RepositoryContentConsumer) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with KnownRepositoryContentConsumer

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);
    }
}
Also used : BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) RepositoryScanner(org.apache.archiva.repository.scanner.RepositoryScanner) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) RepositoryScanStatistics(org.apache.archiva.repository.scanner.RepositoryScanStatistics) ArrayList(java.util.ArrayList) RepositoryScannerException(org.apache.archiva.repository.scanner.RepositoryScannerException) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer)

Example 9 with KnownRepositoryContentConsumer

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));
}
Also used : Path(java.nio.file.Path) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) FileType(org.apache.archiva.configuration.FileType) BaseFile(org.apache.archiva.common.utils.BaseFile) FileTypes(org.apache.archiva.configuration.FileTypes) ConsumerWantsFilePredicate(org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration)

Example 10 with KnownRepositoryContentConsumer

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);
}
Also used : Path(java.nio.file.Path) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Aggregations

KnownRepositoryContentConsumer (org.apache.archiva.consumers.KnownRepositoryContentConsumer)22 Test (org.junit.Test)15 InvalidRepositoryContentConsumer (org.apache.archiva.consumers.InvalidRepositoryContentConsumer)13 ArrayList (java.util.ArrayList)12 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)12 ManagedRepository (org.apache.archiva.repository.ManagedRepository)9 Path (java.nio.file.Path)8 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)8 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)4 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)4 HashSet (java.util.HashSet)2 BaseFile (org.apache.archiva.common.utils.BaseFile)2 RepositoryContentConsumer (org.apache.archiva.consumers.RepositoryContentConsumer)2 ConsumerWantsFilePredicate (org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate)2 RepositoryScannerException (org.apache.archiva.repository.scanner.RepositoryScannerException)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)1 FileType (org.apache.archiva.configuration.FileType)1