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