Search in sources :

Example 1 with RejectedByRuleVersion

use of org.gradle.internal.resolve.RejectedByRuleVersion 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();
}
Also used : RejectedByRuleVersion(org.gradle.internal.resolve.RejectedByRuleVersion) SpecRuleAction(org.gradle.internal.rules.SpecRuleAction) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) RejectedByAttributesVersion(org.gradle.internal.resolve.RejectedByAttributesVersion) ComponentSelection(org.gradle.api.artifacts.ComponentSelection) DefaultComponentSelection(org.gradle.api.internal.artifacts.DefaultComponentSelection)

Example 2 with RejectedByRuleVersion

use of org.gradle.internal.resolve.RejectedByRuleVersion in project gradle by gradle.

the class DefaultVersionedComponentChooser method isRejectedByRule.

@Nullable
private RejectedByRuleVersion isRejectedByRule(ModuleComponentIdentifier candidateIdentifier, Collection<SpecRuleAction<? super ComponentSelection>> rules, MetadataProvider metadataProvider) {
    ComponentSelectionInternal selection = new DefaultComponentSelection(candidateIdentifier, metadataProvider);
    rulesProcessor.apply(selection, rules, metadataProvider);
    if (selection.isRejected()) {
        return new RejectedByRuleVersion(candidateIdentifier, selection.getRejectionReason());
    }
    return null;
}
Also used : RejectedByRuleVersion(org.gradle.internal.resolve.RejectedByRuleVersion) DefaultComponentSelection(org.gradle.api.internal.artifacts.DefaultComponentSelection) ComponentSelectionInternal(org.gradle.api.internal.artifacts.ComponentSelectionInternal) Nullable(javax.annotation.Nullable)

Example 3 with RejectedByRuleVersion

use of org.gradle.internal.resolve.RejectedByRuleVersion 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);
    }
}
Also used : RejectedVersion(org.gradle.internal.resolve.RejectedVersion) RejectedByRuleVersion(org.gradle.internal.resolve.RejectedByRuleVersion) DefaultBuildableComponentIdResolveResult(org.gradle.internal.resolve.result.DefaultBuildableComponentIdResolveResult) BuildableComponentIdResolveResult(org.gradle.internal.resolve.result.BuildableComponentIdResolveResult) ComponentIdResolveResult(org.gradle.internal.resolve.result.ComponentIdResolveResult) RejectedByAttributesVersion(org.gradle.internal.resolve.RejectedByAttributesVersion) ComponentSelectionDescriptorInternal(org.gradle.api.internal.artifacts.ivyservice.resolveengine.result.ComponentSelectionDescriptorInternal) RejectedBySelectorVersion(org.gradle.internal.resolve.RejectedBySelectorVersion)

Aggregations

RejectedByRuleVersion (org.gradle.internal.resolve.RejectedByRuleVersion)3 DefaultComponentSelection (org.gradle.api.internal.artifacts.DefaultComponentSelection)2 RejectedByAttributesVersion (org.gradle.internal.resolve.RejectedByAttributesVersion)2 Nullable (javax.annotation.Nullable)1 ComponentSelection (org.gradle.api.artifacts.ComponentSelection)1 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)1 ComponentSelectionInternal (org.gradle.api.internal.artifacts.ComponentSelectionInternal)1 ComponentSelectionDescriptorInternal (org.gradle.api.internal.artifacts.ivyservice.resolveengine.result.ComponentSelectionDescriptorInternal)1 RejectedBySelectorVersion (org.gradle.internal.resolve.RejectedBySelectorVersion)1 RejectedVersion (org.gradle.internal.resolve.RejectedVersion)1 BuildableComponentIdResolveResult (org.gradle.internal.resolve.result.BuildableComponentIdResolveResult)1 ComponentIdResolveResult (org.gradle.internal.resolve.result.ComponentIdResolveResult)1 DefaultBuildableComponentIdResolveResult (org.gradle.internal.resolve.result.DefaultBuildableComponentIdResolveResult)1 SpecRuleAction (org.gradle.internal.rules.SpecRuleAction)1