Search in sources :

Example 51 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class DefaultMavenImmutableAttributesFactory method libraryWithUsage.

@Override
public ImmutableAttributes libraryWithUsage(ImmutableAttributes original, String usage) {
    ComponentTypeEntry entry = new ComponentTypeEntry(original, Category.LIBRARY, usage);
    ImmutableAttributes result = concatCache.get(entry);
    if (result == null) {
        result = concat(original, USAGE_ATTRIBUTE, new CoercingStringValueSnapshot(usage, objectInstantiator));
        result = concat(result, FORMAT_ATTRIBUTE, new CoercingStringValueSnapshot(LibraryElements.JAR, objectInstantiator));
        result = concat(result, CATEGORY_ATTRIBUTE, new CoercingStringValueSnapshot(Category.LIBRARY, objectInstantiator));
        concatCache.put(entry, result);
    }
    return result;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) CoercingStringValueSnapshot(org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot)

Example 52 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class DefaultMavenImmutableAttributesFactory method sourcesVariant.

@Override
public ImmutableAttributes sourcesVariant(ImmutableAttributes original) {
    ImmutableAttributes result = original;
    result = concat(result, CATEGORY_ATTRIBUTE, new CoercingStringValueSnapshot(Category.DOCUMENTATION, objectInstantiator));
    result = concat(result, Bundling.BUNDLING_ATTRIBUTE, objectInstantiator.named(Bundling.class, Bundling.EXTERNAL));
    result = concat(result, DocsType.DOCS_TYPE_ATTRIBUTE, objectInstantiator.named(DocsType.class, DocsType.SOURCES));
    result = concat(result, USAGE_ATTRIBUTE, new CoercingStringValueSnapshot(Usage.JAVA_RUNTIME, objectInstantiator));
    return result;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) CoercingStringValueSnapshot(org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot)

Example 53 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class DefaultMavenImmutableAttributesFactory method javadocVariant.

@Override
public ImmutableAttributes javadocVariant(ImmutableAttributes original) {
    ImmutableAttributes result = original;
    result = concat(result, CATEGORY_ATTRIBUTE, new CoercingStringValueSnapshot(Category.DOCUMENTATION, objectInstantiator));
    result = concat(result, Bundling.BUNDLING_ATTRIBUTE, objectInstantiator.named(Bundling.class, Bundling.EXTERNAL));
    result = concat(result, DocsType.DOCS_TYPE_ATTRIBUTE, objectInstantiator.named(DocsType.class, DocsType.JAVADOC));
    result = concat(result, USAGE_ATTRIBUTE, new CoercingStringValueSnapshot(Usage.JAVA_RUNTIME, objectInstantiator));
    return result;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) CoercingStringValueSnapshot(org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot)

Example 54 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class AttributeMatchingVariantSelector method doSelect.

private ResolvedArtifactSet doSelect(ResolvedVariantSet producer, Factory factory, AttributeMatchingExplanationBuilder explanationBuilder) {
    AttributeMatcher matcher = schema.withProducer(producer.getSchema());
    ImmutableAttributes componentRequested = attributesFactory.concat(requested, producer.getOverriddenAttributes());
    List<? extends ResolvedVariant> matches = matcher.matches(producer.getVariants(), componentRequested, explanationBuilder);
    if (matches.size() == 1) {
        return matches.get(0).getArtifacts();
    }
    if (matches.size() > 1) {
        if (explanationBuilder instanceof TraceDiscardedVariants) {
            Set<ResolvedVariant> discarded = Cast.uncheckedCast(((TraceDiscardedVariants) explanationBuilder).discarded);
            AttributeDescriber describer = DescriberSelector.selectDescriber(componentRequested, schema);
            throw new AmbiguousVariantSelectionException(describer, producer.asDescribable().getDisplayName(), componentRequested, matches, matcher, discarded);
        } else {
            // because we're going to fail, we can afford a second run with details
            return doSelect(producer, factory, new TraceDiscardedVariants());
        }
    }
    List<Pair<ResolvedVariant, MutableConsumerVariantMatchResult.ConsumerVariant>> candidates = new ArrayList<>();
    for (ResolvedVariant variant : producer.getVariants()) {
        AttributeContainerInternal variantAttributes = variant.getAttributes().asImmutable();
        ConsumerVariantMatchResult matchResult = consumerProvidedVariantFinder.collectConsumerVariants(variantAttributes, componentRequested);
        for (MutableConsumerVariantMatchResult.ConsumerVariant consumerVariant : matchResult.getMatches()) {
            candidates.add(Pair.of(variant, consumerVariant));
        }
    }
    if (candidates.size() > 1) {
        candidates = tryDisambiguate(matcher, candidates, componentRequested, explanationBuilder);
    }
    if (candidates.size() == 1) {
        Pair<ResolvedVariant, MutableConsumerVariantMatchResult.ConsumerVariant> result = candidates.get(0);
        ResolvedVariant variant = result.getLeft();
        VariantDefinition definition = result.getRight();
        return factory.asTransformed(variant, definition, dependenciesResolver, transformedVariantFactory);
    }
    if (!candidates.isEmpty()) {
        throw new AmbiguousTransformException(producer.asDescribable().getDisplayName(), componentRequested, candidates);
    }
    if (ignoreWhenNoMatches) {
        return ResolvedArtifactSet.EMPTY;
    }
    throw new NoMatchingVariantSelectionException(producer.asDescribable().getDisplayName(), componentRequested, producer.getVariants(), matcher, DescriberSelector.selectDescriber(componentRequested, schema));
}
Also used : AttributeMatcher(org.gradle.internal.component.model.AttributeMatcher) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) 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) AttributeDescriber(org.gradle.api.internal.attributes.AttributeDescriber) Pair(org.gradle.internal.Pair)

Example 55 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes 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)

Aggregations

ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)63 CoercingStringValueSnapshot (org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot)9 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)8 ArrayList (java.util.ArrayList)7 Attribute (org.gradle.api.attributes.Attribute)7 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)7 ImmutableCapabilities (org.gradle.internal.component.external.model.ImmutableCapabilities)6 AttributeMatcher (org.gradle.internal.component.model.AttributeMatcher)6 ImmutableList (com.google.common.collect.ImmutableList)5 File (java.io.File)5 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)4 CapabilitiesMetadata (org.gradle.api.capabilities.CapabilitiesMetadata)4 ExcludeMetadata (org.gradle.internal.component.model.ExcludeMetadata)4 List (java.util.List)3 VersionConstraint (org.gradle.api.artifacts.VersionConstraint)3 DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)3 ModuleDependencyMetadata (org.gradle.internal.component.external.model.ModuleDependencyMetadata)3 MutableComponentVariant (org.gradle.internal.component.external.model.MutableComponentVariant)3 RealisedConfigurationMetadata (org.gradle.internal.component.external.model.RealisedConfigurationMetadata)3 VariantResolveMetadata (org.gradle.internal.component.model.VariantResolveMetadata)3