Search in sources :

Example 1 with Closure

use of org.apache.commons.collections4.Closure 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)

Aggregations

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 Path (java.nio.file.Path)1 PathMatcher (java.nio.file.PathMatcher)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 BaseFile (org.apache.archiva.common.utils.BaseFile)1 PathUtil (org.apache.archiva.common.utils.PathUtil)1 InvalidRepositoryContentConsumer (org.apache.archiva.consumers.InvalidRepositoryContentConsumer)1 KnownRepositoryContentConsumer (org.apache.archiva.consumers.KnownRepositoryContentConsumer)1 RepositoryContentConsumer (org.apache.archiva.consumers.RepositoryContentConsumer)1