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();
}
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);
}
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();
}
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());
}
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();
}
Aggregations