Search in sources :

Example 1 with ModuleIdExclude

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

the class Unions method tryModuleUnion.

private ExcludeSpec tryModuleUnion(ModuleExclude left, ExcludeSpec right) {
    String leftModule = left.getModule();
    if (right instanceof ModuleIdExclude) {
        ModuleIdExclude mie = (ModuleIdExclude) right;
        if (mie.getModuleId().getName().equals(leftModule)) {
            return left;
        }
    }
    if (right instanceof ModuleIdSetExclude) {
        ModuleIdSetExclude ids = (ModuleIdSetExclude) right;
        Set<ModuleIdentifier> items = ids.getModuleIds().stream().filter(id -> !id.getName().equals(leftModule)).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 2 with ModuleIdExclude

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

the class Unions method tryGroupSetUnion.

private ExcludeSpec tryGroupSetUnion(GroupSetExclude left, ExcludeSpec right) {
    Set<String> leftGroups = left.getGroups();
    if (right instanceof ModuleIdExclude) {
        ModuleIdExclude mie = (ModuleIdExclude) right;
        if (leftGroups.contains(mie.getModuleId().getGroup())) {
            return left;
        }
    }
    if (right instanceof ModuleIdSetExclude) {
        ModuleIdSetExclude ids = (ModuleIdSetExclude) right;
        Set<ModuleIdentifier> items = ids.getModuleIds().stream().filter(id -> !leftGroups.contains(id.getGroup())).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 3 with ModuleIdExclude

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

the class NormalizingExcludeFactory method doUnion.

private ExcludeSpec doUnion(Set<ExcludeSpec> specs) {
    specs = simplifySet(ExcludeAllOf.class, specs);
    FlattenOperationResult flattened = flatten(ExcludeAnyOf.class, specs, ExcludeEverything.class::isInstance, ExcludeNothing.class::isInstance);
    if (flattened.fastExit) {
        return everything();
    }
    if (flattened.result.isEmpty()) {
        return nothing();
    }
    Map<UnionOf, List<ExcludeSpec>> byType = flattened.result.stream().collect(Collectors.groupingBy(UnionOf::typeOf));
    List<ModuleIdExclude> moduleIdExcludes = UnionOf.MODULEID.fromMap(byType);
    List<ModuleIdSetExclude> moduleIdSetsExcludes = UnionOf.MODULEID_SET.fromMap(byType);
    List<GroupExclude> groupExcludes = UnionOf.GROUP.fromMap(byType);
    List<GroupSetExclude> groupSetExcludes = UnionOf.GROUP_SET.fromMap(byType);
    List<ModuleExclude> moduleExcludes = UnionOf.MODULE.fromMap(byType);
    List<ModuleSetExclude> moduleSetExcludes = UnionOf.MODULE_SET.fromMap(byType);
    List<ExcludeSpec> other = UnionOf.NOT_JOINABLE.fromMap(byType);
    if (!moduleIdExcludes.isEmpty()) {
        // If there's more than one module id, merge them into a module id set
        if (moduleIdExcludes.size() > 1 || !moduleIdSetsExcludes.isEmpty()) {
            ModuleIdSetExclude excludeSpec = delegate.moduleIdSet(moduleIdExcludes.stream().map(ModuleIdExclude::getModuleId).collect(toSet()));
            if (moduleIdSetsExcludes.isEmpty()) {
                moduleIdSetsExcludes = ImmutableList.of(excludeSpec);
            } else {
                moduleIdSetsExcludes.add(excludeSpec);
            }
            moduleIdExcludes = Collections.emptyList();
        }
    }
    if (!groupExcludes.isEmpty()) {
        // If there's more than group, merge them into a group set
        if (groupExcludes.size() > 1 || !groupSetExcludes.isEmpty()) {
            GroupSetExclude excludeSpec = delegate.groupSet(groupExcludes.stream().map(GroupExclude::getGroup).collect(toSet()));
            if (groupSetExcludes.isEmpty()) {
                groupSetExcludes = ImmutableList.of(excludeSpec);
            } else {
                groupSetExcludes.add(excludeSpec);
            }
            groupExcludes = Collections.emptyList();
        }
    }
    if (!moduleExcludes.isEmpty()) {
        // If there's more than one module, merge them into a module set
        if (moduleExcludes.size() > 1 || !moduleSetExcludes.isEmpty()) {
            ModuleSetExclude excludeSpec = delegate.moduleSet(moduleExcludes.stream().map(ModuleExclude::getModule).collect(toSet()));
            if (moduleSetExcludes.isEmpty()) {
                moduleSetExcludes = ImmutableList.of(excludeSpec);
            } else {
                moduleSetExcludes.add(excludeSpec);
            }
            moduleExcludes = Collections.emptyList();
        }
    }
    if (moduleIdSetsExcludes.size() > 1) {
        moduleIdSetsExcludes = ImmutableList.of(delegate.moduleIdSet(moduleIdSetsExcludes.stream().flatMap(e -> e.getModuleIds().stream()).collect(toSet())));
    }
    if (groupSetExcludes.size() > 1) {
        groupSetExcludes = ImmutableList.of(delegate.groupSet(groupSetExcludes.stream().flatMap(e -> e.getGroups().stream()).collect(toSet())));
    }
    if (moduleSetExcludes.size() > 1) {
        moduleSetExcludes = ImmutableList.of(delegate.moduleSet(moduleSetExcludes.stream().flatMap(e -> e.getModules().stream()).collect(toSet())));
    }
    ImmutableSet.Builder<ExcludeSpec> builder = ImmutableSet.builderWithExpectedSize(moduleIdExcludes.size() + groupExcludes.size() + moduleExcludes.size() + moduleIdSetsExcludes.size() + groupSetExcludes.size() + moduleSetExcludes.size() + other.size());
    builder.addAll(moduleIdExcludes);
    builder.addAll(groupExcludes);
    builder.addAll(moduleExcludes);
    builder.addAll(moduleIdSetsExcludes);
    builder.addAll(groupSetExcludes);
    builder.addAll(moduleSetExcludes);
    builder.addAll(other);
    Set<ExcludeSpec> elements = builder.build();
    if (elements.size() > 1) {
        // try simplify
        ExcludeSpec[] asArray = elements.toArray(new ExcludeSpec[0]);
        boolean simplified = false;
        for (int i = 0; i < asArray.length; i++) {
            ExcludeSpec left = asArray[i];
            if (left != null) {
                for (int j = 0; j < asArray.length; j++) {
                    ExcludeSpec right = asArray[j];
                    if (right != null && i != j) {
                        ExcludeSpec merged = unions.tryUnion(left, right);
                        if (merged != null) {
                            if (merged instanceof ExcludeEverything) {
                                return merged;
                            }
                            left = merged;
                            asArray[i] = merged;
                            asArray[j] = null;
                            simplified = true;
                        }
                    }
                }
            }
        }
        if (simplified) {
            elements = Arrays.stream(asArray).filter(Objects::nonNull).collect(toSet());
        }
    }
    if (elements.size() == 2) {
        // Corner case to handle one of the two elements being an anyOf
        Iterator<ExcludeSpec> specIterator = elements.iterator();
        ExcludeSpec first = specIterator.next();
        ExcludeSpec second = specIterator.next();
        if (first instanceof ExcludeAnyOf || second instanceof ExcludeAnyOf) {
            ImmutableSet.Builder<ExcludeSpec> newBuilder = ImmutableSet.builder();
            if (first instanceof ExcludeAnyOf) {
                newBuilder.addAll(((ExcludeAnyOf) first).getComponents());
            } else {
                builder.add(first);
            }
            if (second instanceof ExcludeAnyOf) {
                newBuilder.addAll(((ExcludeAnyOf) second).getComponents());
            } else {
                builder.add(second);
            }
            elements = builder.build();
        }
    }
    return Optimizations.optimizeCollection(this, elements, delegate::anyOf);
}
Also used : ModuleSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleSetExclude) GroupExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupExclude) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec) ExcludeNothing(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeNothing) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ExcludeEverything(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeEverything) ExcludeAnyOf(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeAnyOf) ModuleIdExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdExclude) ModuleIdSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleIdSetExclude) GroupSetExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.GroupSetExclude) ModuleExclude(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ModuleExclude) ExcludeAllOf(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeAllOf) Objects(java.util.Objects)

Example 4 with ModuleIdExclude

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

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

Aggregations

ExcludeSpec (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)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 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)4 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 List (java.util.List)1 Objects (java.util.Objects)1 ExcludeAllOf (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeAllOf)1 ExcludeAnyOf (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeAnyOf)1 ExcludeEverything (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeEverything)1 ExcludeNothing (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeNothing)1