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;
}
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));
}
}
}
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();
}
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();
}
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()));
}
}
}
}
Aggregations