Search in sources :

Example 1 with DefaultVariantVersionMappingStrategy

use of org.gradle.api.publish.internal.versionmapping.DefaultVariantVersionMappingStrategy in project gradle by gradle.

the class DefaultVersionMappingStrategy method findStrategyForVariant.

@Override
public VariantVersionMappingStrategyInternal findStrategyForVariant(ImmutableAttributes variantAttributes) {
    DefaultVariantVersionMappingStrategy strategy = createDefaultMappingStrategy(variantAttributes);
    // Apply strategies for "all variants"
    for (Action<? super VariantVersionMappingStrategy> action : mappingsForAllVariants) {
        action.execute(strategy);
    }
    // Then use attribute specific mapping
    if (!attributeBasedMappings.isEmpty()) {
        AttributeMatcher matcher = schema.matcher();
        Set<ImmutableAttributes> candidates = attributeBasedMappings.keySet();
        List<ImmutableAttributes> matches = matcher.matches(candidates, variantAttributes, AttributeMatchingExplanationBuilder.NO_OP);
        if (matches.size() == 1) {
            Collection<Action<? super VariantVersionMappingStrategy>> actions = attributeBasedMappings.get(matches.get(0));
            for (Action<? super VariantVersionMappingStrategy> action : actions) {
                action.execute(strategy);
            }
        } else if (matches.size() > 1) {
            throw new InvalidUserCodeException("Unable to find a suitable version mapping strategy for " + variantAttributes);
        }
    }
    return strategy;
}
Also used : AttributeMatcher(org.gradle.internal.component.model.AttributeMatcher) Action(org.gradle.api.Action) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) DefaultVariantVersionMappingStrategy(org.gradle.api.publish.internal.versionmapping.DefaultVariantVersionMappingStrategy) DefaultVariantVersionMappingStrategy(org.gradle.api.publish.internal.versionmapping.DefaultVariantVersionMappingStrategy) VariantVersionMappingStrategy(org.gradle.api.publish.VariantVersionMappingStrategy)

Example 2 with DefaultVariantVersionMappingStrategy

use of org.gradle.api.publish.internal.versionmapping.DefaultVariantVersionMappingStrategy in project gradle by gradle.

the class DefaultVersionMappingStrategy method createDefaultMappingStrategy.

private DefaultVariantVersionMappingStrategy createDefaultMappingStrategy(ImmutableAttributes variantAttributes) {
    DefaultVariantVersionMappingStrategy strategy = new DefaultVariantVersionMappingStrategy(configurations, projectResolver, projectRegistry);
    if (!defaultConfigurations.isEmpty()) {
        // First need to populate the default variant version mapping strategy with the default values
        // provided by plugins
        AttributeMatcher matcher = schema.matcher();
        Set<ImmutableAttributes> candidates = defaultConfigurations.keySet();
        List<ImmutableAttributes> matches = matcher.matches(candidates, variantAttributes, AttributeMatchingExplanationBuilder.NO_OP);
        for (ImmutableAttributes match : matches) {
            strategy.setTargetConfiguration(configurations.getByName(defaultConfigurations.get(match)));
        }
    }
    return strategy;
}
Also used : AttributeMatcher(org.gradle.internal.component.model.AttributeMatcher) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) DefaultVariantVersionMappingStrategy(org.gradle.api.publish.internal.versionmapping.DefaultVariantVersionMappingStrategy)

Aggregations

ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 DefaultVariantVersionMappingStrategy (org.gradle.api.publish.internal.versionmapping.DefaultVariantVersionMappingStrategy)2 AttributeMatcher (org.gradle.internal.component.model.AttributeMatcher)2 Action (org.gradle.api.Action)1 InvalidUserCodeException (org.gradle.api.InvalidUserCodeException)1 VariantVersionMappingStrategy (org.gradle.api.publish.VariantVersionMappingStrategy)1