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;
}
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;
}
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;
}
}
}
}
Aggregations