Search in sources :

Example 1 with TreeFormatter

use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.

the class IncompatibleDependencyAttributesMessageBuilder method buildMergeErrorMessage.

static String buildMergeErrorMessage(ModuleResolveState module, AttributeMergingException e) {
    Attribute<?> attribute = e.getAttribute();
    TreeFormatter fmt = new TreeFormatter();
    fmt.node("Cannot select a variant of '" + module.getId());
    fmt.append("' because different values for attribute '");
    fmt.append(attribute.toString());
    fmt.append("' are requested");
    fmt.startChildren();
    Set<EdgeState> incomingEdges = module.getIncomingEdges();
    incomingEdges.addAll(module.getUnattachedDependencies());
    for (EdgeState incomingEdge : incomingEdges) {
        SelectorState selector = incomingEdge.getSelector();
        for (String path : pathTo(incomingEdge, false)) {
            String requestedAttribute = formatAttributeQuery(selector, attribute);
            fmt.node(path + " " + requestedAttribute);
        }
    }
    fmt.endChildren();
    return fmt.toString();
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter)

Example 2 with TreeFormatter

use of org.gradle.internal.logging.text.TreeFormatter 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)

Example 3 with TreeFormatter

use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.

the class AmbiguousVariantSelectionException method format.

private static String format(AttributeDescriber describer, String producerDisplayName, AttributeContainerInternal consumer, List<? extends ResolvedVariant> variants, AttributeMatcher matcher, Set<ResolvedVariant> discarded) {
    TreeFormatter formatter = new TreeFormatter();
    if (consumer.getAttributes().isEmpty()) {
        formatter.node("More than one variant of " + producerDisplayName + " matches the consumer attributes");
    } else {
        formatter.node("The consumer was configured to find " + describer.describeAttributeSet(consumer.asMap()) + ". However we cannot choose between the following variants of " + producerDisplayName);
    }
    formatter.startChildren();
    for (ResolvedVariant variant : variants) {
        formatter.node(variant.asDescribable().getCapitalizedDisplayName());
        formatAttributeMatchesForAmbiguity(formatter, consumer.asImmutable(), matcher, variant.getAttributes().asImmutable(), describer);
    }
    formatter.endChildren();
    if (!discarded.isEmpty()) {
        formatter.node("The following variants were also considered but didn't match the requested attributes:");
        formatter.startChildren();
        discarded.stream().sorted(Comparator.comparing(v -> v.asDescribable().getCapitalizedDisplayName())).forEach(discardedVariant -> {
            formatter.node(discardedVariant.asDescribable().getCapitalizedDisplayName());
            formatAttributeMatchesForIncompatibility(formatter, consumer.asImmutable(), matcher, discardedVariant.getAttributes().asImmutable(), describer);
        });
        formatter.endChildren();
    }
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) ResolvedVariant(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)

Example 4 with TreeFormatter

use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.

the class AmbiguousConfigurationSelectionException method generateMessage.

private static String generateMessage(AttributeDescriber describer, AttributeContainerInternal fromConfigurationAttributes, AttributeMatcher attributeMatcher, List<? extends ConfigurationMetadata> matches, Set<ConfigurationMetadata> discarded, ComponentResolveMetadata targetComponent, boolean variantAware) {
    Map<String, ConfigurationMetadata> ambiguousConfigurations = new TreeMap<>();
    for (ConfigurationMetadata match : matches) {
        ambiguousConfigurations.put(match.getName(), match);
    }
    TreeFormatter formatter = new TreeFormatter();
    String configTerm = variantAware ? "variants" : "configurations";
    if (fromConfigurationAttributes.isEmpty()) {
        formatter.node("Cannot choose between the following " + configTerm + " of ");
    } else {
        formatter.node("The consumer was configured to find " + describer.describeAttributeSet(fromConfigurationAttributes.asMap()) + ". However we cannot choose between the following " + configTerm + " of ");
    }
    formatter.append(style(StyledTextOutput.Style.Info, targetComponent.getId().getDisplayName()));
    formatter.startChildren();
    for (String configuration : ambiguousConfigurations.keySet()) {
        formatter.node(configuration);
    }
    formatter.endChildren();
    formatter.node("All of them match the consumer attributes");
    // We're sorting the names of the configurations and later attributes
    // to make sure the output is consistently the same between invocations
    formatter.startChildren();
    for (ConfigurationMetadata ambiguousConf : ambiguousConfigurations.values()) {
        formatConfiguration(formatter, targetComponent, fromConfigurationAttributes, attributeMatcher, ambiguousConf, variantAware, true, describer);
    }
    formatter.endChildren();
    if (!discarded.isEmpty()) {
        formatter.node("The following " + configTerm + " were also considered but didn't match the requested attributes:");
        formatter.startChildren();
        discarded.stream().sorted(Comparator.comparing(ConfigurationMetadata::getName)).forEach(discardedConf -> formatConfiguration(formatter, targetComponent, fromConfigurationAttributes, attributeMatcher, discardedConf, variantAware, false, describer));
        formatter.endChildren();
    }
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) TreeMap(java.util.TreeMap) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 5 with TreeFormatter

use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.

the class NoMatchingVariantSelectionException method format.

private static String format(String producerDisplayName, AttributeContainerInternal consumer, Collection<? extends ResolvedVariant> candidates, AttributeMatcher matcher, AttributeDescriber describer) {
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("No variants of " + style(StyledTextOutput.Style.Info, producerDisplayName) + " match the consumer attributes");
    formatter.startChildren();
    for (ResolvedVariant variant : candidates) {
        formatter.node(variant.asDescribable().getCapitalizedDisplayName());
        formatAttributeMatchesForIncompatibility(formatter, consumer.asImmutable(), matcher, variant.getAttributes().asImmutable(), describer);
    }
    formatter.endChildren();
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) ResolvedVariant(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)

Aggregations

TreeFormatter (org.gradle.internal.logging.text.TreeFormatter)46 ImmutableList (com.google.common.collect.ImmutableList)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Nullable (javax.annotation.Nullable)3 GradleException (org.gradle.api.GradleException)3 VariantTransformConfigurationException (org.gradle.api.artifacts.transform.VariantTransformConfigurationException)3 ResolvedVariant (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)3 Lists (com.google.common.collect.Lists)2 File (java.io.File)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 InvalidUserDataException (org.gradle.api.InvalidUserDataException)2 ArtifactTransformRegistration (org.gradle.api.internal.artifacts.ArtifactTransformRegistration)2 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)2 ClassGenerationException (org.gradle.internal.instantiation.ClassGenerationException)2 Solution (org.gradle.problems.Solution)2 ImmutableMap (com.google.common.collect.ImmutableMap)1