Search in sources :

Example 1 with RepositoryContentConsumer

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

the class AddAdminRepoConsumerClosure method execute.

@Override
public void execute(RepositoryContentConsumer input) {
    RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
    boolean enabled = this.selectedIds.contains(consumer.getId());
    AdminRepositoryConsumer adminconsumer = new AdminRepositoryConsumer();
    adminconsumer.setEnabled(enabled);
    adminconsumer.setId(consumer.getId());
    adminconsumer.setDescription(consumer.getDescription());
    list.add(adminconsumer);
}
Also used : AdminRepositoryConsumer(org.apache.archiva.rest.api.model.AdminRepositoryConsumer) RepositoryContentConsumer(org.apache.archiva.consumers.RepositoryContentConsumer)

Example 2 with RepositoryContentConsumer

use of org.apache.archiva.consumers.RepositoryContentConsumer 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 RepositoryContentConsumer

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

the class RepositoryScannerInstance method visitFile.

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    if (excludeMatcher.stream().noneMatch(m -> m.matches(file)) && includeMatcher.stream().allMatch(m -> m.matches(file))) {
        log.debug("Walk Step: {}, {}", file);
        stats.increaseFileCount();
        // consume files regardless - the predicate will check the timestamp
        Path repoPath = PathUtil.getPathFromUri(repository.getLocation());
        BaseFile basefile = new BaseFile(repoPath.toString(), file.toFile());
        // Timestamp finished points to the last successful scan, not this current one.
        if (Files.getLastModifiedTime(file).toMillis() >= changesSince) {
            stats.increaseNewFileCount();
        }
        consumerProcessFile.setBasefile(basefile);
        consumerWantsFile.setBasefile(basefile);
        Closure<RepositoryContentConsumer> processIfWanted = IfClosure.ifClosure(consumerWantsFile, consumerProcessFile);
        IterableUtils.forEach(this.knownConsumers, processIfWanted);
        if (consumerWantsFile.getWantedFileCount() <= 0) {
            // Nothing known processed this file.  It is invalid!
            IterableUtils.forEach(this.invalidConsumers, consumerProcessFile);
        }
    }
    return FileVisitResult.CONTINUE;
}
Also used : PathUtil(org.apache.archiva.common.utils.PathUtil) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) IfClosure(org.apache.commons.collections4.functors.IfClosure) Closure(org.apache.commons.collections4.Closure) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) IterableUtils(org.apache.commons.collections4.IterableUtils) RepositoryContentConsumer(org.apache.archiva.consumers.RepositoryContentConsumer) Map(java.util.Map) PathMatcher(java.nio.file.PathMatcher) ConsumerWantsFilePredicate(org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate) SystemUtils(org.apache.commons.lang.SystemUtils) Path(java.nio.file.Path) TriggerBeginScanClosure(org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure) Logger(org.slf4j.Logger) FileVisitor(java.nio.file.FileVisitor) Files(java.nio.file.Files) ConsumerProcessFileClosure(org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) IOException(java.io.IOException) FileSystem(java.nio.file.FileSystem) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Collectors(java.util.stream.Collectors) ManagedRepository(org.apache.archiva.repository.ManagedRepository) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) BaseFile(org.apache.archiva.common.utils.BaseFile) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer) TriggerScanCompletedClosure(org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure) FileSystems(java.nio.file.FileSystems) Path(java.nio.file.Path) BaseFile(org.apache.archiva.common.utils.BaseFile) RepositoryContentConsumer(org.apache.archiva.consumers.RepositoryContentConsumer) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer)

Example 4 with RepositoryContentConsumer

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

the class TriggerScanCompletedClosure method execute.

@Override
public void execute(RepositoryContentConsumer input) {
    RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
    consumer.completeScan(executeOnEntireRepo);
    log.debug("Consumer [{}] completed for repository [{}]", consumer.getId(), repository.getId());
}
Also used : RepositoryContentConsumer(org.apache.archiva.consumers.RepositoryContentConsumer)

Example 5 with RepositoryContentConsumer

use of org.apache.archiva.consumers.RepositoryContentConsumer 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)

Aggregations

RepositoryContentConsumer (org.apache.archiva.consumers.RepositoryContentConsumer)7 InvalidRepositoryContentConsumer (org.apache.archiva.consumers.InvalidRepositoryContentConsumer)3 KnownRepositoryContentConsumer (org.apache.archiva.consumers.KnownRepositoryContentConsumer)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BaseFile (org.apache.archiva.common.utils.BaseFile)2 ConsumerWantsFilePredicate (org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate)2 ConsumerProcessFileClosure (org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure)2 TriggerBeginScanClosure (org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure)2 TriggerScanCompletedClosure (org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure)2 IOException (java.io.IOException)1 FileSystem (java.nio.file.FileSystem)1 FileSystems (java.nio.file.FileSystems)1 FileVisitResult (java.nio.file.FileVisitResult)1 FileVisitor (java.nio.file.FileVisitor)1 Files (java.nio.file.Files)1 PathMatcher (java.nio.file.PathMatcher)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1