Search in sources :

Example 6 with TreeFormatter

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

the class DefaultProjectDependencyPublicationResolver method resolve.

@Override
public <T> T resolve(Class<T> coordsType, ProjectDependency dependency) {
    // Could probably apply some caching and some immutable types
    ProjectInternal dependencyProject = (ProjectInternal) dependency.getDependencyProject();
    // Ensure target project is configured
    projectConfigurer.configureFully(dependencyProject);
    List<ProjectPublication> publications = new ArrayList<ProjectPublication>();
    for (ProjectPublication publication : publicationRegistry.getPublications(dependencyProject.getPath())) {
        if (!publication.isLegacy() && publication.getCoordinates(coordsType) != null) {
            publications.add(publication);
        }
    }
    if (publications.isEmpty()) {
        // Project has no publications: simply use the project name in place of the dependency name
        if (coordsType.isAssignableFrom(ModuleVersionIdentifier.class)) {
            return coordsType.cast(new DefaultModuleVersionIdentifier(dependency.getGroup(), dependencyProject.getName(), dependency.getVersion()));
        }
        throw new UnsupportedOperationException(String.format("Could not find any publications of type %s in %s.", coordsType.getSimpleName(), dependencyProject.getDisplayName()));
    }
    // Select all entry points. An entry point is a publication that does not contain a component whose parent is also published
    Set<SoftwareComponent> ignored = new HashSet<SoftwareComponent>();
    for (ProjectPublication publication : publications) {
        if (publication.getComponent() != null && publication.getComponent() instanceof ComponentWithVariants) {
            ComponentWithVariants parent = (ComponentWithVariants) publication.getComponent();
            ignored.addAll(parent.getVariants());
        }
    }
    Set<ProjectPublication> topLevel = new LinkedHashSet<ProjectPublication>();
    for (ProjectPublication publication : publications) {
        if (!publication.isAlias() && (publication.getComponent() == null || !ignored.contains(publication.getComponent()))) {
            topLevel.add(publication);
        }
    }
    // See if all entry points have the same identifier
    Iterator<ProjectPublication> iterator = topLevel.iterator();
    T candidate = iterator.next().getCoordinates(coordsType);
    while (iterator.hasNext()) {
        T alternative = iterator.next().getCoordinates(coordsType);
        if (!candidate.equals(alternative)) {
            TreeFormatter formatter = new TreeFormatter();
            formatter.node("Publishing is not able to resolve a dependency on a project with multiple publications that have different coordinates.");
            formatter.node("Found the following publications in " + dependencyProject.getDisplayName());
            formatter.startChildren();
            for (ProjectPublication publication : topLevel) {
                formatter.node(publication.getDisplayName().getCapitalizedDisplayName() + " with coordinates " + publication.getCoordinates(coordsType));
            }
            formatter.endChildren();
            throw new UnsupportedOperationException(formatter.toString());
        }
    }
    return candidate;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ArrayList(java.util.ArrayList) ComponentWithVariants(org.gradle.api.component.ComponentWithVariants) TreeFormatter(org.gradle.internal.text.TreeFormatter) SoftwareComponent(org.gradle.api.component.SoftwareComponent) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 7 with TreeFormatter

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

the class AmbiguousConfigurationSelectionException method generateMessage.

private static String generateMessage(AttributeContainerInternal fromConfigurationAttributes, AttributeMatcher attributeMatcher, List<? extends ConfigurationMetadata> matches, ComponentResolveMetadata targetComponent) {
    Map<String, ConfigurationMetadata> ambiguousConfigurations = new TreeMap<String, ConfigurationMetadata>();
    for (ConfigurationMetadata match : matches) {
        ambiguousConfigurations.put(match.getName(), match);
    }
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("Cannot choose between the following configurations of ");
    formatter.append(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, fromConfigurationAttributes, attributeMatcher, ambiguousConf);
    }
    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 8 with TreeFormatter

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

use of org.gradle.internal.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) {
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("No variants of " + producerDisplayName + " match the consumer attributes");
    formatter.startChildren();
    for (ResolvedVariant variant : candidates) {
        formatter.node(variant.asDescribable().getCapitalizedDisplayName());
        formatAttributeMatches(formatter, consumer, matcher, variant.getAttributes());
    }
    formatter.endChildren();
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.text.TreeFormatter) ResolvedVariant(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)

Example 10 with TreeFormatter

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

the class UnavailablePlatformToolProvider method failure.

private RuntimeException failure() {
    TreeFormatter formatter = new TreeFormatter();
    this.explain(formatter);
    return new GradleException(formatter.toString());
}
Also used : TreeFormatter(org.gradle.internal.text.TreeFormatter) GradleException(org.gradle.api.GradleException)

Aggregations

TreeFormatter (org.gradle.internal.text.TreeFormatter)14 ResolvedVariant (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)3 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)3 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 GradleException (org.gradle.api.GradleException)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 ComponentWithVariants (org.gradle.api.component.ComponentWithVariants)1 SoftwareComponent (org.gradle.api.component.SoftwareComponent)1 DefaultModuleVersionIdentifier (org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier)1 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)1 BinaryBuildAbility (org.gradle.platform.base.internal.BinaryBuildAbility)1 BinarySpecInternal (org.gradle.platform.base.internal.BinarySpecInternal)1