Search in sources :

Example 1 with InvalidRepositoryContentConsumer

use of org.apache.archiva.consumers.InvalidRepositoryContentConsumer in project archiva by apache.

the class DefaultLegacyRepositoryConverter method convertLegacyRepository.

@Override
public void convertLegacyRepository(Path legacyRepositoryDirectory, Path repositoryDirectory, List<String> fileExclusionPatterns) throws RepositoryConversionException {
    try {
        String defaultRepositoryUrl = PathUtil.toUrl(repositoryDirectory);
        BasicManagedRepository legacyRepository = new BasicManagedRepository("legacy", "Legacy Repository", repositoryDirectory.getParent());
        legacyRepository.setLocation(legacyRepositoryDirectory.toAbsolutePath().toUri());
        legacyRepository.setLayout("legacy");
        ArtifactRepository repository = artifactRepositoryFactory.createArtifactRepository("default", defaultRepositoryUrl, defaultLayout, null, null);
        legacyConverterConsumer.setExcludes(fileExclusionPatterns);
        legacyConverterConsumer.setDestinationRepository(repository);
        List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>(1);
        knownConsumers.add(legacyConverterConsumer);
        List<InvalidRepositoryContentConsumer> invalidConsumers = Collections.emptyList();
        List<String> ignoredContent = new ArrayList<String>(Arrays.asList(RepositoryScanner.IGNORABLE_CONTENT));
        repoScanner.scan(legacyRepository, knownConsumers, invalidConsumers, ignoredContent, RepositoryScanner.FRESH_SCAN);
    } catch (RepositoryScannerException e) {
        throw new RepositoryConversionException("Error convering legacy repository.", e);
    }
}
Also used : BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) RepositoryScannerException(org.apache.archiva.repository.scanner.RepositoryScannerException) RepositoryConversionException(org.apache.archiva.converter.RepositoryConversionException) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer)

Example 2 with InvalidRepositoryContentConsumer

use of org.apache.archiva.consumers.InvalidRepositoryContentConsumer in project archiva by apache.

the class RepositoryContentConsumers method executeConsumers.

/**
 * A convienence method to execute all of the active selected consumers for a
 * particular arbitrary file.
 * NOTE: Make sure that there is no repository scanning task executing before invoking this so as to prevent
 * the index writer/reader of the current index-content consumer executing from getting closed. For an example,
 * see ArchivaDavResource#executeConsumers( File ).
 *
 * @param repository             the repository configuration to use.
 * @param localFile              the local file to execute the consumers against.
 * @param updateRelatedArtifacts TODO
 */
public void executeConsumers(ManagedRepository repository, Path localFile, boolean updateRelatedArtifacts) throws RepositoryAdminException {
    List<KnownRepositoryContentConsumer> selectedKnownConsumers = null;
    // Run the repository consumers
    try {
        Closure<RepositoryContentConsumer> triggerBeginScan = new TriggerBeginScanClosure(repository, getStartTime(), false);
        selectedKnownConsumers = getSelectedKnownConsumers();
        // - do not create missing/fix invalid checksums and update metadata when deploying from webdav since these are uploaded by maven
        if (!updateRelatedArtifacts) {
            List<KnownRepositoryContentConsumer> clone = new ArrayList<>();
            clone.addAll(selectedKnownConsumers);
            for (KnownRepositoryContentConsumer consumer : clone) {
                if (consumer.getId().equals("create-missing-checksums") || consumer.getId().equals("metadata-updater")) {
                    selectedKnownConsumers.remove(consumer);
                }
            }
        }
        List<InvalidRepositoryContentConsumer> selectedInvalidConsumers = getSelectedInvalidConsumers();
        IterableUtils.forEach(selectedKnownConsumers, triggerBeginScan);
        IterableUtils.forEach(selectedInvalidConsumers, triggerBeginScan);
        // yuck. In case you can't read this, it says
        // "process the file if the consumer has it in the includes list, and not in the excludes list"
        Path repoPath = PathUtil.getPathFromUri(repository.getLocation());
        BaseFile baseFile = new BaseFile(repoPath.toString(), localFile.toFile());
        ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(repository);
        predicate.setBasefile(baseFile);
        predicate.setCaseSensitive(false);
        ConsumerProcessFileClosure closure = new ConsumerProcessFileClosure();
        closure.setBasefile(baseFile);
        closure.setExecuteOnEntireRepo(false);
        Closure<RepositoryContentConsumer> processIfWanted = IfClosure.ifClosure(predicate, closure);
        IterableUtils.forEach(selectedKnownConsumers, processIfWanted);
        if (predicate.getWantedFileCount() <= 0) {
            // Nothing known processed this file.  It is invalid!
            IterableUtils.forEach(selectedInvalidConsumers, closure);
        }
        TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure(repository, false);
        IterableUtils.forEach(selectedKnownConsumers, scanCompletedClosure);
    } finally {
        /* TODO: This is never called by the repository scanner instance, so not calling here either - but it probably should be?
                        IterableUtils.forEach( availableKnownConsumers, triggerCompleteScan );
                        IterableUtils.forEach( availableInvalidConsumers, triggerCompleteScan );
            */
        releaseSelectedKnownConsumers(selectedKnownConsumers);
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) ConsumerWantsFilePredicate(org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate) TriggerBeginScanClosure(org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) BaseFile(org.apache.archiva.common.utils.BaseFile) TriggerScanCompletedClosure(org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure) RepositoryContentConsumer(org.apache.archiva.consumers.RepositoryContentConsumer) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer) ConsumerProcessFileClosure(org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer)

