Search in sources :

Example 56 with ImmutableAttributes

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

the class RealisedIvyModuleResolveMetadata method addVariantsFromRules.

private static void addVariantsFromRules(DefaultIvyModuleResolveMetadata componentMetadata, Map<String, ConfigurationMetadata> declaredConfigurations, VariantMetadataRules variantMetadataRules) {
    List<AdditionalVariant> additionalVariants = variantMetadataRules.getAdditionalVariants();
    if (additionalVariants.isEmpty()) {
        return;
    }
    for (AdditionalVariant additionalVariant : additionalVariants) {
        String name = additionalVariant.getName();
        String baseName = additionalVariant.getBase();
        ImmutableAttributes attributes;
        ImmutableCapabilities capabilities;
        List<ModuleDependencyMetadata> dependencies;
        ImmutableList<? extends ModuleComponentArtifactMetadata> artifacts;
        ImmutableList<ExcludeMetadata> excludes;
        ModuleConfigurationMetadata baseConf = (ModuleConfigurationMetadata) declaredConfigurations.get(baseName);
        if (baseConf == null) {
            attributes = componentMetadata.getAttributes();
            capabilities = ImmutableCapabilities.EMPTY;
            dependencies = ImmutableList.of();
            artifacts = ImmutableList.of();
            excludes = ImmutableList.of();
        } else {
            attributes = baseConf.getAttributes();
            capabilities = (ImmutableCapabilities) baseConf.getCapabilities();
            dependencies = Cast.uncheckedCast(baseConf.getDependencies());
            artifacts = Cast.uncheckedCast(baseConf.getArtifacts());
            excludes = Cast.uncheckedCast(baseConf.getExcludes());
        }
        if (baseName == null || baseConf != null) {
            declaredConfigurations.put(name, applyRules(componentMetadata.getId(), name, variantMetadataRules, attributes, capabilities, artifacts, excludes, true, true, ImmutableSet.of(), null, dependencies, true, false));
        } else if (!additionalVariant.isLenient()) {
            throw new InvalidUserDataException("Configuration '" + baseName + "' not defined in module " + componentMetadata.getId().getDisplayName());
        }
    }
}
Also used : AdditionalVariant(org.gradle.internal.component.external.model.AdditionalVariant) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ImmutableCapabilities(org.gradle.internal.component.external.model.ImmutableCapabilities) ModuleConfigurationMetadata(org.gradle.internal.component.model.ModuleConfigurationMetadata) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ModuleDependencyMetadata(org.gradle.internal.component.external.model.ModuleDependencyMetadata) ExcludeMetadata(org.gradle.internal.component.model.ExcludeMetadata)

Example 57 with ImmutableAttributes

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

the class RealisedMavenModuleResolveMetadata method applyRules.

private static RealisedConfigurationMetadata applyRules(ModuleComponentIdentifier id, String configurationName, VariantMetadataRules variantMetadataRules, ImmutableAttributes attributes, ImmutableCapabilities capabilities, List<? extends ModuleDependencyMetadata> dependencies, ImmutableList<? extends ModuleComponentArtifactMetadata> artifacts, boolean transitive, boolean visible, ImmutableSet<String> hierarchy, boolean addedByRule, boolean isExternalVariant) {
    NameOnlyVariantResolveMetadata variant = new NameOnlyVariantResolveMetadata(configurationName);
    ImmutableAttributes variantAttributes = variantMetadataRules.applyVariantAttributeRules(variant, attributes);
    CapabilitiesMetadata capabilitiesMetadata = variantMetadataRules.applyCapabilitiesRules(variant, capabilities);
    List<? extends DependencyMetadata> dependenciesMetadata = variantMetadataRules.applyDependencyMetadataRules(variant, dependencies);
    ImmutableList<? extends ModuleComponentArtifactMetadata> artifactsMetadata = variantMetadataRules.applyVariantFilesMetadataRulesToArtifacts(variant, artifacts, id);
    return createConfiguration(id, configurationName, transitive, visible, hierarchy, artifactsMetadata, dependenciesMetadata, variantAttributes, ImmutableCapabilities.of(capabilitiesMetadata.getCapabilities()), addedByRule, isExternalVariant);
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) CapabilitiesMetadata(org.gradle.api.capabilities.CapabilitiesMetadata)

Example 58 with ImmutableAttributes

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

the class RealisedMavenModuleResolveMetadata method addVariantsFromRules.

