Search in sources :

Example 46 with ImmutableAttributes

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

the class EdgeState method calculateTargetConfigurations.

private void calculateTargetConfigurations(ComponentState targetComponent) {
    ComponentResolveMetadata targetModuleVersion = targetComponent.getMetadata();
    targetNodes.clear();
    targetNodeSelectionFailure = null;
    if (targetModuleVersion == null) {
        targetComponent.getModule().getPlatformState().addOrphanEdge(this);
        // Broken version
        return;
    }
    if (isConstraint && !isVirtualDependency()) {
        List<NodeState> nodes = targetComponent.getNodes();
        for (NodeState node : nodes) {
            if (node.isSelected()) {
                targetNodes.add(node);
            }
        }
        if (targetNodes.isEmpty()) {
            // There is a chance we could not attach target configurations previously
            List<EdgeState> unattachedDependencies = targetComponent.getModule().getUnattachedDependencies();
            if (!unattachedDependencies.isEmpty()) {
                for (EdgeState otherEdge : unattachedDependencies) {
                    if (otherEdge != this && !otherEdge.isConstraint()) {
                        otherEdge.attachToTargetConfigurations();
                        if (otherEdge.targetNodeSelectionFailure != null) {
                            // Copy selection failure
                            this.targetNodeSelectionFailure = otherEdge.targetNodeSelectionFailure;
                            return;
                        }
                        break;
                    }
                }
            }
            for (NodeState node : nodes) {
                if (node.isSelected()) {
                    targetNodes.add(node);
                }
            }
        }
        return;
    }
    List<ConfigurationMetadata> targetConfigurations;
    try {
        ImmutableAttributes attributes = resolveState.getRoot().getMetadata().getAttributes();
        attributes = resolveState.getAttributesFactory().concat(attributes, safeGetAttributes());
        targetConfigurations = dependencyMetadata.selectConfigurations(attributes, targetModuleVersion, resolveState.getAttributesSchema(), dependencyState.getDependency().getSelector().getRequestedCapabilities());
    } catch (AttributeMergingException mergeError) {
        targetNodeSelectionFailure = new ModuleVersionResolveException(dependencyState.getRequested(), () -> {
            Attribute<?> attribute = mergeError.getAttribute();
            Object constraintValue = mergeError.getLeftValue();
            Object dependencyValue = mergeError.getRightValue();
            return "Inconsistency between attributes of a constraint and a dependency, on attribute '" + attribute + "' : dependency requires '" + dependencyValue + "' while constraint required '" + constraintValue + "'";
        });
        return;
    } catch (Exception t) {
        // Failure to select the target variant/configurations from this component, given the dependency attributes/metadata.
        targetNodeSelectionFailure = new ModuleVersionResolveException(dependencyState.getRequested(), t);
        return;
    }
    for (ConfigurationMetadata targetConfiguration : targetConfigurations) {
        NodeState targetNodeState = resolveState.getNode(targetComponent, targetConfiguration);
        this.targetNodes.add(targetNodeState);
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) AttributeMergingException(org.gradle.api.internal.attributes.AttributeMergingException) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) AttributeMergingException(org.gradle.api.internal.attributes.AttributeMergingException)

Example 47 with ImmutableAttributes

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

the class ModuleResolveState method appendAttributes.

private ImmutableAttributes appendAttributes(ImmutableAttributes dependencyAttributes, SelectorState selectorState) {
    try {
        DependencyMetadata dependencyMetadata = selectorState.getDependencyMetadata();
        boolean constraint = dependencyMetadata.isConstraint();
        if (constraint) {
            ComponentSelector selector = dependencyMetadata.getSelector();
            ImmutableAttributes attributes = ((AttributeContainerInternal) selector.getAttributes()).asImmutable();
            dependencyAttributes = attributesFactory.safeConcat(attributes, dependencyAttributes);
        }
    } catch (AttributeMergingException e) {
        attributeMergingError = e;
    }
    return dependencyAttributes;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) DependencyMetadata(org.gradle.internal.component.model.DependencyMetadata) ForcingDependencyMetadata(org.gradle.internal.component.model.ForcingDependencyMetadata) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) AttributeMergingException(org.gradle.api.internal.attributes.AttributeMergingException)

Example 48 with ImmutableAttributes

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

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

the class DesugaredAttributeContainerSerializer 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 == INTEGER_ATTRIBUTE) {
            attributes = attributesFactory.concat(attributes, Attribute.of(name, Integer.class), decoder.readInt());
        } else {
            String value = decoder.readString();
            attributes = attributesFactory.concat(attributes, Attribute.of(name, String.class), new CoercingStringValueSnapshot(value, instantiator));
        }
    }
    return attributes;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) CoercingStringValueSnapshot(org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot)

Example 50 with ImmutableAttributes

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

the class DefaultMavenImmutableAttributesFactory method platformWithUsage.

@Override
public ImmutableAttributes platformWithUsage(ImmutableAttributes original, String usage, boolean enforced) {
    String componentType = enforced ? Category.ENFORCED_PLATFORM : Category.REGULAR_PLATFORM;
    ComponentTypeEntry entry = new ComponentTypeEntry(original, componentType, usage);
    ImmutableAttributes result = concatCache.get(entry);
    if (result == null) {
        result = concat(original, USAGE_ATTRIBUTE, new CoercingStringValueSnapshot(usage, objectInstantiator));
        result = concat(result, CATEGORY_ATTRIBUTE, new CoercingStringValueSnapshot(componentType, objectInstantiator));
        concatCache.put(entry, result);
    }
    return result;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) CoercingStringValueSnapshot(org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot)

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