Search in sources :

Example 11 with ExcludeSpec

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec 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)

Example 12 with ExcludeSpec

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

the class Unions method tryGroupUnion.

private ExcludeSpec tryGroupUnion(GroupExclude left, ExcludeSpec right) {
    String leftGroup = left.getGroup();
    if (right instanceof ModuleIdExclude) {
        ModuleIdExclude mie = (ModuleIdExclude) right;
        if (mie.getModuleId().getGroup().equals(leftGroup)) {
            return left;
        }
    }
    if (right instanceof ModuleIdSetExclude) {
        ModuleIdSetExclude ids = (ModuleIdSetExclude) right;
        Set<ModuleIdentifier> items = ids.getModuleIds().stream().filter(id -> !id.getGroup().equals(leftGroup)).collect(Collectors.toSet());
        if (items.size() == 1) {
            return factory.anyOf(left, factory.moduleId(items.iterator().next()));
        }
        if (items.isEmpty()) {
            return left;
        }
        if (items.size() != ids.getModuleIds().size()) {
            return factory.anyOf(left, factory.moduleIdSet(items));
        }
    }
    return null;
}
Also used : GroupExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupExclude) ModuleSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleSetExclude) ModuleIdExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdExclude) GroupSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupSetExclude) ModuleExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleExclude) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) ModuleIdSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdSetExclude) Set(java.util.Set) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec) Collectors(java.util.stream.Collectors) ModuleIdExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdExclude) ModuleIdSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdSetExclude) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 13 with ExcludeSpec

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

the class Unions method tryModuleSetUnion.

private ExcludeSpec tryModuleSetUnion(ModuleSetExclude left, ExcludeSpec right) {
    Set<String> leftModules = left.getModules();
    if (right instanceof ModuleIdExclude) {
        ModuleIdExclude mie = (ModuleIdExclude) right;
        if (leftModules.contains(mie.getModuleId().getName())) {
            return left;
        }
    }
    if (right instanceof ModuleIdSetExclude) {
        ModuleIdSetExclude ids = (ModuleIdSetExclude) right;
        Set<ModuleIdentifier> items = ids.getModuleIds().stream().filter(id -> !leftModules.contains(id.getName())).collect(Collectors.toSet());
        if (items.size() == 1) {
            return factory.anyOf(left, factory.moduleId(items.iterator().next()));
        }
        if (items.isEmpty()) {
            return left;
        }
        if (items.size() != ids.getModuleIds().size()) {
            return factory.anyOf(left, factory.moduleIdSet(items));
        }
    }
    return null;
}
Also used : GroupExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupExclude) ModuleSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleSetExclude) ModuleIdExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdExclude) GroupSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupSetExclude) ModuleExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleExclude) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) ModuleIdSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdSetExclude) Set(java.util.Set) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec) Collectors(java.util.stream.Collectors) ModuleIdExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdExclude) ModuleIdSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdSetExclude) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 14 with ExcludeSpec

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

the class NodeState method computeModuleExclusionsManyEdges.

private ExcludeSpec computeModuleExclusionsManyEdges(List<EdgeState> incomingEdges, ExcludeSpec nodeExclusions, int incomingEdgeCount) {
    ExcludeSpec nothing = moduleExclusions.nothing();
    ExcludeSpec edgeExclusions = null;
    Set<ExcludeSpec> excludedByBoth = null;
    Set<ExcludeSpec> excludedByEither = null;
    for (EdgeState dependencyEdge : incomingEdges) {
        if (dependencyEdge.isTransitive()) {
            if (edgeExclusions != nothing) {
                // Transitive dependency
                ExcludeSpec exclusions = dependencyEdge.getExclusions();
                if (edgeExclusions == null || exclusions == nothing) {
                    edgeExclusions = exclusions;
                } else if (edgeExclusions != exclusions) {
                    if (excludedByBoth == null) {
                        excludedByBoth = Sets.newHashSetWithExpectedSize(incomingEdgeCount);
                    }
                    excludedByBoth.add(exclusions);
                }
                if (edgeExclusions == nothing) {
                    // if exclusions == nothing, then the intersection will be "nothing"
                    excludedByBoth = null;
                }
            }
        } else if (isConstraint(dependencyEdge)) {
            excludedByEither = collectEdgeConstraint(nodeExclusions, excludedByEither, dependencyEdge, nothing, incomingEdgeCount);
        }
    }
    edgeExclusions = intersectEdgeExclusions(edgeExclusions, excludedByBoth);
    nodeExclusions = joinNodeExclusions(nodeExclusions, excludedByEither);
    return joinEdgeAndNodeExclusionsThenCacheResult(nodeExclusions, edgeExclusions, incomingEdgeCount);
}
Also used : ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)

Example 15 with ExcludeSpec

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

the class NodeState method visitOutgoingDependencies.

/**
 * Visits all of the dependencies that originate on this node, adding them as outgoing edges.
 * The {@link #outgoingEdges} collection is populated, as is the `discoveredEdges` parameter.
 *
 * @param discoveredEdges A collector for visited edges.
 */
public void visitOutgoingDependencies(Collection<EdgeState> discoveredEdges) {
    if (!component.isSelected()) {
        LOGGER.debug("version for {} is not selected. ignoring.", this);
        cleanupConstraints();
        return;
    }
    // Check if there are any transitive incoming edges at all. Don't traverse if not.
    if (transitiveEdgeCount == 0 && !isRoot() && canIgnoreExternalVariant()) {
        handleNonTransitiveNode(discoveredEdges);
        return;
    }
    // Determine the net exclusion for this node, by inspecting all transitive incoming edges
    ExcludeSpec resolutionFilter = computeModuleResolutionFilter(incomingEdges);
    // Virtual platforms require their constraints to be recomputed each time as each module addition can cause a shift in versions
    if (!isVirtualPlatformNeedsRefresh()) {
        // Check if node was previously traversed with the same net exclusion when not a virtual platform
        if (excludesSameDependenciesAsPreviousTraversal(resolutionFilter)) {
            boolean newConstraints = handleNewConstraints(discoveredEdges);
            boolean edgesToRecompute = handleEdgesToRecompute(discoveredEdges);
            if (!newConstraints && !edgesToRecompute) {
                // Was previously traversed, and no change to the set of modules that are linked by outgoing edges.
                // Don't need to traverse again, but hang on to the new filter since it may change the set of excluded artifacts.
                LOGGER.debug("Changed edges for {} selects same versions as previous traversal. ignoring", this);
            }
            previousTraversalExclusions = resolutionFilter;
            return;
        }
    }
    // Clear previous traversal state, if any
    if (previousTraversalExclusions != null) {
        removeOutgoingEdges();
        upcomingNoLongerPendingConstraints = null;
        edgesToRecompute = null;
        potentiallyActivatedConstraints = null;
        ownStrictVersionConstraints = null;
    }
    visitDependencies(resolutionFilter, discoveredEdges);
    visitOwners(discoveredEdges);
}
Also used : ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)

Aggregations

ExcludeSpec (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)16 Set (java.util.Set)5 GroupExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupExclude)5 GroupSetExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupSetExclude)5 ModuleExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleExclude)5 ModuleIdExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdExclude)5 ModuleIdSetExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdSetExclude)5 ModuleSetExclude (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleSetExclude)5 Collectors (java.util.stream.Collectors)4 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)4 Objects (java.util.Objects)3 ExcludeAnyOf (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeAnyOf)3 ExcludeNothing (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeNothing)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 List (java.util.List)2 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)2 ExcludeEverything (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeEverything)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)2