private static List<ConfigurationMetadata> addVariantsFromRules(ModuleComponentResolveMetadata componentMetadata, ImmutableList<ConfigurationMetadata> derivedVariants, VariantMetadataRules variantMetadataRules) {
    List<AdditionalVariant> additionalVariants = variantMetadataRules.getAdditionalVariants();
    if (additionalVariants.isEmpty()) {
        return derivedVariants;
    }
    ImmutableList.Builder<ConfigurationMetadata> builder = new ImmutableList.Builder<>();
    builder.addAll(derivedVariants);
    Map<String, ConfigurationMetadata> variantsByName = derivedVariants.stream().collect(Collectors.toMap(ConfigurationMetadata::getName, Function.identity()));
    for (AdditionalVariant additionalVariant : additionalVariants) {
        String name = additionalVariant.getName();
        String baseName = additionalVariant.getBase();
        ImmutableAttributes attributes;
        ImmutableCapabilities capabilities;
        List<? extends ModuleDependencyMetadata> dependencies;
        ImmutableList<? extends ModuleComponentArtifactMetadata> artifacts;
        ConfigurationMetadata baseConf = variantsByName.get(baseName);
        if (baseConf == null) {
            attributes = componentMetadata.getAttributes();
            capabilities = ImmutableCapabilities.EMPTY;
            dependencies = ImmutableList.of();
            artifacts = ImmutableList.of();
        } else {
            attributes = baseConf.getAttributes();
            capabilities = (ImmutableCapabilities) baseConf.getCapabilities();
            dependencies = ((ModuleConfigurationMetadata) baseConf).getDependencies();
            artifacts = Cast.uncheckedCast(baseConf.getArtifacts());
        }
        if (baseName == null || baseConf != null) {
            builder.add(applyRules(componentMetadata.getId(), name, variantMetadataRules, attributes, capabilities, dependencies, artifacts, true, true, ImmutableSet.of(), true, false));
        } else if (!additionalVariant.isLenient()) {
            throw new InvalidUserDataException("Variant '" + baseName + "' not defined in module " + componentMetadata.getId().getDisplayName());
        }
    }
    return builder.build();
}
Also used : AdditionalVariant(org.gradle.internal.component.external.model.AdditionalVariant) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ImmutableCapabilities(org.gradle.internal.component.external.model.ImmutableCapabilities) ImmutableList(com.google.common.collect.ImmutableList) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ModuleConfigurationMetadata(org.gradle.internal.component.model.ModuleConfigurationMetadata) RealisedConfigurationMetadata(org.gradle.internal.component.external.model.RealisedConfigurationMetadata) InvalidUserDataException(org.gradle.api.InvalidUserDataException)

Example 59 with ImmutableAttributes

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

the class LazyToRealisedModuleComponentResolveMetadataHelper method applyRules.

private static AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl applyRules(ComponentVariant variant, VariantMetadataRules variantMetadataRules, ModuleComponentIdentifier id) {
    ImmutableAttributes attributes = variantMetadataRules.applyVariantAttributeRules(variant, variant.getAttributes());
    CapabilitiesMetadata capabilitiesMetadata = variantMetadataRules.applyCapabilitiesRules(variant, variant.getCapabilities());
    ImmutableList<? extends ComponentVariant.File> files = variantMetadataRules.applyVariantFilesMetadataRulesToFiles(variant, variant.getFiles(), id);
    boolean force = PlatformSupport.hasForcedDependencies(variant);
    List<GradleDependencyMetadata> dependencies = variantMetadataRules.applyDependencyMetadataRules(variant, convertDependencies(variant.getDependencies(), variant.getDependencyConstraints(), force));
    return new AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl(id, variant.getName(), attributes, variant.getDependencies(), variant.getDependencyConstraints(), files, ImmutableCapabilities.of(capabilitiesMetadata.getCapabilities()), dependencies, variant.isExternalVariant());
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) CapabilitiesMetadata(org.gradle.api.capabilities.CapabilitiesMetadata)

Example 60 with ImmutableAttributes

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

the class AttributeSelectionUtils method collectExtraAttributes.

public static Attribute<?>[] collectExtraAttributes(AttributeSelectionSchema schema, ImmutableAttributes[] candidateAttributeSets, ImmutableAttributes requested) {
    Set<Attribute<?>> extraAttributes = Sets.newLinkedHashSet();
    for (ImmutableAttributes attributes : candidateAttributeSets) {
        extraAttributes.addAll(attributes.keySet());
    }
    removeSameAttributes(requested, extraAttributes);
    Attribute<?>[] extraAttributesArray = extraAttributes.toArray(new Attribute<?>[0]);
    for (int i = 0; i < extraAttributesArray.length; i++) {
        Attribute<?> extraAttribute = extraAttributesArray[i];
        Attribute<?> schemaAttribute = schema.getAttribute(extraAttribute.getName());
        if (schemaAttribute != null) {
            extraAttributesArray[i] = schemaAttribute;
        }
    }
    return extraAttributesArray;
}
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