Search in sources :

Example 1 with AttributeMergingException

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

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

Aggregations

AttributeMergingException (org.gradle.api.internal.attributes.AttributeMergingException)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)1 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)1 ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)1 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)1 DependencyMetadata (org.gradle.internal.component.model.DependencyMetadata)1 ForcingDependencyMetadata (org.gradle.internal.component.model.ForcingDependencyMetadata)1 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)1