Search in sources :

Example 1 with AmbiguousVariantSelectionException

use of org.gradle.internal.component.AmbiguousVariantSelectionException 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)

Aggregations

ArrayList (java.util.ArrayList)1 ResolvedVariant (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)1 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)1 Pair (org.gradle.internal.Pair)1 AmbiguousVariantSelectionException (org.gradle.internal.component.AmbiguousVariantSelectionException)1 NoMatchingVariantSelectionException (org.gradle.internal.component.NoMatchingVariantSelectionException)1 AttributeMatcher (org.gradle.internal.component.model.AttributeMatcher)1