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);
}
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;
}
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;
}
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);
}
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);
}
Aggregations