Search in sources :

Example 1 with ModuleConfigurationMetadata

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

the class AbstractLazyModuleComponentResolveMetadata method addVariantsByRule.

private Optional<ImmutableList<? extends ConfigurationMetadata>> addVariantsByRule(Optional<ImmutableList<? extends ConfigurationMetadata>> variants) {
    if (variantMetadataRules.getAdditionalVariants().isEmpty()) {
        return variants;
    }
    Map<String, ConfigurationMetadata> variantsByName = variants.or(ImmutableList.of()).stream().collect(Collectors.toMap(ConfigurationMetadata::getName, Function.identity()));
    ImmutableList.Builder<ConfigurationMetadata> builder = new ImmutableList.Builder<>();
    if (variants.isPresent()) {
        builder.addAll(variants.get());
    }
    for (AdditionalVariant additionalVariant : variantMetadataRules.getAdditionalVariants()) {
        String baseName = additionalVariant.getBase();
        ConfigurationMetadata base = null;
        if (baseName != null) {
            if (variants.isPresent()) {
                base = variantsByName.get(baseName);
                if (!additionalVariant.isLenient() && !(base instanceof ModuleConfigurationMetadata)) {
                    throw new InvalidUserDataException("Variant '" + baseName + "' not defined in module " + getId().getDisplayName());
                }
            } else {
                base = getConfiguration(baseName);
                if (!additionalVariant.isLenient() && !(base instanceof ModuleConfigurationMetadata)) {
                    throw new InvalidUserDataException("Configuration '" + baseName + "' not defined in module " + getId().getDisplayName());
                }
            }
        }
        if (baseName == null || base instanceof ModuleConfigurationMetadata) {
            ConfigurationMetadata configurationMetadata = new LazyRuleAwareWithBaseConfigurationMetadata(additionalVariant.getName(), (ModuleConfigurationMetadata) base, getId(), getAttributes(), variantMetadataRules, constructVariantExcludes(base), false);
            builder.add(configurationMetadata);
        }
    }
    return Optional.of(builder.build());
}
Also used : ModuleConfigurationMetadata(org.gradle.internal.component.model.ModuleConfigurationMetadata) ImmutableList(com.google.common.collect.ImmutableList) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ModuleConfigurationMetadata(org.gradle.internal.component.model.ModuleConfigurationMetadata)

Example 2 with ModuleConfigurationMetadata

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

use of org.gradle.internal.component.model.ModuleConfigurationMetadata 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)

Aggregations

InvalidUserDataException (org.gradle.api.InvalidUserDataException)3 ModuleConfigurationMetadata (org.gradle.internal.component.model.ModuleConfigurationMetadata)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 AdditionalVariant (org.gradle.internal.component.external.model.AdditionalVariant)2 ImmutableCapabilities (org.gradle.internal.component.external.model.ImmutableCapabilities)2 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)2 ModuleDependencyMetadata (org.gradle.internal.component.external.model.ModuleDependencyMetadata)1 RealisedConfigurationMetadata (org.gradle.internal.component.external.model.RealisedConfigurationMetadata)1 ExcludeMetadata (org.gradle.internal.component.model.ExcludeMetadata)1