Search in sources :

Example 1 with CoercingStringValueSnapshot

use of org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot in project gradle by gradle.

the class GradleModuleMetadataParser method maybeAddEnforcedPlatformVariant.

private void maybeAddEnforcedPlatformVariant(MutableModuleComponentResolveMetadata metadata) {
    List<? extends MutableComponentVariant> variants = metadata.getMutableVariants();
    if (variants == null || variants.isEmpty()) {
        return;
    }
    for (MutableComponentVariant variant : ImmutableList.copyOf(variants)) {
        AttributeValue<String> entry = variant.getAttributes().findEntry(MavenImmutableAttributesFactory.CATEGORY_ATTRIBUTE);
        if (entry.isPresent() && Category.REGULAR_PLATFORM.equals(entry.get()) && variant.getCapabilities().isEmpty()) {
            // This generates a synthetic enforced platform variant with the same dependencies, similar to what the Maven variant derivation strategy does
            ImmutableAttributes enforcedAttributes = attributesFactory.concat(variant.getAttributes(), MavenImmutableAttributesFactory.CATEGORY_ATTRIBUTE, new CoercingStringValueSnapshot(Category.ENFORCED_PLATFORM, instantiator));
            Capability enforcedCapability = buildShadowPlatformCapability(metadata.getId());
            metadata.addVariant(variant.copy("enforced" + capitalize(variant.getName()), enforcedAttributes, enforcedCapability));
        }
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) DefaultShadowedCapability(org.gradle.internal.component.external.model.DefaultShadowedCapability) ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) Capability(org.gradle.api.capabilities.Capability) CoercingStringValueSnapshot(org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot) MutableComponentVariant(org.gradle.internal.component.external.model.MutableComponentVariant)

Example 2 with CoercingStringValueSnapshot

use of org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot in project gradle by gradle.

the class GradleModuleMetadataCompatibilityConverter method handleAttributeCompatibility.

private void handleAttributeCompatibility(MutableModuleComponentResolveMetadata metaDataFromResource) {
    // However this code will have to remain forever while the other one should be removed at some point (Gradle 7.0?)
    for (MutableComponentVariant variant : metaDataFromResource.getMutableVariants()) {
        ImmutableAttributes attributes = variant.getAttributes();
        ImmutableAttributes updatedAttributes = ImmutableAttributes.EMPTY;
        if (attributes.contains(USAGE_STRING_ATTRIBUTE)) {
            String attributeValue = attributes.getAttribute(USAGE_STRING_ATTRIBUTE);
            if (attributeValue.endsWith("-jars")) {
                updatedAttributes = attributesFactory.concat(updatedAttributes, USAGE_STRING_ATTRIBUTE, new CoercingStringValueSnapshot(attributeValue.replace("-jars", ""), instantiator));
            }
        }
        if (!updatedAttributes.isEmpty() && !attributes.contains(LIBRARY_ELEMENTS_STRING_ATTRIBUTE)) {
            updatedAttributes = attributesFactory.concat(updatedAttributes, LIBRARY_ELEMENTS_STRING_ATTRIBUTE, new CoercingStringValueSnapshot(LibraryElements.JAR, instantiator));
        }
        if (!updatedAttributes.isEmpty()) {
            updatedAttributes = attributesFactory.concat(attributes, updatedAttributes);
            variant.setAttributes(updatedAttributes);
        }
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) CoercingStringValueSnapshot(org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot) MutableComponentVariant(org.gradle.internal.component.external.model.MutableComponentVariant)

Example 3 with CoercingStringValueSnapshot

use of org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot in project gradle by gradle.

the class GradleModuleMetadataParser method consumeAttributes.

private ImmutableAttributes consumeAttributes(JsonReader reader) throws IOException {
    ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
    reader.beginObject();
    while (reader.peek() != END_OBJECT) {
        String attrName = reader.nextName();
        if (reader.peek() == BOOLEAN) {
            boolean attrValue = reader.nextBoolean();
            attributes = attributesFactory.concat(attributes, Attribute.of(attrName, Boolean.class), attrValue);
        } else if (reader.peek() == NUMBER) {
            Integer attrValue = reader.nextInt();
            attributes = attributesFactory.concat(attributes, Attribute.of(attrName, Integer.class), attrValue);
        } else {
            String attrValue = reader.nextString();
            attributes = attributesFactory.concat(attributes, Attribute.of(attrName, String.class), new CoercingStringValueSnapshot(attrValue, instantiator));
        }
    }
    reader.endObject();
    return attributes;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) CoercingStringValueSnapshot(org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot)

Example 4 with CoercingStringValueSnapshot

use of org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot 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 5 with CoercingStringValueSnapshot

use of org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot 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)9 CoercingStringValueSnapshot (org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot)9 MutableComponentVariant (org.gradle.internal.component.external.model.MutableComponentVariant)2 Capability (org.gradle.api.capabilities.Capability)1 DefaultShadowedCapability (org.gradle.internal.component.external.model.DefaultShadowedCapability)1 ImmutableCapability (org.gradle.internal.component.external.model.ImmutableCapability)1