Search in sources :

Example 31 with ImmutableAttributes

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

the class EdgeState method calculateTargetConfigurations.

private void calculateTargetConfigurations() {
    targetNodes.clear();
    targetNodeSelectionFailure = null;
    ComponentResolveMetadata targetModuleVersion = targetModuleRevision.getMetadata();
    if (targetModuleVersion == null) {
        // Broken version
        return;
    }
    ImmutableAttributes attributes = resolveState.getRoot().getMetadata().getAttributes();
    List<ConfigurationMetadata> targetConfigurations;
    try {
        targetConfigurations = dependencyMetadata.selectConfigurations(attributes, targetModuleVersion, resolveState.getAttributesSchema());
    } catch (Throwable t) {
        // Failure to select the target variant/configurations from this component, given the dependency attributes/metadata.
        targetNodeSelectionFailure = new ModuleVersionResolveException(dependencyState.getRequested(), t);
        return;
    }
    for (ConfigurationMetadata targetConfiguration : targetConfigurations) {
        NodeState targetNodeState = resolveState.getNode(targetModuleRevision, targetConfiguration);
        this.targetNodes.add(targetNodeState);
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 32 with ImmutableAttributes

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

the class ModuleMetadataParser method consumeVariant.

private void consumeVariant(JsonReader reader, MutableModuleComponentResolveMetadata metadata) throws IOException {
    reader.beginObject();
    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();
    while (reader.peek() != END_OBJECT) {
        String name = reader.nextName();
        if (name.equals("name")) {
            variantName = reader.nextString();
        } else if (name.equals("attributes")) {
            attributes = consumeAttributes(reader);
        } else if (name.equals("files")) {
            files = consumeFiles(reader);
        } else if (name.equals("dependencies")) {
            dependencies = consumeDependencies(reader);
        } else if (name.equals("dependencyConstraints")) {
            dependencyConstraints = consumeDependencyConstraints(reader);
        } else if (name.equals("capabilities")) {
            capabilities = consumeCapabilities(reader);
        } else if (name.equals("available-at")) {
            // For now just collect this as another dependency
            // TODO - collect this information and merge the metadata from the other module
            dependencies = consumeVariantLocation(reader);
        } else {
            consumeAny(reader);
        }
    }
    reader.endObject();
    MutableComponentVariant variant = metadata.addVariant(variantName, attributes);
    for (ModuleFile file : files) {
        variant.addFile(file.name, file.uri);
    }
    for (ModuleDependency dependency : dependencies) {
        variant.addDependency(dependency.group, dependency.module, dependency.versionConstraint, dependency.excludes, dependency.reason);
    }
    for (ModuleDependencyConstraint dependencyConstraint : dependencyConstraints) {
        variant.addDependencyConstraint(dependencyConstraint.group, dependencyConstraint.module, dependencyConstraint.versionConstraint, dependencyConstraint.reason);
    }
    for (VariantCapability capability : capabilities) {
        variant.addCapability(capability.group, capability.name, capability.version);
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) MutableComponentVariant(org.gradle.internal.component.external.model.MutableComponentVariant)

Example 33 with ImmutableAttributes

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

the class ConsumerProvidedVariantFinder method findProducersFor.

private void findProducersFor(AttributeContainerInternal actual, AttributeContainerInternal requested, ConsumerVariantMatchResult result) {
    // Prefer direct transformation over indirect transformation
    List<VariantTransformRegistry.Registration> candidates = new ArrayList<VariantTransformRegistry.Registration>();
    for (VariantTransformRegistry.Registration transform : variantTransforms.getTransforms()) {
        if (matchAttributes(transform.getTo(), requested)) {
            if (matchAttributes(actual, transform.getFrom())) {
                ImmutableAttributes variantAttributes = attributesFactory.concat(actual.asImmutable(), transform.getTo().asImmutable());
                result.matched(variantAttributes, transform.getArtifactTransform(), 1);
            }
            candidates.add(transform);
        }
    }
    if (result.hasMatches()) {
        return;
    }
    for (final VariantTransformRegistry.Registration candidate : candidates) {
        ConsumerVariantMatchResult inputVariants = new ConsumerVariantMatchResult();
        collectConsumerVariants(actual, candidate.getFrom(), inputVariants);
        if (!inputVariants.hasMatches()) {
            continue;
        }
        for (final ConsumerVariantMatchResult.ConsumerVariant inputVariant : inputVariants.getMatches()) {
            ImmutableAttributes variantAttributes = attributesFactory.concat(inputVariant.attributes.asImmutable(), candidate.getTo().asImmutable());
            ArtifactTransformer transformer = new ChainedTransformer(inputVariant.transformer, candidate.getArtifactTransform());
            result.matched(variantAttributes, transformer, inputVariant.depth + 1);
        }
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ArrayList(java.util.ArrayList) VariantTransformRegistry(org.gradle.api.internal.artifacts.VariantTransformRegistry)

Example 34 with ImmutableAttributes

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

the class ComponentAttributeMatcher method match.

/**
 * Selects the candidates from the given set that are compatible with the requested criteria, according to the given schema.
 */
public <T extends HasAttributes> List<T> match(AttributeSelectionSchema schema, Collection<? extends T> candidates, AttributeContainerInternal requested, @Nullable T fallback) {
    if (candidates.size() == 0) {
        if (fallback != null && isMatching(schema, (AttributeContainerInternal) fallback.getAttributes(), requested)) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("No candidates for {}, selected matching fallback {}", requested, fallback);
            }
            return ImmutableList.of(fallback);
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("No candidates for {} and fallback {} does not match. Select nothing.", requested, fallback);
        }
        return ImmutableList.of();
    }
    if (candidates.size() == 1) {
        T candidate = candidates.iterator().next();
        if (isMatching(schema, (AttributeContainerInternal) candidate.getAttributes(), requested)) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Selected match {} from candidates {} for {}", candidate, candidates, requested);
            }
            return Collections.singletonList(candidate);
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Selected match [] from candidates {} for {}", candidates, requested);
        }
        return ImmutableList.of();
    }
    ImmutableAttributes requestedAttributes = requested.asImmutable();
    List<T> matches = new MultipleCandidateMatcher<T>(schema, candidates, requestedAttributes).getMatches();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Selected matches {} from candidates {} for {}", matches, candidates, requested);
    }
    return matches;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal)

Example 35 with ImmutableAttributes

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

the class MultipleCandidateMatcher method collectExtraAttributes.

/**
 * Collects attributes that were present on the candidates, but which the consumer did
 * not ask for. Some of these attributes might be weakly typed, e.g. coming as Strings
 * from an artifact repository. We always check whether the schema has a more strongly
 * typed version of an attribute and use that one instead to apply its disambiguation
 * rules.
 */
private void collectExtraAttributes() {
    Set<Attribute<?>> extraAttributes = Sets.newLinkedHashSet();
    for (ImmutableAttributes attributes : candidateAttributeSets) {
        extraAttributes.addAll(attributes.keySet());
    }
    extraAttributes.removeAll(requested.keySet());
    this.extraAttributes = extraAttributes.toArray(new Attribute[0]);
    for (int i = 0; i < this.extraAttributes.length; i++) {
        Attribute<?> extraAttribute = this.extraAttributes[i];
        Attribute<?> schemaAttribute = schema.getAttribute(extraAttribute.getName());
        if (schemaAttribute != null) {
            this.extraAttributes[i] = schemaAttribute;
        }
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Attribute(org.gradle.api.attributes.Attribute)

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