Search in sources :

Example 16 with ImmutableAttributes

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;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ResolvedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSet) VariantResolveMetadata(org.gradle.internal.component.model.VariantResolveMetadata)

Example 17 with ImmutableAttributes

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;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ArtifactTransformRegistration(org.gradle.api.internal.artifacts.ArtifactTransformRegistration) ArrayList(java.util.ArrayList) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal)

Example 18 with ImmutableAttributes

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);
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) MutableComponentVariant(org.gradle.internal.component.external.model.MutableComponentVariant)

Example 19 with ImmutableAttributes

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));
        }
    }
}
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 20 with ImmutableAttributes

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);
            }
        }
    }
}
Also used : ArtifactTypeDefinition(org.gradle.api.artifacts.type.ArtifactTypeDefinition) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ArtifactTransformRegistration(org.gradle.api.internal.artifacts.ArtifactTransformRegistration) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) HashSet(java.util.HashSet)

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