Search in sources :

Example 6 with Capability

use of org.gradle.api.capabilities.Capability in project gradle by gradle.

the class AttributeConfigurationSelector method providesAllCapabilities.

/**
 * Determines if a producer variant provides all the requested capabilities. When doing so it does
 * NOT consider capability versions, as they will be used later in the engine during conflict resolution.
 */
private static MatchResult providesAllCapabilities(ComponentResolveMetadata targetComponent, Collection<? extends Capability> explicitRequestedCapabilities, List<? extends Capability> providerCapabilities) {
    if (providerCapabilities.isEmpty()) {
        // producer doesn't declare anything, so we assume that it only provides the implicit capability
        if (explicitRequestedCapabilities.size() == 1) {
            Capability requested = explicitRequestedCapabilities.iterator().next();
            ModuleVersionIdentifier mvi = targetComponent.getModuleVersionId();
            if (requested.getGroup().equals(mvi.getGroup()) && requested.getName().equals(mvi.getName())) {
                return MatchResult.EXACT_MATCH;
            }
        }
    }
    for (Capability requested : explicitRequestedCapabilities) {
        String requestedGroup = requested.getGroup();
        String requestedName = requested.getName();
        boolean found = false;
        for (Capability provided : providerCapabilities) {
            if (provided.getGroup().equals(requestedGroup) && provided.getName().equals(requestedName)) {
                found = true;
                break;
            }
        }
        if (!found) {
            return MatchResult.NO_MATCH;
        }
    }
    boolean exactMatch = explicitRequestedCapabilities.size() == providerCapabilities.size();
    return exactMatch ? MatchResult.EXACT_MATCH : MatchResult.MATCHES_ALL;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) Capability(org.gradle.api.capabilities.Capability) ShadowedCapability(org.gradle.internal.component.external.model.ShadowedCapability)

Example 7 with Capability

use of org.gradle.api.capabilities.Capability in project gradle by gradle.

the class GradleModuleMetadataParser method maybeAddEnforcedPlatformVariant.

private void maybeAddEnforcedPlatformVariant(MutableModuleComponentResolveMetadata metadata) {
    List<? extends MutableComponentVariant> variants = metadata.getMutableVariants();
    if (variants == null || variants.isEmpty()) {
        return;
    }
    for (MutableComponentVariant variant : ImmutableList.copyOf(variants)) {
        AttributeValue<String> entry = variant.getAttributes().findEntry(MavenImmutableAttributesFactory.CATEGORY_ATTRIBUTE);
        if (entry.isPresent() && Category.REGULAR_PLATFORM.equals(entry.get()) && variant.getCapabilities().isEmpty()) {
            // This generates a synthetic enforced platform variant with the same dependencies, similar to what the Maven variant derivation strategy does
            ImmutableAttributes enforcedAttributes = attributesFactory.concat(variant.getAttributes(), MavenImmutableAttributesFactory.CATEGORY_ATTRIBUTE, new CoercingStringValueSnapshot(Category.ENFORCED_PLATFORM, instantiator));
            Capability enforcedCapability = buildShadowPlatformCapability(metadata.getId());
            metadata.addVariant(variant.copy("enforced" + capitalize(variant.getName()), enforcedAttributes, enforcedCapability));
        }
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) DefaultShadowedCapability(org.gradle.internal.component.external.model.DefaultShadowedCapability) ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) Capability(org.gradle.api.capabilities.Capability) CoercingStringValueSnapshot(org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot) MutableComponentVariant(org.gradle.internal.component.external.model.MutableComponentVariant)

Example 8 with Capability

use of org.gradle.api.capabilities.Capability in project gradle by gradle.

the class ComponentState method formatCapabilityRejectMessage.

private String formatCapabilityRejectMessage(ModuleIdentifier id, Pair<Capability, Collection<NodeState>> capabilityConflict) {
    StringBuilder sb = new StringBuilder("Module '");
    sb.append(id).append("' has been rejected:\n");
    sb.append("   Cannot select module with conflict on ");
    Capability capability = capabilityConflict.left;
    sb.append("capability '").append(capability.getGroup()).append(":").append(capability.getName()).append(":").append(capability.getVersion()).append("' also provided by ");
    sb.append(capabilityConflict.getRight());
    return sb.toString();
}
Also used : ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) Capability(org.gradle.api.capabilities.Capability)

Example 9 with Capability

use of org.gradle.api.capabilities.Capability in project gradle by gradle.

the class DefaultJavaPluginExtension method registerFeature.

