Search in sources :

Example 31 with ConfigurationMetadata

use of org.gradle.internal.component.model.ConfigurationMetadata 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 32 with ConfigurationMetadata

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

the class RealisedMavenModuleResolveMetadataSerializationHelper method writeDerivedVariants.

private void writeDerivedVariants(Encoder encoder, RealisedMavenModuleResolveMetadata metadata, Map<ExternalDependencyDescriptor, Integer> deduplicationDependencyCache) throws IOException {
    ImmutableList<? extends ConfigurationMetadata> derivedVariants = metadata.getDerivedVariants();
    encoder.writeSmallInt(derivedVariants.size());
    for (ConfigurationMetadata derivedVariant : derivedVariants) {
        writeConfiguration(encoder, derivedVariant);
        writeFiles(encoder, derivedVariant.getArtifacts());
        writeDerivedVariantExtra(encoder, derivedVariant, deduplicationDependencyCache);
    }
}
Also used : ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) RealisedConfigurationMetadata(org.gradle.internal.component.external.model.RealisedConfigurationMetadata)

Aggregations

ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)32 ImmutableList (com.google.common.collect.ImmutableList)10 RealisedConfigurationMetadata (org.gradle.internal.component.external.model.RealisedConfigurationMetadata)8 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)6 ModuleConfigurationMetadata (org.gradle.internal.component.model.ModuleConfigurationMetadata)6 TreeMap (java.util.TreeMap)4 ModuleDependencyMetadata (org.gradle.internal.component.external.model.ModuleDependencyMetadata)4 ImmutableCapabilities (org.gradle.internal.component.external.model.ImmutableCapabilities)3 ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)3 ConfigurationNotFoundException (org.gradle.internal.component.model.ConfigurationNotFoundException)3 TreeFormatter (org.gradle.internal.text.TreeFormatter)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)2 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 Configuration (org.gradle.internal.component.external.descriptor.Configuration)2 VariantMetadataRules (org.gradle.internal.component.external.model.VariantMetadataRules)2 LocalConfigurationMetadata (org.gradle.internal.component.local.model.LocalConfigurationMetadata)2 TreeFormatter (org.gradle.internal.logging.text.TreeFormatter)2 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1