Search in sources :

Example 11 with Attribute

use of org.gradle.api.attributes.Attribute in project gradle by gradle.

the class DependencyGraphBuilder method assertCompatibleAttributes.

private void assertCompatibleAttributes(NodeState first, NodeState second, Set<NodeState> incompatibleNodes) {
    ImmutableAttributes firstAttributes = first.getMetadata().getAttributes();
    ImmutableAttributes secondAttributes = second.getMetadata().getAttributes();
    ImmutableSet<Attribute<?>> firstKeys = firstAttributes.keySet();
    ImmutableSet<Attribute<?>> secondKeys = secondAttributes.keySet();
    for (Attribute<?> attribute : Sets.intersection(firstKeys, secondKeys)) {
        CompatibilityRule<Object> rule = attributesSchema.compatibilityRules(attribute);
        Object v1 = firstAttributes.getAttribute(attribute);
        Object v2 = secondAttributes.getAttribute(attribute);
        // for all commons attributes, make sure they are compatible with each other
        if (!compatible(rule, v1, v2) && !compatible(rule, v2, v1)) {
            incompatibleNodes.add(first);
            incompatibleNodes.add(second);
        }
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Attribute(org.gradle.api.attributes.Attribute)

Example 12 with Attribute

use of org.gradle.api.attributes.Attribute in project gradle by gradle.

the class AttributeSelectionUtils method collectExtraAttributes.

public static Attribute<?>[] collectExtraAttributes(AttributeSelectionSchema schema, ImmutableAttributes[] candidateAttributeSets, ImmutableAttributes requested) {
    Set<Attribute<?>> extraAttributes = Sets.newLinkedHashSet();
    for (ImmutableAttributes attributes : candidateAttributeSets) {
        extraAttributes.addAll(attributes.keySet());
    }
    removeSameAttributes(requested, extraAttributes);
    Attribute<?>[] extraAttributesArray = extraAttributes.toArray(new Attribute<?>[0]);
    for (int i = 0; i < extraAttributesArray.length; i++) {
        Attribute<?> extraAttribute = extraAttributesArray[i];
        Attribute<?> schemaAttribute = schema.getAttribute(extraAttribute.getName());
        if (schemaAttribute != null) {
            extraAttributesArray[i] = schemaAttribute;
        }
    }
    return extraAttributesArray;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Attribute(org.gradle.api.attributes.Attribute)

Aggregations

Attribute (org.gradle.api.attributes.Attribute)12 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)6 TreeMap (java.util.TreeMap)2 AttributeContainer (org.gradle.api.attributes.AttributeContainer)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Named (org.gradle.api.Named)1 PublishException (org.gradle.api.artifacts.PublishException)1 Category (org.gradle.api.attributes.Category)1 DocumentationRegistry (org.gradle.api.internal.DocumentationRegistry)1 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)1 AttributeDescriber (org.gradle.api.internal.attributes.AttributeDescriber)1 SoftwareComponentInternal (org.gradle.api.internal.component.SoftwareComponentInternal)1 UsageContext (org.gradle.api.internal.component.UsageContext)1 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)1