use of org.gradle.internal.resolve.RejectedByAttributesVersion in project gradle by gradle.
the class DefaultVersionedComponentChooser method selectNewestMatchingComponent.
@Override
public void selectNewestMatchingComponent(Collection<? extends ModuleComponentResolveState> versions, ComponentSelectionContext result, VersionSelector requestedVersionMatcher, VersionSelector rejectedVersionSelector, ImmutableAttributes consumerAttributes) {
Collection<SpecRuleAction<? super ComponentSelection>> rules = componentSelectionRules.getRules();
// Loop over all listed versions, sorted by LATEST first
List<ModuleComponentResolveState> resolveStates = sortLatestFirst(versions);
Action<? super ArtifactResolutionDetails> contentFilter = result.getContentFilter();
for (ModuleComponentResolveState candidate : resolveStates) {
if (contentFilter != null) {
DynamicArtifactResolutionDetails details = new DynamicArtifactResolutionDetails(candidate, result.getConfigurationName(), result.getConsumerAttributes());
contentFilter.execute(details);
if (!details.found) {
continue;
}
}
DefaultMetadataProvider metadataProvider = createMetadataProvider(candidate);
boolean versionMatches = versionMatches(requestedVersionMatcher, candidate, metadataProvider);
if (metadataIsNotUsable(result, metadataProvider)) {
return;
}
ModuleComponentIdentifier candidateId = candidate.getId();
if (!versionMatches) {
result.notMatched(candidateId, requestedVersionMatcher);
continue;
}
RejectedByAttributesVersion maybeRejectByAttributes = tryRejectByAttributes(candidateId, metadataProvider, consumerAttributes);
if (maybeRejectByAttributes != null) {
result.doesNotMatchConsumerAttributes(maybeRejectByAttributes);
} else if (isRejectedBySelector(candidateId, rejectedVersionSelector)) {
// Mark this version as rejected
result.rejectedBySelector(candidateId, rejectedVersionSelector);
} else {
RejectedByRuleVersion rejectedByRules = isRejectedByRule(candidateId, rules, metadataProvider);
if (rejectedByRules != null) {
// Mark this version as rejected
result.rejectedByRule(rejectedByRules);
if (requestedVersionMatcher.matchesUniqueVersion()) {
// Only consider one candidate, because matchesUniqueVersion means that there's no ambiguity on the version number
break;
}
} else {
result.matches(candidateId);
return;
}
}
}
// if we reach this point, no match was found, either because there are no versions matching the selector
// or all of them were rejected
result.noMatchFound();
}
use of org.gradle.internal.resolve.RejectedByAttributesVersion in project gradle by gradle.
the class DefaultVersionedComponentChooser method tryRejectByAttributes.
@Nullable
private RejectedByAttributesVersion tryRejectByAttributes(ModuleComponentIdentifier id, MetadataProvider provider, ImmutableAttributes consumerAttributes) {
if (consumerAttributes.isEmpty()) {
return null;
}
// At this point, we need the component metadata, because it may declare attributes that are needed for matching
// Component metadata may not necessarily hit the network if there is a custom component metadata supplier
ComponentMetadata componentMetadata = provider.getComponentMetadata();
if (componentMetadata != null) {
AttributeContainerInternal attributes = (AttributeContainerInternal) componentMetadata.getAttributes();
boolean matching = attributesSchema.matcher().isMatching(attributes, consumerAttributes);
if (!matching) {
return new RejectedByAttributesVersion(id, attributesSchema.matcher().describeMatching(attributes, consumerAttributes));
}
}
return null;
}
use of org.gradle.internal.resolve.RejectedByAttributesVersion in project gradle by gradle.
the class SelectorState method addReasonsForSelector.
/**
* Append selection descriptors to the supplied "reason", enhancing with any 'unmatched' or 'rejected' reasons.
*/
public void addReasonsForSelector(ComponentSelectionReasonInternal selectionReason) {
ComponentIdResolveResult result = preferResult == null ? requireResult : preferResult;
Collection<String> rejectedBySelector = null;
if (result != null) {
for (RejectedVersion rejectedVersion : result.getRejectedVersions()) {
String version = rejectedVersion.getId().getVersion();
if (rejectedVersion instanceof RejectedBySelectorVersion) {
if (rejectedBySelector == null) {
rejectedBySelector = Lists.newArrayList();
}
rejectedBySelector.add(version);
} else if (rejectedVersion instanceof RejectedByRuleVersion) {
String reason = ((RejectedByRuleVersion) rejectedVersion).getReason();
selectionReason.addCause(ComponentSelectionReasons.REJECTION.withDescription(new RejectedByRuleReason(version, reason)));
} else if (rejectedVersion instanceof RejectedByAttributesVersion) {
selectionReason.addCause(ComponentSelectionReasons.REJECTION.withDescription(new RejectedByAttributesReason((RejectedByAttributesVersion) rejectedVersion)));
}
}
}
for (ComponentSelectionDescriptorInternal descriptor : dependencyReasons) {
if (descriptor.getCause() == ComponentSelectionCause.REQUESTED || descriptor.getCause() == ComponentSelectionCause.CONSTRAINT) {
if (rejectedBySelector != null) {
descriptor = descriptor.withDescription(new RejectedBySelectorReason(rejectedBySelector, descriptor));
} else if (result != null && !result.getUnmatchedVersions().isEmpty()) {
descriptor = descriptor.withDescription(new UnmatchedVersionsReason(result.getUnmatchedVersions(), descriptor));
}
}
selectionReason.addCause(descriptor);
}
}
Aggregations