Search in sources :

Example 6 with VariantResolveMetadata

use of org.gradle.internal.component.model.VariantResolveMetadata in project gradle by gradle.

the class ProjectArtifactSetResolver method mapVariant.

private ResolvedVariant mapVariant(ModuleVersionIdentifier ownerId, ModuleSources moduleSources, ExcludeSpec exclusions, ArtifactTypeRegistry artifactTypeRegistry, VariantResolveMetadata variant) {
    VariantResolveMetadata.Identifier identifier = variant.getIdentifier();
    if (identifier == null) {
        throw new IllegalArgumentException(String.format("Project variant %s does not have an identifier.", variant.asDescribable()));
    }
    // Apply any artifact type mappings to the attributes of the variant
    ImmutableAttributes variantAttributes = artifactTypeRegistry.mapAttributesFor(variant.getAttributes().asImmutable(), variant.getArtifacts());
    if (exclusions.mayExcludeArtifacts()) {
        // Some artifact may be excluded, so do not reuse. It might be better to apply the exclusions and reuse if none of them apply
        return DefaultArtifactSet.toResolvedVariant(variant, ownerId, moduleSources, exclusions, artifactResolver, allProjectArtifacts, variantAttributes, calculatedValueContainerFactory);
    }
    VariantWithOverloadAttributes key = new VariantWithOverloadAttributes(identifier, variantAttributes);
    return allProjectVariants.computeIfAbsent(key, k -> DefaultArtifactSet.toResolvedVariant(variant, ownerId, moduleSources, exclusions, artifactResolver, allProjectArtifacts, variantAttributes, calculatedValueContainerFactory));
}
Also used : VariantWithOverloadAttributes(org.gradle.internal.component.model.VariantWithOverloadAttributes) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) VariantResolveMetadata(org.gradle.internal.component.model.VariantResolveMetadata)

Example 7 with VariantResolveMetadata

use of org.gradle.internal.component.model.VariantResolveMetadata in project gradle by gradle.

the class ProjectArtifactSetResolver method resolveArtifacts.

/**
 * Creates an {@link ArtifactSet} that represents the available artifacts for the given set of project variants.
 */
public ArtifactSet resolveArtifacts(ComponentIdentifier componentIdentifier, ModuleVersionIdentifier ownerId, ModuleSources moduleSources, ExcludeSpec exclusions, Set<? extends VariantResolveMetadata> variants, AttributesSchemaInternal schema, ArtifactTypeRegistry artifactTypeRegistry, ImmutableAttributes selectionAttributes) {
    ImmutableSet.Builder<ResolvedVariant> result = ImmutableSet.builderWithExpectedSize(variants.size());
    for (VariantResolveMetadata variant : variants) {
        ResolvedVariant resolvedVariant = mapVariant(ownerId, moduleSources, exclusions, artifactTypeRegistry, variant);
        result.add(resolvedVariant);
    }
    return DefaultArtifactSet.createFromVariants(componentIdentifier, result.build(), schema, selectionAttributes);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ResolvedVariant(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant) VariantResolveMetadata(org.gradle.internal.component.model.VariantResolveMetadata)

Example 8 with VariantResolveMetadata

use of org.gradle.internal.component.model.VariantResolveMetadata in project gradle by gradle.

the class DefaultArtifactSet method adHocVariant.

public static ArtifactSet adHocVariant(ComponentIdentifier componentIdentifier, ModuleVersionIdentifier ownerId, Collection<? extends ComponentArtifactMetadata> artifacts, ModuleSources moduleSources, ExcludeSpec exclusions, AttributesSchemaInternal schema, ArtifactResolver artifactResolver, Map<ComponentArtifactIdentifier, ResolvableArtifact> allResolvedArtifacts, ArtifactTypeRegistry artifactTypeRegistry, ImmutableAttributes variantAttributes, ImmutableAttributes selectionAttributes, CalculatedValueContainerFactory calculatedValueContainerFactory) {
    VariantResolveMetadata.Identifier identifier = null;
    if (artifacts.size() == 1) {
        identifier = new SingleArtifactVariantIdentifier(artifacts.iterator().next().getId());
    }
    VariantResolveMetadata variantMetadata = new DefaultVariantMetadata(null, identifier, Describables.of(componentIdentifier), variantAttributes, ImmutableList.copyOf(artifacts), ImmutableCapabilities.EMPTY);
    ResolvedVariant resolvedVariant = toResolvedVariant(variantMetadata, ownerId, moduleSources, exclusions, artifactResolver, allResolvedArtifacts, artifactTypeRegistry, calculatedValueContainerFactory);
    return new SingleVariantArtifactSet(componentIdentifier, schema, resolvedVariant, selectionAttributes);
}
Also used : VariantResolveMetadata(org.gradle.internal.component.model.VariantResolveMetadata) DefaultVariantMetadata(org.gradle.internal.component.model.DefaultVariantMetadata)

Example 9 with VariantResolveMetadata

use of org.gradle.internal.component.model.VariantResolveMetadata in project gradle by gradle.

the class DefaultArtifactSet method createFromVariantMetadata.

public static ArtifactSet createFromVariantMetadata(ComponentIdentifier componentIdentifier, ModuleVersionIdentifier ownerId, ModuleSources moduleSources, ExcludeSpec exclusions, Set<? extends VariantResolveMetadata> variants, AttributesSchemaInternal schema, ArtifactResolver artifactResolver, Map<ComponentArtifactIdentifier, ResolvableArtifact> allResolvedArtifacts, ArtifactTypeRegistry artifactTypeRegistry, ImmutableAttributes selectionAttributes, CalculatedValueContainerFactory calculatedValueContainerFactory) {
    if (variants.size() == 1) {
        VariantResolveMetadata variantMetadata = variants.iterator().next();
        ResolvedVariant resolvedVariant = toResolvedVariant(variantMetadata, ownerId, moduleSources, exclusions, artifactResolver, allResolvedArtifacts, artifactTypeRegistry, calculatedValueContainerFactory);
        return new SingleVariantArtifactSet(componentIdentifier, schema, resolvedVariant, selectionAttributes);
    }
    ImmutableSet.Builder<ResolvedVariant> result = ImmutableSet.builder();
    for (VariantResolveMetadata variant : variants) {
        ResolvedVariant resolvedVariant = toResolvedVariant(variant, ownerId, moduleSources, exclusions, artifactResolver, allResolvedArtifacts, artifactTypeRegistry, calculatedValueContainerFactory);
        result.add(resolvedVariant);
    }
    return new MultipleVariantArtifactSet(componentIdentifier, schema, result.build(), selectionAttributes);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) VariantResolveMetadata(org.gradle.internal.component.model.VariantResolveMetadata)

Aggregations

VariantResolveMetadata (org.gradle.internal.component.model.VariantResolveMetadata)9 ImmutableSet (com.google.common.collect.ImmutableSet)4 DefaultVariantMetadata (org.gradle.internal.component.model.DefaultVariantMetadata)4 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)3 File (java.io.File)2 ArtifactTypeRegistry (org.gradle.api.internal.artifacts.type.ArtifactTypeRegistry)2 ComponentConfigurationIdentifier (org.gradle.internal.component.model.ComponentConfigurationIdentifier)2 ImmutableList (com.google.common.collect.ImmutableList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 Describable (org.gradle.api.Describable)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ComponentArtifactIdentifier (org.gradle.api.artifacts.component.ComponentArtifactIdentifier)1 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1 ArtifactTypeContainer (org.gradle.api.artifacts.type.ArtifactTypeContainer)1 CapabilitiesMetadata (org.gradle.api.capabilities.CapabilitiesMetadata)1