Search in sources :

Example 1 with ResolvedVariant

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant in project gradle by gradle.

the class NoMatchingVariantSelectionException method format.

private static String format(String producerDisplayName, AttributeContainerInternal consumer, Collection<? extends ResolvedVariant> candidates, AttributeMatcher matcher) {
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("No variants of " + producerDisplayName + " match the consumer attributes");
    formatter.startChildren();
    for (ResolvedVariant variant : candidates) {
        formatter.node(variant.asDescribable().getCapitalizedDisplayName());
        formatAttributeMatches(formatter, consumer, matcher, variant.getAttributes());
    }
    formatter.endChildren();
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.text.TreeFormatter) ResolvedVariant(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)

Example 2 with ResolvedVariant

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant in project gradle by gradle.

the class AmbiguousVariantSelectionException method format.

private static String format(AttributeDescriber describer, String producerDisplayName, AttributeContainerInternal consumer, List<? extends ResolvedVariant> variants, AttributeMatcher matcher, Set<ResolvedVariant> discarded) {
    TreeFormatter formatter = new TreeFormatter();
    if (consumer.getAttributes().isEmpty()) {
        formatter.node("More than one variant of " + producerDisplayName + " matches the consumer attributes");
    } else {
        formatter.node("The consumer was configured to find " + describer.describeAttributeSet(consumer.asMap()) + ". However we cannot choose between the following variants of " + producerDisplayName);
    }
    formatter.startChildren();
    for (ResolvedVariant variant : variants) {
        formatter.node(variant.asDescribable().getCapitalizedDisplayName());
        formatAttributeMatchesForAmbiguity(formatter, consumer.asImmutable(), matcher, variant.getAttributes().asImmutable(), describer);
    }
    formatter.endChildren();
    if (!discarded.isEmpty()) {
        formatter.node("The following variants were also considered but didn't match the requested attributes:");
        formatter.startChildren();
        discarded.stream().sorted(Comparator.comparing(v -> v.asDescribable().getCapitalizedDisplayName())).forEach(discardedVariant -> {
            formatter.node(discardedVariant.asDescribable().getCapitalizedDisplayName());
            formatAttributeMatchesForIncompatibility(formatter, consumer.asImmutable(), matcher, discardedVariant.getAttributes().asImmutable(), describer);
        });
        formatter.endChildren();
    }
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) ResolvedVariant(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)

Example 3 with ResolvedVariant

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant in project gradle by gradle.

the class NoMatchingVariantSelectionException method format.

private static String format(String producerDisplayName, AttributeContainerInternal consumer, Collection<? extends ResolvedVariant> candidates, AttributeMatcher matcher, AttributeDescriber describer) {
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("No variants of " + style(StyledTextOutput.Style.Info, producerDisplayName) + " match the consumer attributes");
    formatter.startChildren();
    for (ResolvedVariant variant : candidates) {
        formatter.node(variant.asDescribable().getCapitalizedDisplayName());
        formatAttributeMatchesForIncompatibility(formatter, consumer.asImmutable(), matcher, variant.getAttributes().asImmutable(), describer);
    }
    formatter.endChildren();
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) ResolvedVariant(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)

Example 4 with ResolvedVariant

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant in project gradle by gradle.

the class AttributeMatchingVariantSelector method doSelect.

private ResolvedArtifactSet doSelect(ResolvedVariantSet producer) {
    AttributeMatcher matcher = schema.withProducer(producer.getSchema());
    List<? extends ResolvedVariant> matches = matcher.matches(producer.getVariants(), requested);
    if (matches.size() == 1) {
        return matches.get(0).getArtifacts();
    }
    if (matches.size() > 1) {
        throw new AmbiguousVariantSelectionException(producer.asDescribable().getDisplayName(), requested, matches, matcher);
    }
    List<Pair<ResolvedVariant, ConsumerVariantMatchResult.ConsumerVariant>> candidates = new ArrayList<Pair<ResolvedVariant, ConsumerVariantMatchResult.ConsumerVariant>>();
    for (ResolvedVariant variant : producer.getVariants()) {
        AttributeContainerInternal variantAttributes = variant.getAttributes().asImmutable();
        ConsumerVariantMatchResult matchResult = new ConsumerVariantMatchResult();
        consumerProvidedVariantFinder.collectConsumerVariants(variantAttributes, requested, matchResult);
        for (ConsumerVariantMatchResult.ConsumerVariant consumerVariant : matchResult.getMatches()) {
            candidates.add(Pair.of(variant, consumerVariant));
        }
    }
    if (candidates.size() == 1) {
        Pair<ResolvedVariant, ConsumerVariantMatchResult.ConsumerVariant> result = candidates.get(0);
        return new ConsumerProvidedResolvedVariant(result.getLeft().getArtifacts(), result.getRight().attributes, result.getRight().transformer);
    }
    if (!candidates.isEmpty()) {
        throw new AmbiguousTransformException(producer.asDescribable().getDisplayName(), requested, candidates);
    }
    if (ignoreWhenNoMatches) {
        return ResolvedArtifactSet.EMPTY;
    }
    throw new NoMatchingVariantSelectionException(producer.asDescribable().getDisplayName(), requested, producer.getVariants(), matcher);
}
Also used : AttributeMatcher(org.gradle.internal.component.model.AttributeMatcher) NoMatchingVariantSelectionException(org.gradle.internal.component.NoMatchingVariantSelectionException) ResolvedVariant(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant) ArrayList(java.util.ArrayList) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) AmbiguousVariantSelectionException(org.gradle.internal.component.AmbiguousVariantSelectionException) Pair(org.gradle.internal.Pair)

Example 5 with ResolvedVariant

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant in project gradle by gradle.

the class AmbiguousVariantSelectionException method format.

private static String format(String producerDisplayName, AttributeContainerInternal consumer, List<? extends ResolvedVariant> variants, AttributeMatcher matcher) {
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("More than one variant of " + producerDisplayName + " matches the consumer attributes");
    formatter.startChildren();
    for (ResolvedVariant variant : variants) {
        formatter.node(variant.asDescribable().getCapitalizedDisplayName());
        formatAttributeMatches(formatter, consumer, matcher, variant.getAttributes());
    }
    formatter.endChildren();
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.text.TreeFormatter) ResolvedVariant(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)

Aggregations

ResolvedVariant (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)9 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)4 Pair (org.gradle.internal.Pair)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 TreeFormatter (org.gradle.internal.logging.text.TreeFormatter)3 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 AttributeDescriber (org.gradle.api.internal.attributes.AttributeDescriber)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 VariantSelectionException (org.gradle.internal.component.VariantSelectionException)2 TreeFormatter (org.gradle.internal.text.TreeFormatter)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 LinkedHashMap (java.util.LinkedHashMap)1