use of org.gradle.internal.component.model.ConfigurationMetadata in project gradle by gradle.
the class LegacyConfigurationsSupplier method get.
@Override
public ImmutableList<? extends ConfigurationMetadata> get() {
Set<String> configurationNames = targetComponent.getConfigurationNames();
ImmutableList.Builder<ConfigurationMetadata> builder = new ImmutableList.Builder<>();
for (String configurationName : configurationNames) {
ConfigurationMetadata configuration = targetComponent.getConfiguration(configurationName);
if (configuration.isCanBeConsumed()) {
builder.add(configuration);
}
}
return builder.build();
}
use of org.gradle.internal.component.model.ConfigurationMetadata 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();
}
use of org.gradle.internal.component.model.ConfigurationMetadata in project gradle by gradle.
the class RealisedIvyModuleResolveMetadataSerializationHelper method readIvyConfigurations.
private Map<String, ConfigurationMetadata> readIvyConfigurations(Decoder decoder, DefaultIvyModuleResolveMetadata metadata) throws IOException {
IvyConfigurationHelper configurationHelper = new IvyConfigurationHelper(metadata.getArtifactDefinitions(), new IdentityHashMap<>(), metadata.getExcludes(), metadata.getDependencies(), metadata.getId());
ImmutableMap<String, Configuration> configurationDefinitions = metadata.getConfigurationDefinitions();
int configurationsCount = decoder.readSmallInt();
Map<String, ConfigurationMetadata> configurations = Maps.newHashMapWithExpectedSize(configurationsCount);
for (int i = 0; i < configurationsCount; i++) {
String configurationName = decoder.readString();
boolean transitive = true;
boolean visible = true;
ImmutableSet<String> hierarchy = ImmutableSet.of(configurationName);
ImmutableList<ExcludeMetadata> excludes;
Configuration configuration = configurationDefinitions.get(configurationName);
if (configuration != null) {
// if the configuration represents a variant added by a rule, it is not in the definition list
transitive = configuration.isTransitive();
visible = configuration.isVisible();
hierarchy = LazyToRealisedModuleComponentResolveMetadataHelper.constructHierarchy(configuration, configurationDefinitions);
excludes = configurationHelper.filterExcludes(hierarchy);
} else {
excludes = ImmutableList.of();
}
ImmutableAttributes attributes = getAttributeContainerSerializer().read(decoder);
ImmutableCapabilities capabilities = readCapabilities(decoder);
boolean isExternalVariant = decoder.readBoolean();
boolean hasExplicitExcludes = decoder.readBoolean();
if (hasExplicitExcludes) {
excludes = ImmutableList.copyOf(readMavenExcludes(decoder));
}
ImmutableList<? extends ModuleComponentArtifactMetadata> artifacts = readFiles(decoder, metadata.getId());
RealisedConfigurationMetadata configurationMetadata = new RealisedConfigurationMetadata(metadata.getId(), configurationName, transitive, visible, hierarchy, artifacts, excludes, attributes, capabilities, false, isExternalVariant);
ImmutableList.Builder<ModuleDependencyMetadata> builder = ImmutableList.builder();
int dependenciesCount = decoder.readSmallInt();
for (int j = 0; j < dependenciesCount; j++) {
byte dependencyType = decoder.readByte();
switch(dependencyType) {
case GRADLE_DEPENDENCY_METADATA:
builder.add(readDependencyMetadata(decoder));
break;
case IVY_DEPENDENCY_METADATA:
IvyDependencyDescriptor ivyDependency = readIvyDependency(decoder);
ModuleDependencyMetadata dependencyMetadata = configurationHelper.contextualize(configurationMetadata, metadata.getId(), ivyDependency);
builder.add(dependencyMetadata.withReason(decoder.readNullableString()));
break;
case MAVEN_DEPENDENCY_METADATA:
throw new IllegalStateException("Unexpected Maven dependency for Ivy module");
default:
throw new IllegalStateException("Unknown dependency type " + dependencyType);
}
}
ImmutableList<ModuleDependencyMetadata> dependencies = builder.build();
configurationMetadata.setDependencies(dependencies);
configurations.put(configurationName, configurationMetadata);
}
return configurations;
}
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.
*/
@Override
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 RealisedMavenModuleResolveMetadataSerializationHelper method readMavenConfigurations.
private Map<String, ConfigurationMetadata> readMavenConfigurations(Decoder decoder, DefaultMavenModuleResolveMetadata metadata, Map<Integer, MavenDependencyDescriptor> deduplicationDependencyCache) throws IOException {
ImmutableMap<String, Configuration> configurationDefinitions = metadata.getConfigurationDefinitions();
int configurationsCount = decoder.readSmallInt();
Map<String, ConfigurationMetadata> configurations = Maps.newHashMapWithExpectedSize(configurationsCount);
for (int i = 0; i < configurationsCount; i++) {
String configurationName = decoder.readString();
Configuration configuration = configurationDefinitions.get(configurationName);
ImmutableSet<String> hierarchy = LazyToRealisedModuleComponentResolveMetadataHelper.constructHierarchy(configuration, configurationDefinitions);
ImmutableAttributes attributes = getAttributeContainerSerializer().read(decoder);
ImmutableCapabilities capabilities = readCapabilities(decoder);
boolean isExternalVariant = decoder.readBoolean();
ImmutableList<? extends ModuleComponentArtifactMetadata> artifacts = readFiles(decoder, metadata.getId());
RealisedConfigurationMetadata configurationMetadata = new RealisedConfigurationMetadata(metadata.getId(), configurationName, configuration.isTransitive(), configuration.isVisible(), hierarchy, artifacts, ImmutableList.of(), attributes, capabilities, false, isExternalVariant);
ImmutableList<ModuleDependencyMetadata> dependencies = readDependencies(decoder, metadata, configurationMetadata, deduplicationDependencyCache);
configurationMetadata.setDependencies(dependencies);
configurations.put(configurationName, configurationMetadata);
}
return configurations;
}
Aggregations