Example 3 with InvalidRepositoryContentConsumer

use of org.apache.archiva.consumers.InvalidRepositoryContentConsumer in project archiva by apache.

the class RepositoryContentConsumersTest method testGetAvailableInvalidList.

@Test
public void testGetAvailableInvalidList() throws Exception {
    RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();
    String[] expectedInvalidIds = new String[] { "update-db-bad-content", "move-to-trash-then-notify" };
    List<InvalidRepositoryContentConsumer> invalidConsumers = consumerutil.getAvailableInvalidConsumers();
    assertNotNull("invalid consumers should not be null.", invalidConsumers);
    assertEquals("invalid consumers", expectedInvalidIds.length, invalidConsumers.size());
    List<String> expectedIds = Arrays.asList(expectedInvalidIds);
    for (InvalidRepositoryContentConsumer consumer : invalidConsumers) {
        assertTrue("Consumer [" + consumer.getId() + "] returned by .getAvailableInvalidConsumers() is unexpected.", expectedIds.contains(consumer.getId()));
    }
}
Also used : InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer) Test(org.junit.Test)

Example 4 with InvalidRepositoryContentConsumer

use of org.apache.archiva.consumers.InvalidRepositoryContentConsumer in project archiva by apache.

the class RepositoryScannerTest method testDefaultRepositoryMetadataScanner.

