Search in sources :

Example 61 with ImmutableAttributes

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

the class ComponentAttributeMatcher method isMatching.

/**
 * Determines whether the given candidate is compatible with the requested criteria, according to the given schema.
 */
public boolean isMatching(AttributeSelectionSchema schema, AttributeContainerInternal candidate, AttributeContainerInternal requested) {
    if (requested.isEmpty() || candidate.isEmpty()) {
        return true;
    }
    ImmutableAttributes requestedAttributes = requested.asImmutable();
    ImmutableAttributes candidateAttributes = candidate.asImmutable();
    for (Attribute<?> attribute : requestedAttributes.keySet()) {
        AttributeValue<?> requestedValue = requestedAttributes.findEntry(attribute);
        AttributeValue<?> candidateValue = candidateAttributes.findEntry(attribute.getName());
        if (candidateValue.isPresent()) {
            Object coercedValue = candidateValue.coerce(attribute);
            boolean match = schema.matchValue(attribute, requestedValue.get(), coercedValue);
            if (!match) {
                return false;
            }
        }
    }
    return true;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes)

Example 62 with ImmutableAttributes

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

the class DesugaringAttributeContainerSerializer method read.

@Override
public ImmutableAttributes read(Decoder decoder) throws IOException {
    ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
    int count = decoder.readSmallInt();
    for (int i = 0; i < count; i++) {
        String name = decoder.readString();
        byte type = decoder.readByte();
        if (type == BOOLEAN_ATTRIBUTE) {
            attributes = attributesFactory.concat(attributes, Attribute.of(name, Boolean.class), decoder.readBoolean());
        } else if (type == STRING_ATTRIBUTE) {
            String value = decoder.readString();
            attributes = attributesFactory.concat(attributes, Attribute.of(name, String.class), value);
        } else if (type == INTEGER_ATTRIBUTE) {
            int value = decoder.readInt();
            attributes = attributesFactory.concat(attributes, Attribute.of(name, Integer.class), value);
        } else if (type == DESUGARED_ATTRIBUTE) {
            String value = decoder.readString();
            attributes = attributesFactory.concat(attributes, Attribute.of(name, String.class), new CoercingStringValueSnapshot(value, namedObjectInstantiator));
        }
    }
    return attributes;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) CoercingStringValueSnapshot(org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot)

Example 63 with ImmutableAttributes

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

the class MultipleCandidateMatcher method disambiguateWithRequestedAttributeKeys.

private void disambiguateWithRequestedAttributeKeys() {
    if (requestedAttributes.isEmpty()) {
        return;
    }
    for (Attribute<?> extraAttribute : extraAttributes) {
        // We consider only extra attributes which are NOT on every candidate:
        // Because they are EXTRA attributes, we consider that a
        // candidate which does NOT provide this value is a better match
        int candidateCount = candidateAttributeSets.length;
        BitSet any = new BitSet(candidateCount);
        for (int c = 0; c < candidateCount; c++) {
            ImmutableAttributes candidateAttributeSet = candidateAttributeSets[c];
            if (candidateAttributeSet.findEntry(extraAttribute.getName()).isPresent()) {
                any.set(c);
            }
        }
        if (any.cardinality() > 0 && any.cardinality() != candidateCount) {
            // there is at least one candidate which does NOT provide this attribute
            remaining.andNot(any);
            if (remaining.cardinality() == 0) {
                // there are no left candidate, do not bother checking other attributes
                break;
            }
        }
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) BitSet(java.util.BitSet)

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