Search in sources :

Example 1 with ConfigurationMetadata

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

the class NoMatchingConfigurationSelectionException method generateMessage.

private static String generateMessage(AttributeContainer fromConfigurationAttributes, AttributesSchema consumerSchema, ComponentResolveMetadata targetComponent, List<String> configurationNames) {
    List<ConfigurationMetadata> configurations = new ArrayList<ConfigurationMetadata>(configurationNames.size());
    for (String name : configurationNames) {
        ConfigurationMetadata targetComponentConfiguration = targetComponent.getConfiguration(name);
        if (targetComponentConfiguration.isCanBeConsumed() && !targetComponentConfiguration.getAttributes().isEmpty()) {
            configurations.add(targetComponentConfiguration);
        }
    }
    Set<String> requestedAttributes = Sets.newTreeSet(Iterables.transform(fromConfigurationAttributes.keySet(), ATTRIBUTE_NAME));
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("Unable to find a matching configuration in " + targetComponent.getComponentId().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 (String config : configurationNames) {
            formatConfiguration(formatter, fromConfigurationAttributes, consumerSchema, configurations, requestedAttributes, config);
        }
    }
    formatter.endChildren();
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.text.TreeFormatter) ArrayList(java.util.ArrayList) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 2 with ConfigurationMetadata

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

the class MavenDependencyMetadata method selectConfigurations.

@Override
public Set<ConfigurationMetadata> selectConfigurations(ComponentResolveMetadata fromComponent, ConfigurationMetadata fromConfiguration, ComponentResolveMetadata targetComponent, AttributesSchema attributesSchema) {
    Set<ConfigurationMetadata> result = Sets.newLinkedHashSet();
    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;
}
Also used : ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 3 with ConfigurationMetadata

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

the class DefaultResolvedArtifactsBuilder method visitArtifacts.

@Override
public void visitArtifacts(DependencyGraphNode from, DependencyGraphNode to, ArtifactSet artifacts) {
    if (sortOrder != ResolutionStrategy.SortOrder.DEFAULT) {
        sortedNodeIds.get(to.getNodeId()).add(artifacts);
    } else {
        artifactSets.put(artifacts.getId(), artifacts);
    }
    // Don't collect build dependencies if not required
    if (!buildProjectDependencies) {
        return;
    }
    if (buildableArtifactSets.contains(artifacts.getId())) {
        return;
    }
    // Collect the build dependencies in 2 steps: collect the artifact sets while traversing and at the end of traversal unpack the build dependencies for each
    // We need to discard the artifact sets to avoid keeping strong references
    ConfigurationMetadata configurationMetadata = to.getMetadata();
    if (!(configurationMetadata instanceof LocalConfigurationMetadata)) {
        return;
    }
    if (from.getOwner().getComponentId() instanceof ProjectComponentIdentifier) {
        // This is here to attempt to leave out build dependencies that would cause a cycle in the task graph for the current build, so that the cross-build cycle detection kicks in. It's not fully correct
        ProjectComponentIdentifier incomingId = (ProjectComponentIdentifier) from.getOwner().getComponentId();
        if (!incomingId.getBuild().isCurrentBuild()) {
            return;
        }
    }
    buildableArtifactSets.add(artifacts.getId());
}
Also used : LocalConfigurationMetadata(org.gradle.internal.component.local.model.LocalConfigurationMetadata) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) LocalConfigurationMetadata(org.gradle.internal.component.local.model.LocalConfigurationMetadata)

Example 4 with ConfigurationMetadata

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

the class DefaultResolvedArtifactsBuilder method visitArtifacts.

@Override
public void visitArtifacts(DependencyGraphNode from, DependencyGraphNode to, int artifactSetId, ArtifactSet artifacts) {
    // Don't collect build dependencies if not required
    if (!buildProjectDependencies) {
        artifacts = new NoBuildDependenciesArtifactSet(artifacts);
    } else {
        ConfigurationMetadata configurationMetadata = to.getMetadata();
        if (configurationMetadata instanceof LocalConfigurationMetadata) {
            // For a dependency from _another_ build to _this_ build, don't make the artifact buildable
            // Making these artifacts buildable leads to poor error reporting due to direct task dependency cycle (losing the intervening build dependencies)
            ComponentIdentifier incomingId = from.getOwner().getComponentId();
            ComponentIdentifier outgoingId = to.getOwner().getComponentId();
            if (incomingId instanceof ProjectComponentIdentifier && outgoingId instanceof ProjectComponentIdentifier) {
                if (!isCurrentBuild(incomingId) && isCurrentBuild(outgoingId)) {
                    artifacts = new NoBuildDependenciesArtifactSet(artifacts);
                }
            }
        }
    }
    collectArtifacts(artifactSetId, artifacts);
}
Also used : ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) LocalConfigurationMetadata(org.gradle.internal.component.local.model.LocalConfigurationMetadata) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) LocalConfigurationMetadata(org.gradle.internal.component.local.model.LocalConfigurationMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 5 with ConfigurationMetadata

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

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