use of org.gradle.api.attributes.AttributesSchema in project gradle by gradle.
the class LocalComponentDependencyMetadata method selectConfigurations.
@Override
public Set<ConfigurationMetadata> selectConfigurations(ComponentResolveMetadata fromComponent, ConfigurationMetadata fromConfiguration, ComponentResolveMetadata targetComponent, AttributesSchema attributesSchema) {
AttributeContainerInternal fromConfigurationAttributes = fromConfiguration.getAttributes();
boolean consumerHasAttributes = !fromConfigurationAttributes.isEmpty();
boolean useConfigurationAttributes = dependencyConfiguration == null && consumerHasAttributes;
AttributesSchema producerAttributeSchema = targetComponent.getAttributesSchema() == null ? attributesSchema : targetComponent.getAttributesSchema();
if (useConfigurationAttributes) {
List<? extends ConfigurationMetadata> consumableConfigurations = targetComponent.getConsumableConfigurationsHavingAttributes();
List<? extends ConfigurationMetadata> matches = ((AttributesSchemaInternal) attributesSchema).getMatches(producerAttributeSchema, consumableConfigurations, fromConfigurationAttributes);
if (matches.size() == 1) {
return ImmutableSet.of(ClientAttributesPreservingConfigurationMetadata.wrapIfLocal(matches.get(0), fromConfigurationAttributes));
} else if (!matches.isEmpty()) {
throw new AmbiguousConfigurationSelectionException(fromConfigurationAttributes, attributesSchema, matches, targetComponent);
}
}
String targetConfiguration = GUtil.elvis(dependencyConfiguration, Dependency.DEFAULT_CONFIGURATION);
ConfigurationMetadata toConfiguration = targetComponent.getConfiguration(targetConfiguration);
if (toConfiguration == null) {
throw new ConfigurationNotFoundException(fromComponent.getComponentId(), moduleConfiguration, targetConfiguration, targetComponent.getComponentId());
}
if (!toConfiguration.isCanBeConsumed()) {
if (dependencyConfiguration == null) {
// this was a fallback to `default`, and `default` is not consumable
Set<String> configurationNames = Sets.newTreeSet();
configurationNames.addAll(targetComponent.getConfigurationNames());
throw new NoMatchingConfigurationSelectionException(fromConfigurationAttributes, attributesSchema, targetComponent, Lists.newArrayList(configurationNames));
}
// explicit configuration selection
throw new ConfigurationNotConsumableException(targetComponent.toString(), toConfiguration.getName());
}
ConfigurationMetadata delegate = toConfiguration;
if (consumerHasAttributes) {
if (!delegate.getAttributes().isEmpty()) {
// need to validate that the selected configuration still matches the consumer attributes
List<ConfigurationMetadata> matches = ((AttributesSchemaInternal) attributesSchema).getMatches(producerAttributeSchema, Collections.singletonList(delegate), fromConfigurationAttributes);
if (matches.isEmpty()) {
throw new IncompatibleConfigurationSelectionException(fromConfigurationAttributes, attributesSchema, targetComponent, targetConfiguration);
}
}
}
if (useConfigurationAttributes) {
delegate = ClientAttributesPreservingConfigurationMetadata.wrapIfLocal(delegate, fromConfigurationAttributes);
}
return ImmutableSet.of(delegate);
}
use of org.gradle.api.attributes.AttributesSchema in project gradle by gradle.
the class JvmEcosystemPlugin method configureSchema.
private void configureSchema(ProjectInternal project) {
AttributesSchema attributesSchema = project.getDependencies().getAttributesSchema();
JavaEcosystemSupport.configureSchema(attributesSchema, objectFactory);
project.getDependencies().getArtifactTypes().create(ArtifactTypeDefinition.JAR_TYPE).getAttributes().attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.JAVA_RUNTIME)).attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objectFactory.named(LibraryElements.class, LibraryElements.JAR));
}
Aggregations