org.apache.commons.collections4.Closure Java Examples

The following examples show how to use org.apache.commons.collections4.Closure. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryScannerInstance.java    From archiva with Apache License 2.0 5 votes vote down vote up
public RepositoryScannerInstance( ManagedRepository repository,
                                  List<KnownRepositoryContentConsumer> knownConsumerList,
                                  List<InvalidRepositoryContentConsumer> invalidConsumerList )
{
    this.repository = repository;
    this.knownConsumers = knownConsumerList;
    this.invalidConsumers = invalidConsumerList;

    addFileNameIncludePattern("**/*");

    consumerTimings = new HashMap<>();
    consumerCounts = new HashMap<>();

    this.consumerProcessFile = new ConsumerProcessFileClosure();
    consumerProcessFile.setExecuteOnEntireRepo( true );
    consumerProcessFile.setConsumerTimings( consumerTimings );
    consumerProcessFile.setConsumerCounts( consumerCounts );

    this.consumerWantsFile = new ConsumerWantsFilePredicate( repository );

    stats = new RepositoryScanStatistics();
    stats.setRepositoryId( repository.getId() );

    Closure<RepositoryContentConsumer> triggerBeginScan =
        new TriggerBeginScanClosure( repository, new Date( System.currentTimeMillis() ), true );

    IterableUtils.forEach( knownConsumerList, triggerBeginScan );
    IterableUtils.forEach( invalidConsumerList, triggerBeginScan );

    if ( SystemUtils.IS_OS_WINDOWS )
    {
        consumerWantsFile.setCaseSensitive( false );
    }
}
 
Example #2
Source File: RepositoryScannerInstance.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    final Path relativeFile = basePath.relativize( file );
    if (excludeMatcher.stream().noneMatch(m -> m.matches(relativeFile)) && includeMatcher.stream().allMatch(m -> m.matches(relativeFile))) {
        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;
}
 
Example #3
Source File: DefaultPluginJarLocationMonitor.java    From gocd with Apache License 2.0 5 votes vote down vote up
private void doOnAllPluginJarChangeListener(Closure<PluginJarChangeListener> closure) {
    for (WeakReference<PluginJarChangeListener> listener : listeners) {
        PluginJarChangeListener changeListener = listener.get();
        if (changeListener == null) {
            continue;
        }

        try {
            closure.execute(changeListener);
        } catch (Exception e) {
            LOGGER.warn("Plugin listener failed", e);
        }
    }
}
 
Example #4
Source File: RepositoryContentConsumers.java    From archiva with Apache License 2.0 4 votes vote down vote up
/**
 * 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 ConsumerException
{
    List<KnownRepositoryContentConsumer> selectedKnownConsumers = null;
    // Run the repository consumers
    try
    {
        Closure<RepositoryContentConsumer> triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime(), false );

        selectedKnownConsumers = getSelectedKnownConsumers();

        // MRM-1212/MRM-1197 
        // - 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 );
    }
}