Search in sources :

Example 1 with CompositeExclude

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.CompositeExclude in project gradle by gradle.

the class NormalizingExcludeFactory method flatten.

/**
 * Flattens a collection of elements that are going to be joined or intersected. There
 * are 3 possible outcomes:
 * - null means that the fast exit condition was reached, meaning that the caller knows it's not worth computing more
 * - empty list meaning that an easy simplification was reached and we directly know the result
 * - flattened unions/intersections
 */
private <T extends ExcludeSpec> FlattenOperationResult flatten(Class<T> flattenType, Set<ExcludeSpec> specs, Predicate<ExcludeSpec> fastExit, Predicate<ExcludeSpec> ignoreSpec) {
    boolean filtered = false;
    boolean flatten = false;
    int size = 0;
    for (ExcludeSpec spec : specs) {
        if (fastExit.test(spec)) {
            return FlattenOperationResult.FAST_EXIT;
        }
        if (ignoreSpec.test(spec)) {
            filtered = true;
        } else if (flattenType.isInstance(spec)) {
            flatten = true;
            size += ((CompositeExclude) spec).size();
        } else {
            size++;
        }
    }
    if (!filtered && !flatten) {
        return FlattenOperationResult.of(specs);
    }
    if (filtered && !flatten) {
        return filterOnly(specs, ignoreSpec);
    }
    // slowest path
    return expensiveFlatten(flattenType, maybeFilter(specs, ignoreSpec, filtered), size);
}
Also used : CompositeExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.CompositeExclude) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)

Aggregations

CompositeExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.CompositeExclude)1 ExcludeSpec (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)1