public void registerFeature(String name, Action<? super FeatureSpec> configureAction) {
    Capability defaultCapability = new ProjectDerivedCapability(project, name);
    DefaultJavaFeatureSpec spec = new DefaultJavaFeatureSpec(validateFeatureName(name), defaultCapability, jvmPluginServices);
    configureAction.execute(spec);
    spec.create();
}
Also used : ProjectDerivedCapability(org.gradle.internal.component.external.model.ProjectDerivedCapability) Capability(org.gradle.api.capabilities.Capability) ProjectDerivedCapability(org.gradle.internal.component.external.model.ProjectDerivedCapability)

Example 10 with Capability

use of org.gradle.api.capabilities.Capability in project gradle by gradle.

the class DefaultIvyPublication method populateDependencies.

private void populateDependencies(Set<? extends UsageContext> usageContexts, PublicationWarningsCollector publicationWarningsCollector) {
    for (UsageContext usageContext : usageContexts) {
        publicationWarningsCollector.newContext(usageContext.getName());
        for (ModuleDependency dependency : usageContext.getDependencies()) {
            String confMapping = confMappingFor(usageContext, dependency);
            if (!dependency.getAttributes().isEmpty()) {
                publicationWarningsCollector.addUnsupported(String.format("%s:%s:%s declared with Gradle attributes", dependency.getGroup(), dependency.getName(), dependency.getVersion()));
            }
            if (dependency instanceof ProjectDependency) {
                addProjectDependency((ProjectDependency) dependency, confMapping);
            } else {
                ExternalDependency externalDependency = (ExternalDependency) dependency;
                if (platformSupport.isTargetingPlatform(dependency)) {
                    publicationWarningsCollector.addUnsupported(String.format("%s:%s:%s declared as platform", dependency.getGroup(), dependency.getName(), dependency.getVersion()));
                }
                if (!versionMappingInUse && externalDependency.getVersion() == null) {
                    publicationWarningsCollector.addUnsupported(String.format("%s:%s declared without version", externalDependency.getGroup(), externalDependency.getName()));
                }
                addExternalDependency(externalDependency, confMapping, ((AttributeContainerInternal) usageContext.getAttributes()).asImmutable());
            }
        }
        if (!usageContext.getDependencyConstraints().isEmpty()) {
            for (DependencyConstraint constraint : usageContext.getDependencyConstraints()) {
                publicationWarningsCollector.addUnsupported(String.format("%s:%s:%s declared as a dependency constraint", constraint.getGroup(), constraint.getName(), constraint.getVersion()));
            }
        }
        if (!usageContext.getCapabilities().isEmpty()) {
            for (Capability capability : usageContext.getCapabilities()) {
                publicationWarningsCollector.addVariantUnsupported(String.format("Declares capability %s:%s:%s which cannot be mapped to Ivy", capability.getGroup(), capability.getName(), capability.getVersion()));
            }
        }
    }
}
Also used : ExternalDependency(org.gradle.api.artifacts.ExternalDependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) Capability(org.gradle.api.capabilities.Capability) UsageContext(org.gradle.api.internal.component.UsageContext) DependencyConstraint(org.gradle.api.artifacts.DependencyConstraint) DefaultIvyProjectDependency(org.gradle.api.publish.ivy.internal.dependency.DefaultIvyProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

Aggregations

Capability (org.gradle.api.capabilities.Capability)21 ImmutableCapability (org.gradle.internal.component.external.model.ImmutableCapability)7 VersionConstraint (org.gradle.api.artifacts.VersionConstraint)3 DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)3 ShadowedCapability (org.gradle.internal.component.external.model.ShadowedCapability)3 ImmutableList (com.google.common.collect.ImmutableList)2 DependencyConstraint (org.gradle.api.artifacts.DependencyConstraint)2 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)2 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)2 AttributeContainer (org.gradle.api.attributes.AttributeContainer)2 DefaultResolvedVariantResult (org.gradle.api.internal.artifacts.result.DefaultResolvedVariantResult)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 UsageContext (org.gradle.api.internal.component.UsageContext)2 DisplayName (org.gradle.internal.DisplayName)2 DefaultShadowedCapability (org.gradle.internal.component.external.model.DefaultShadowedCapability)2 ProjectDerivedCapability (org.gradle.internal.component.external.model.ProjectDerivedCapability)2 Nullable (javax.annotation.Nullable)1 InvalidUserCodeException (org.gradle.api.InvalidUserCodeException)1 Configuration (org.gradle.api.artifacts.Configuration)1 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)1