Search in sources :

Example 1 with AttributesSchemaInternal

use of org.gradle.api.internal.attributes.AttributesSchemaInternal 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);
}
Also used : ConfigurationNotConsumableException(org.gradle.internal.exceptions.ConfigurationNotConsumableException) AmbiguousConfigurationSelectionException(org.gradle.internal.component.AmbiguousConfigurationSelectionException) AttributesSchema(org.gradle.api.attributes.AttributesSchema) AttributesSchemaInternal(org.gradle.api.internal.attributes.AttributesSchemaInternal) NoMatchingConfigurationSelectionException(org.gradle.internal.component.NoMatchingConfigurationSelectionException) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) LocalConfigurationMetadata(org.gradle.internal.component.local.model.LocalConfigurationMetadata) IncompatibleConfigurationSelectionException(org.gradle.internal.component.IncompatibleConfigurationSelectionException)

Example 2 with AttributesSchemaInternal

use of org.gradle.api.internal.attributes.AttributesSchemaInternal in project gradle by gradle.

the class DefaultConfiguration method toRootComponentMetaData.

public ComponentResolveMetadata toRootComponentMetaData() {
    Module module = getModule();
    ComponentIdentifier componentIdentifier = componentIdentifierFactory.createComponentIdentifier(module);
    ModuleVersionIdentifier moduleVersionIdentifier = moduleIdentifierFactory.moduleWithVersion(module.getGroup(), module.getName(), module.getVersion());
    ProjectInternal project = projectFinder.findProject(module.getProjectPath());
    AttributesSchemaInternal schema = project == null ? null : (AttributesSchemaInternal) project.getDependencies().getAttributesSchema();
    DefaultLocalComponentMetadata metaData = new DefaultLocalComponentMetadata(moduleVersionIdentifier, componentIdentifier, module.getStatus(), schema);
    configurationComponentMetaDataBuilder.addConfigurations(metaData, configurationsProvider.getAll());
    return metaData;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultLocalComponentMetadata(org.gradle.internal.component.local.model.DefaultLocalComponentMetadata) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) Module(org.gradle.api.internal.artifacts.Module) AttributesSchemaInternal(org.gradle.api.internal.attributes.AttributesSchemaInternal)

Aggregations

AttributesSchemaInternal (org.gradle.api.internal.attributes.AttributesSchemaInternal)2 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)1 AttributesSchema (org.gradle.api.attributes.AttributesSchema)1 Module (org.gradle.api.internal.artifacts.Module)1 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)1 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)1 AmbiguousConfigurationSelectionException (org.gradle.internal.component.AmbiguousConfigurationSelectionException)1 IncompatibleConfigurationSelectionException (org.gradle.internal.component.IncompatibleConfigurationSelectionException)1 NoMatchingConfigurationSelectionException (org.gradle.internal.component.NoMatchingConfigurationSelectionException)1 DefaultLocalComponentMetadata (org.gradle.internal.component.local.model.DefaultLocalComponentMetadata)1 LocalConfigurationMetadata (org.gradle.internal.component.local.model.LocalConfigurationMetadata)1 ConfigurationNotConsumableException (org.gradle.internal.exceptions.ConfigurationNotConsumableException)1