use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class DefaultTransformedVariantFactory method locateOrCreate.
private ResolvedArtifactSet locateOrCreate(Factory factory, ComponentIdentifier componentIdentifier, ResolvedVariant sourceVariant, VariantDefinition variantDefinition, ExtraExecutionGraphDependenciesResolverFactory dependenciesResolverFactory) {
ImmutableAttributes target = variantDefinition.getTargetAttributes();
Transformation transformation = variantDefinition.getTransformation();
VariantResolveMetadata.Identifier identifier = sourceVariant.getIdentifier();
if (identifier == null) {
// An ad hoc variant, do not cache the result
return factory.create(componentIdentifier, sourceVariant, variantDefinition, dependenciesResolverFactory);
}
VariantKey variantKey;
if (transformation.requiresDependencies()) {
variantKey = new VariantWithUpstreamDependenciesKey(identifier, target, dependenciesResolverFactory);
} else {
variantKey = new VariantKey(identifier, target);
}
// Can't use computeIfAbsent() as the default implementation does not allow recursive updates
ResolvedArtifactSet result = variants.get(variantKey);
if (result == null) {
ResolvedArtifactSet newResult = factory.create(componentIdentifier, sourceVariant, variantDefinition, dependenciesResolverFactory);
result = variants.putIfAbsent(variantKey, newResult);
if (result == null) {
result = newResult;
}
}
return result;
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class ConsumerProvidedVariantFinder method findProducersFor.
private MutableConsumerVariantMatchResult findProducersFor(AttributeContainerInternal actual, AttributeContainerInternal requested) {
// Prefer direct transformation over indirect transformation
List<ArtifactTransformRegistration> candidates = new ArrayList<>();
List<ArtifactTransformRegistration> transforms = variantTransforms.getTransforms();
int nbOfTransforms = transforms.size();
MutableConsumerVariantMatchResult result = new MutableConsumerVariantMatchResult(nbOfTransforms * nbOfTransforms);
for (ArtifactTransformRegistration registration : transforms) {
if (matchAttributes(registration.getTo(), requested)) {
if (matchAttributes(actual, registration.getFrom())) {
ImmutableAttributes variantAttributes = attributesFactory.concat(actual.asImmutable(), registration.getTo().asImmutable());
if (matchAttributes(variantAttributes, requested)) {
result.matched(variantAttributes, registration.getTransformationStep(), null, 1);
}
}
candidates.add(registration);
}
}
if (result.hasMatches()) {
return result;
}
for (ArtifactTransformRegistration candidate : candidates) {
AttributeContainerInternal requestedPrevious = computeRequestedAttributes(requested, candidate);
ConsumerVariantMatchResult inputVariants = collectConsumerVariants(actual, requestedPrevious);
if (!inputVariants.hasMatches()) {
continue;
}
for (MutableConsumerVariantMatchResult.ConsumerVariant inputVariant : inputVariants.getMatches()) {
ImmutableAttributes variantAttributes = attributesFactory.concat(inputVariant.attributes.asImmutable(), candidate.getTo().asImmutable());
result.matched(variantAttributes, candidate.getTransformationStep(), inputVariant, inputVariant.depth + 1);
}
}
return result;
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class GradleModuleMetadataParser method consumeVariant.
private void consumeVariant(JsonReader reader, MutableModuleComponentResolveMetadata metadata) throws IOException {
String variantName = null;
ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
List<ModuleFile> files = Collections.emptyList();
List<ModuleDependency> dependencies = Collections.emptyList();
List<ModuleDependencyConstraint> dependencyConstraints = Collections.emptyList();
List<VariantCapability> capabilities = Collections.emptyList();
boolean availableExternally = false;
reader.beginObject();
while (reader.peek() != END_OBJECT) {
String name = reader.nextName();
switch(name) {
case "name":
variantName = reader.nextString();
break;
case "attributes":
attributes = consumeAttributes(reader);
break;
case "files":
files = consumeFiles(reader);
break;
case "dependencies":
dependencies = consumeDependencies(reader);
break;
case "dependencyConstraints":
dependencyConstraints = consumeDependencyConstraints(reader);
break;
case "capabilities":
capabilities = consumeCapabilities(reader, true);
break;
case "available-at":
availableExternally = true;
dependencies = consumeVariantLocation(reader);
break;
default:
consumeAny(reader);
break;
}
}
assertDefined(reader, "name", variantName);
reader.endObject();
MutableComponentVariant variant = metadata.addVariant(variantName, attributes);
variant.setAvailableExternally(availableExternally);
if (availableExternally) {
if (!dependencyConstraints.isEmpty()) {
throw new RuntimeException("A variant declared with available-at cannot declare dependency constraints");
}
if (!files.isEmpty()) {
throw new RuntimeException("A variant declared with available-at cannot declare files");
}
}
populateVariant(files, dependencies, dependencyConstraints, capabilities, variant);
}
use of org.gradle.api.internal.attributes.ImmutableAttributes 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));
}
}
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class DefaultArtifactTypeRegistry method visitArtifactTypes.
@Override
public void visitArtifactTypes(Consumer<? super ImmutableAttributes> action) {
Set<ImmutableAttributes> seen = new HashSet<>();
if (artifactTypeDefinitions != null) {
for (ArtifactTypeDefinition artifactTypeDefinition : artifactTypeDefinitions) {
ImmutableAttributes attributes = ((AttributeContainerInternal) artifactTypeDefinition.getAttributes()).asImmutable();
attributes = attributesFactory.concat(attributesFactory.of(ARTIFACT_TYPE_ATTRIBUTE, artifactTypeDefinition.getName()), attributes);
if (seen.add(attributes)) {
action.accept(attributes);
}
}
}
for (ArtifactTransformRegistration transform : transformRegistry.getTransforms()) {
AttributeContainerInternal sourceAttributes = transform.getFrom();
String format = sourceAttributes.getAttribute(ARTIFACT_TYPE_ATTRIBUTE);
// Some format that is not already registered
if (format != null) {
ImmutableAttributes attributes = sourceAttributes.asImmutable();
if (seen.add(attributes)) {
action.accept(attributes);
}
}
}
}
Aggregations