Search in sources :

Example 6 with ConfigurationMetadata

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

the class NoMatchingConfigurationSelectionException method generateMessage.

private static String generateMessage(AttributeContainerInternal fromConfigurationAttributes, AttributeMatcher attributeMatcher, ComponentResolveMetadata targetComponent) {
    Map<String, ConfigurationMetadata> configurations = new TreeMap<String, ConfigurationMetadata>();
    for (ConfigurationMetadata configurationMetadata : targetComponent.getVariantsForGraphTraversal()) {
        configurations.put(configurationMetadata.getName(), configurationMetadata);
    }
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("Unable to find a matching configuration of " + targetComponent.getId().getDisplayName());
    formatter.startChildren();
    if (configurations.isEmpty()) {
        formatter.node("None of the consumable configurations have attributes.");
    } else {
        // to make sure the output is consistently the same between invocations
        for (ConfigurationMetadata configuration : configurations.values()) {
            formatConfiguration(formatter, fromConfigurationAttributes, attributeMatcher, configuration);
        }
    }
    formatter.endChildren();
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.text.TreeFormatter) TreeMap(java.util.TreeMap) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 7 with ConfigurationMetadata

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

the class IvyDependencyDescriptor method maybeAddConfiguration.

private void maybeAddConfiguration(List<ConfigurationMetadata> configurations, ConfigurationMetadata toAdd) {
    Iterator<ConfigurationMetadata> iter = configurations.iterator();
    while (iter.hasNext()) {
        ConfigurationMetadata configuration = iter.next();
        if (configuration.getHierarchy().contains(toAdd.getName())) {
            // this configuration is a child of toAdd, so no need to add it
            return;
        }
        if (toAdd.getHierarchy().contains(configuration.getName())) {
            // toAdd is a child, so implies this configuration
            iter.remove();
        }
    }
    configurations.add(toAdd);
}
Also used : ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 8 with ConfigurationMetadata

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

the class MavenDependencyDescriptor method selectLegacyConfigurations.

/**
 * Returns a set of configurations from the target component:
 *    - If this dependency is sourced from a 'compile' configuration, choose 'compile' if it exists, or 'default'.
 *    - Otherwise, choose 'runtime' if it exists, or 'default'. Also include 'compile' if it's not a parent of chosen ('runtime'/'default').
 *    - Always include 'master' if it exists, and it has dependencies and/or artifacts.
 */
public List<ConfigurationMetadata> selectLegacyConfigurations(ComponentIdentifier fromComponent, ConfigurationMetadata fromConfiguration, ComponentResolveMetadata targetComponent) {
    ImmutableList.Builder<ConfigurationMetadata> result = ImmutableList.builder();
    boolean requiresCompile = fromConfiguration.getName().equals("compile");
    if (!requiresCompile) {
        // From every configuration other than compile, include both the runtime and compile dependencies
        ConfigurationMetadata runtime = findTargetConfiguration(fromComponent, fromConfiguration, targetComponent, "runtime");
        result.add(runtime);
        requiresCompile = !runtime.getHierarchy().contains("compile");
    }
    if (requiresCompile) {
        // From compile configuration, or when the target's runtime configuration does not extend from compile, include the compile dependencies
        result.add(findTargetConfiguration(fromComponent, fromConfiguration, targetComponent, "compile"));
    }
    ConfigurationMetadata master = targetComponent.getConfiguration("master");
    if (master != null && (!master.getDependencies().isEmpty() || !master.getArtifacts().isEmpty())) {
        result.add(master);
    }
    return result.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 9 with ConfigurationMetadata

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

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

the class NoMatchingConfigurationSelectionException method generateMessage.

private static String generateMessage(AttributeDescriber describer, AttributeContainerInternal fromConfigurationAttributes, AttributeMatcher attributeMatcher, final ComponentResolveMetadata targetComponent, boolean variantAware) {
    Map<String, ConfigurationMetadata> configurations = new TreeMap<>();
    Optional<ImmutableList<? extends ConfigurationMetadata>> variantsForGraphTraversal = targetComponent.getVariantsForGraphTraversal();
    ImmutableList<? extends ConfigurationMetadata> variantsParticipatingInSelection = variantsForGraphTraversal.or(new LegacyConfigurationsSupplier(targetComponent));
    for (ConfigurationMetadata configurationMetadata : variantsParticipatingInSelection) {
        configurations.put(configurationMetadata.getName(), configurationMetadata);
    }
    TreeFormatter formatter = new TreeFormatter();
    String targetVariantText = style(StyledTextOutput.Style.Info, targetComponent.getId().getDisplayName());
    if (fromConfigurationAttributes.isEmpty()) {
        formatter.node("Unable to find a matching " + (variantAware ? "variant" : "configuration") + " of " + targetVariantText);
    } else {
        formatter.node("No matching " + (variantAware ? "variant" : "configuration") + " of " + targetVariantText + " was found. The consumer was configured to find " + describer.describeAttributeSet(fromConfigurationAttributes.asMap()) + " but:");
    }
    formatter.startChildren();
    if (configurations.isEmpty()) {
        formatter.node("None of the " + (variantAware ? "variants" : "consumable configurations") + " have attributes.");
    } else {
        // to make sure the output is consistently the same between invocations
        for (ConfigurationMetadata configuration : configurations.values()) {
            formatConfiguration(formatter, targetComponent, fromConfigurationAttributes, attributeMatcher, configuration, variantAware, false, describer);
        }
    }
    formatter.endChildren();
    return formatter.toString();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) TreeMap(java.util.TreeMap) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

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