Search in sources :

Example 1 with ImmutableAttributes

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

the class DefaultArtifactSet method toResolvedVariant.

private static ResolvedVariant toResolvedVariant(VariantResolveMetadata variant, ModuleVersionIdentifier ownerId, ModuleSource moduleSource, ModuleExclusion exclusions, ArtifactResolver artifactResolver, Map<ComponentArtifactIdentifier, ResolvableArtifact> allResolvedArtifacts, ArtifactTypeRegistry artifactTypeRegistry) {
    List<? extends ComponentArtifactMetadata> artifacts = variant.getArtifacts();
    ImmutableSet.Builder<ResolvableArtifact> resolvedArtifacts = ImmutableSet.builder();
    // Apply any artifact type mappings to the attributes of the variant
    ImmutableAttributes attributes = artifactTypeRegistry.mapAttributesFor(variant);
    for (ComponentArtifactMetadata artifact : artifacts) {
        IvyArtifactName artifactName = artifact.getName();
        if (exclusions.excludeArtifact(ownerId.getModule(), artifactName)) {
            continue;
        }
        ResolvableArtifact resolvedArtifact = allResolvedArtifacts.get(artifact.getId());
        if (resolvedArtifact == null) {
            Factory<File> artifactSource = new LazyArtifactSource(artifact, moduleSource, artifactResolver);
            resolvedArtifact = new DefaultResolvedArtifact(ownerId, artifactName, artifact.getId(), artifact.getBuildDependencies(), artifactSource);
            allResolvedArtifacts.put(artifact.getId(), resolvedArtifact);
        }
        resolvedArtifacts.add(resolvedArtifact);
    }
    return ArtifactBackedResolvedVariant.create(variant.asDescribable(), attributes, resolvedArtifacts.build());
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ImmutableSet(com.google.common.collect.ImmutableSet) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) DefaultResolvedArtifact(org.gradle.api.internal.artifacts.DefaultResolvedArtifact) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) File(java.io.File)

Example 2 with ImmutableAttributes

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

the class AttributeContainerSerializer 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 {
            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.api.internal.changedetection.state.CoercingStringValueSnapshot)

Example 3 with ImmutableAttributes

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

the class ModuleMetadataParser 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 {
            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.api.internal.changedetection.state.CoercingStringValueSnapshot)

Example 4 with ImmutableAttributes

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

the class DefaultArtifactTypeRegistry method mapAttributesFor.

@Override
public ImmutableAttributes mapAttributesFor(File file) {
    String extension = Files.getFileExtension(file.getName());
    ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
    if (artifactTypeDefinitions != null) {
        attributes = applyForExtension(attributes, extension);
    }
    attributes = attributesFactory.concat(attributesFactory.of(ARTIFACT_FORMAT, extension), attributes);
    return attributes;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes)

Example 5 with ImmutableAttributes

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

the class AmbiguousConfigurationSelectionException method formatAttributeMatches.

static void formatAttributeMatches(TreeFormatter formatter, AttributeContainerInternal consumerAttributes, AttributeMatcher attributeMatcher, AttributeContainerInternal producerAttributes) {
    Map<String, Attribute<?>> allAttributes = new TreeMap<String, Attribute<?>>();
    for (Attribute<?> attribute : producerAttributes.keySet()) {
        allAttributes.put(attribute.getName(), attribute);
    }
    for (Attribute<?> attribute : consumerAttributes.keySet()) {
        allAttributes.put(attribute.getName(), attribute);
    }
    ImmutableAttributes immmutableConsumer = consumerAttributes.asImmutable();
    ImmutableAttributes immutableProducer = producerAttributes.asImmutable();
    formatter.startChildren();
    for (Attribute<?> attribute : allAttributes.values()) {
        Attribute<Object> untyped = Cast.uncheckedCast(attribute);
        String attributeName = attribute.getName();
        AttributeValue<Object> consumerValue = immmutableConsumer.findEntry(untyped);
        AttributeValue<?> producerValue = immutableProducer.findEntry(attribute.getName());
        if (consumerValue.isPresent() && producerValue.isPresent()) {
            if (attributeMatcher.isMatching(untyped, producerValue.coerce(attribute), consumerValue.coerce(attribute))) {
                formatter.node("Required " + attributeName + " '" + consumerValue.get() + "' and found compatible value '" + producerValue.get() + "'.");
            } else {
                formatter.node("Required " + attributeName + " '" + consumerValue.get() + "' and found incompatible value '" + producerValue.get() + "'.");
            }
        } else if (consumerValue.isPresent()) {
            formatter.node("Required " + attributeName + " '" + consumerValue.get() + "' but no value provided.");
        } else {
            formatter.node("Found " + attributeName + " '" + producerValue.get() + "' but wasn't required.");
        }
    }
    formatter.endChildren();
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Attribute(org.gradle.api.attributes.Attribute) TreeMap(java.util.TreeMap)

Aggregations

ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)15 File (java.io.File)3 Attribute (org.gradle.api.attributes.Attribute)3 ArrayList (java.util.ArrayList)2 VariantTransformRegistry (org.gradle.api.internal.artifacts.VariantTransformRegistry)2 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)2 CoercingStringValueSnapshot (org.gradle.api.internal.changedetection.state.CoercingStringValueSnapshot)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 Transformer (org.gradle.api.Transformer)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ArtifactTypeContainer (org.gradle.api.artifacts.type.ArtifactTypeContainer)1 DefaultResolvedArtifact (org.gradle.api.internal.artifacts.DefaultResolvedArtifact)1 ArtifactTypeRegistry (org.gradle.api.internal.artifacts.type.ArtifactTypeRegistry)1 MutableComponentVariant (org.gradle.internal.component.external.model.MutableComponentVariant)1 ComponentArtifactMetadata (org.gradle.internal.component.model.ComponentArtifactMetadata)1 ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)1 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)1 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)1