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