Search in sources :

Example 6 with Pair

use of org.gradle.internal.Pair in project gradle by gradle.

the class AttributeMatchingVariantSelector method disambiguateWithSchema.

private List<Pair<ResolvedVariant, MutableConsumerVariantMatchResult.ConsumerVariant>> disambiguateWithSchema(AttributeMatcher matcher, List<Pair<ResolvedVariant, MutableConsumerVariantMatchResult.ConsumerVariant>> candidates, ImmutableAttributes componentRequested, AttributeMatchingExplanationBuilder explanationBuilder) {
    List<AttributeContainerInternal> candidateAttributes = candidates.stream().map(pair -> pair.getRight().attributes).collect(Collectors.toList());
    List<AttributeContainerInternal> matches = matcher.matches(candidateAttributes, componentRequested, explanationBuilder);
    if (matches.size() == 1) {
        AttributeContainerInternal singleMatch = matches.get(0);
        return candidates.stream().filter(pair -> pair.getRight().attributes.equals(singleMatch)).collect(Collectors.toList());
    } else if (matches.size() > 0 && matches.size() < candidates.size()) {
        // We know all are compatibles, so this is only possible if some disambiguation happens but not getting us to 1 candidate
        return candidates.stream().filter(pair -> matches.contains(pair.getRight().attributes)).collect(Collectors.toList());
    }
    return candidates;
}
Also used : BrokenResolvedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.BrokenResolvedArtifactSet) AttributesSchemaInternal(org.gradle.api.internal.attributes.AttributesSchemaInternal) AttributeMatcher(org.gradle.internal.component.model.AttributeMatcher) DescriberSelector(org.gradle.internal.component.model.DescriberSelector) ArrayList(java.util.ArrayList) Pair(org.gradle.internal.Pair) Lists(com.google.common.collect.Lists) Attribute(org.gradle.api.attributes.Attribute) AttributeDescriber(org.gradle.api.internal.attributes.AttributeDescriber) ResolvedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSet) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ResolvedVariant(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant) ResolvedVariantSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariantSet) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) Set(java.util.Set) Cast(org.gradle.internal.Cast) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) NoMatchingVariantSelectionException(org.gradle.internal.component.NoMatchingVariantSelectionException) AttributeMatchingExplanationBuilder(org.gradle.internal.component.model.AttributeMatchingExplanationBuilder) AttributeValue(org.gradle.api.internal.attributes.AttributeValue) Optional(java.util.Optional) VariantSelectionException(org.gradle.internal.component.VariantSelectionException) Comparator(java.util.Comparator) HasAttributes(org.gradle.api.attributes.HasAttributes) Collections(java.util.Collections) AmbiguousVariantSelectionException(org.gradle.internal.component.AmbiguousVariantSelectionException) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal)

Example 7 with Pair

use of org.gradle.internal.Pair in project gradle by gradle.

the class AmbiguousTransformException method format.

private static String format(String producerDisplayName, AttributeContainerInternal requested, List<Pair<ResolvedVariant, ConsumerVariantMatchResult.ConsumerVariant>> candidates) {
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("Found multiple transforms that can produce a variant of " + producerDisplayName + " with requested attributes");
    formatAttributes(formatter, requested);
    formatter.node("Found the following transforms");
    Map<ResolvedVariant, List<ConsumerVariantMatchResult.ConsumerVariant>> variantToTransforms = candidates.stream().collect(Collectors.toMap(Pair::getLeft, candidate -> Lists.newArrayList(candidate.getRight()), (List<ConsumerVariantMatchResult.ConsumerVariant> orig, List<ConsumerVariantMatchResult.ConsumerVariant> add) -> {
        orig.addAll(add);
        return orig;
    }, LinkedHashMap::new));
    formatter.startChildren();
    for (Map.Entry<ResolvedVariant, List<ConsumerVariantMatchResult.ConsumerVariant>> entry : variantToTransforms.entrySet()) {
        formatter.node("From '" + entry.getKey().asDescribable().getDisplayName() + "'");
        formatter.startChildren();
        formatter.node("With source attributes");
        formatAttributes(formatter, entry.getKey().getAttributes());
        formatter.node("Candidate transform(s)");
        formatter.startChildren();
        for (ConsumerVariantMatchResult.ConsumerVariant transform : entry.getValue()) {
            formatter.node("Transform '" + transform.transformation.getDisplayName() + "' producing attributes:");
            formatAttributes(formatter, transform.attributes);
        }
        formatter.endChildren();
        formatter.endChildren();
    }
    formatter.endChildren();
    return formatter.toString();
}
Also used : ResolvedVariant(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant) Pair(org.gradle.internal.Pair) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Lists(com.google.common.collect.Lists) AmbiguousVariantSelectionException.formatAttributes(org.gradle.internal.component.AmbiguousVariantSelectionException.formatAttributes) TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) Map(java.util.Map) VariantSelectionException(org.gradle.internal.component.VariantSelectionException) Collectors(java.util.stream.Collectors) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) ResolvedVariant(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Pair (org.gradle.internal.Pair)7 ResolvedVariant (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)4 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)4 ArrayList (java.util.ArrayList)3 AmbiguousVariantSelectionException (org.gradle.internal.component.AmbiguousVariantSelectionException)3 NoMatchingVariantSelectionException (org.gradle.internal.component.NoMatchingVariantSelectionException)3 AttributeMatcher (org.gradle.internal.component.model.AttributeMatcher)3 Lists (com.google.common.collect.Lists)2 File (java.io.File)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)2 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)2 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 AttributeDescriber (org.gradle.api.internal.attributes.AttributeDescriber)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 VariantSelectionException (org.gradle.internal.component.VariantSelectionException)2 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)2 Sets (com.google.common.collect.Sets)1 IOException (java.io.IOException)1