@Test
public void testDefaultRepositoryMetadataScanner() throws Exception {
    List<String> actualMetadataPaths = new ArrayList<>();
    actualMetadataPaths.add("org/apache/maven/some-ejb/1.0/maven-metadata.xml");
    actualMetadataPaths.add("org/apache/maven/update/test-not-updated/maven-metadata.xml");
    actualMetadataPaths.add("org/apache/maven/update/test-updated/maven-metadata.xml");
    actualMetadataPaths.add("org/apache/maven/maven-metadata.xml");
    actualMetadataPaths.add("org/apache/testgroup/discovery/1.0/maven-metadata.xml");
    actualMetadataPaths.add("org/apache/testgroup/discovery/maven-metadata.xml");
    actualMetadataPaths.add("javax/sql/jdbc/2.0/maven-metadata-repository.xml");
    actualMetadataPaths.add("javax/sql/jdbc/maven-metadata-repository.xml");
    actualMetadataPaths.add("javax/sql/maven-metadata-repository.xml");
    actualMetadataPaths.add("javax/maven-metadata.xml");
    ManagedRepository repository = createDefaultRepository();
    List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>();
    KnownScanConsumer knownConsumer = new KnownScanConsumer();
    knownConsumer.setIncludes(new String[] { "**/maven-metadata*.xml" });
    knownConsumers.add(knownConsumer);
    List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<>();
    InvalidScanConsumer badconsumer = new InvalidScanConsumer();
    invalidConsumers.add(badconsumer);
    RepositoryScanner scanner = lookupRepositoryScanner();
    RepositoryScanStatistics stats = scanner.scan(repository, knownConsumers, invalidConsumers, getIgnoreList(), RepositoryScanner.FRESH_SCAN);
    assertNotNull("Stats should not be null.", stats);
    assertMinimumHits("Stats.totalFileCount", actualMetadataPaths.size(), stats.getTotalFileCount());
    assertMinimumHits("Processed Count", actualMetadataPaths.size(), knownConsumer.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 5 with InvalidRepositoryContentConsumer

use of org.apache.archiva.consumers.InvalidRepositoryContentConsumer in project archiva by apache.

the class RepositoryScannerTest method testLegacyRepositoryArtifactScanner.

@Test
public void testLegacyRepositoryArtifactScanner() throws Exception {
    List<String> actualArtifactPaths = new ArrayList<>();
    actualArtifactPaths.add("invalid/jars/1.0/invalid-1.0.jar");
    actualArtifactPaths.add("invalid/jars/invalid-1.0.rar");
    actualArtifactPaths.add("invalid/jars/invalid.jar");
    actualArtifactPaths.add("invalid/invalid-1.0.jar");
    actualArtifactPaths.add("javax.sql/jars/jdbc-2.0.jar");
    actualArtifactPaths.add("org.apache.maven/jars/some-ejb-1.0-client.jar");
    actualArtifactPaths.add("org.apache.maven/jars/testing-1.0.jar");
    actualArtifactPaths.add("org.apache.maven/jars/testing-1.0-sources.jar");
    actualArtifactPaths.add("org.apache.maven/jars/testing-UNKNOWN.jar");
    actualArtifactPaths.add("org.apache.maven/jars/testing-1.0.zip");
    actualArtifactPaths.add("org.apache.maven/jars/testing-1.0-20050611.112233-1.jar");
    actualArtifactPaths.add("org.apache.maven/jars/testing-1.0.tar.gz");
    actualArtifactPaths.add("org.apache.maven.update/jars/test-not-updated-1.0.jar");
    actualArtifactPaths.add("org.apache.maven.update/jars/test-updated-1.0.jar");
    ManagedRepository repository = createLegacyRepository();
    List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>();
    KnownScanConsumer consumer = new KnownScanConsumer();
    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(), RepositoryScanner.FRESH_SCAN);
    assertNotNull("Stats should not be null.", stats);
    assertMinimumHits("Stats.totalFileCount", actualArtifactPaths.size(), stats.getTotalFileCount());
    assertMinimumHits("Processed Count", actualArtifactPaths.size(), consumer.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)

Aggregations

InvalidRepositoryContentConsumer (org.apache.archiva.consumers.InvalidRepositoryContentConsumer)15 ArrayList (java.util.ArrayList)12 KnownRepositoryContentConsumer (org.apache.archiva.consumers.KnownRepositoryContentConsumer)12 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)11 Test (org.junit.Test)11 ManagedRepository (org.apache.archiva.repository.ManagedRepository)9 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)8 Path (java.nio.file.Path)2 RepositoryScannerException (org.apache.archiva.repository.scanner.RepositoryScannerException)2 Date (java.util.Date)1 BaseFile (org.apache.archiva.common.utils.BaseFile)1 RepositoryContentConsumer (org.apache.archiva.consumers.RepositoryContentConsumer)1 ConsumerWantsFilePredicate (org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate)1 RepositoryConversionException (org.apache.archiva.converter.RepositoryConversionException)1 RepositoryScanStatistics (org.apache.archiva.repository.scanner.RepositoryScanStatistics)1 RepositoryScanner (org.apache.archiva.repository.scanner.RepositoryScanner)1 ConsumerProcessFileClosure (org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure)1 TriggerBeginScanClosure (org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure)1 TriggerScanCompletedClosure (org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1