Search in sources :

Example 41 with ImmutableAttributes

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

the class ModuleComponentSelectorSerializer method read.

@Override
public ModuleComponentSelector read(Decoder decoder) throws IOException {
    String group = decoder.readString();
    String name = decoder.readString();
    VersionConstraint versionConstraint = readVersionConstraint(decoder);
    ImmutableAttributes attributes = readAttributes(decoder);
    List<Capability> capabilities = readCapabilities(decoder);
    return newSelector(DefaultModuleIdentifier.newId(group, name), versionConstraint, attributes, capabilities);
}
Also used : VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) Capability(org.gradle.api.capabilities.Capability)

Example 42 with ImmutableAttributes

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

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

the class GradleModuleMetadataParser method consumeDependencyConstraints.

private List<ModuleDependencyConstraint> consumeDependencyConstraints(JsonReader reader) throws IOException {
    List<ModuleDependencyConstraint> dependencies = new ArrayList<>();
    reader.beginArray();
    while (reader.peek() != END_ARRAY) {
        String group = null;
        String module = null;
        String reason = null;
        VersionConstraint version = null;
        ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
        reader.beginObject();
        while (reader.peek() != END_OBJECT) {
            String name = reader.nextName();
            switch(name) {
                case "group":
                    group = reader.nextString();
                    break;
                case "module":
                    module = reader.nextString();
                    break;
                case "version":
                    version = consumeVersion(reader);
                    break;
                case "reason":
                    reason = reader.nextString();
                    break;
                case "attributes":
                    attributes = consumeAttributes(reader);
                    break;
                default:
                    consumeAny(reader);
                    break;
            }
        }
        assertDefined(reader, "group", group);
        assertDefined(reader, "module", module);
        reader.endObject();
        dependencies.add(new ModuleDependencyConstraint(group, module, version, reason, attributes));
    }
    reader.endArray();
    return dependencies;
}
Also used : ImmutableVersionConstraint(org.gradle.api.internal.artifacts.ImmutableVersionConstraint) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ArrayList(java.util.ArrayList)

Example 44 with ImmutableAttributes

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

the class GradleModuleMetadataParser method consumeDependencies.

private List<ModuleDependency> consumeDependencies(JsonReader reader) throws IOException {
    List<ModuleDependency> dependencies = new ArrayList<>();
    reader.beginArray();
    while (reader.peek() != END_ARRAY) {
        String group = null;
        String module = null;
        String reason = null;
        ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
        VersionConstraint version = DefaultImmutableVersionConstraint.of();
        ImmutableList<ExcludeMetadata> excludes = ImmutableList.of();
        List<VariantCapability> requestedCapabilities = ImmutableList.of();
        IvyArtifactName artifactSelector = null;
        boolean endorseStrictVersions = false;
        reader.beginObject();
        while (reader.peek() != END_OBJECT) {
            String name = reader.nextName();
            switch(name) {
                case "group":
                    group = reader.nextString();
                    break;
                case "module":
                    module = reader.nextString();
                    break;
                case "version":
                    version = consumeVersion(reader);
                    break;
                case "excludes":
                    excludes = consumeExcludes(reader);
                    break;
                case "reason":
                    reason = reader.nextString();
                    break;
                case "attributes":
                    attributes = consumeAttributes(reader);
                    break;
                case "requestedCapabilities":
                    requestedCapabilities = consumeCapabilities(reader, false);
                    break;
                case "endorseStrictVersions":
                    endorseStrictVersions = reader.nextBoolean();
                    break;
                case "thirdPartyCompatibility":
                    reader.beginObject();
                    while (reader.peek() != END_OBJECT) {
                        String compatibilityFeatureName = reader.nextName();
                        if (compatibilityFeatureName.equals("artifactSelector")) {
                            artifactSelector = consumeArtifactSelector(reader);
                        } else {
                            consumeAny(reader);
                        }
                    }
                    reader.endObject();
                    break;
                default:
                    consumeAny(reader);
                    break;
            }
        }
        assertDefined(reader, "group", group);
        assertDefined(reader, "module", module);
        reader.endObject();
        dependencies.add(new ModuleDependency(group, module, version, excludes, reason, attributes, requestedCapabilities, endorseStrictVersions, artifactSelector));
    }
    reader.endArray();
    return dependencies;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ImmutableVersionConstraint(org.gradle.api.internal.artifacts.ImmutableVersionConstraint) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ArrayList(java.util.ArrayList) DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) ExcludeMetadata(org.gradle.internal.component.model.ExcludeMetadata)

Example 45 with ImmutableAttributes

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

the class ProjectArtifactSetResolver method mapVariant.

private ResolvedVariant mapVariant(ModuleVersionIdentifier ownerId, ModuleSources moduleSources, ExcludeSpec exclusions, ArtifactTypeRegistry artifactTypeRegistry, VariantResolveMetadata variant) {
    VariantResolveMetadata.Identifier identifier = variant.getIdentifier();
    if (identifier == null) {
        throw new IllegalArgumentException(String.format("Project variant %s does not have an identifier.", variant.asDescribable()));
    }
    // Apply any artifact type mappings to the attributes of the variant
    ImmutableAttributes variantAttributes = artifactTypeRegistry.mapAttributesFor(variant.getAttributes().asImmutable(), variant.getArtifacts());
    if (exclusions.mayExcludeArtifacts()) {
        // Some artifact may be excluded, so do not reuse. It might be better to apply the exclusions and reuse if none of them apply
        return DefaultArtifactSet.toResolvedVariant(variant, ownerId, moduleSources, exclusions, artifactResolver, allProjectArtifacts, variantAttributes, calculatedValueContainerFactory);
    }
    VariantWithOverloadAttributes key = new VariantWithOverloadAttributes(identifier, variantAttributes);
    return allProjectVariants.computeIfAbsent(key, k -> DefaultArtifactSet.toResolvedVariant(variant, ownerId, moduleSources, exclusions, artifactResolver, allProjectArtifacts, variantAttributes, calculatedValueContainerFactory));
}
Also used : VariantWithOverloadAttributes(org.gradle.internal.component.model.VariantWithOverloadAttributes) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) VariantResolveMetadata(org.gradle.internal.component.model.VariantResolveMetadata)

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