Search in sources :

Example 1 with ComponentSelection

use of org.gradle.api.artifacts.ComponentSelection in project gradle by gradle.

the class DefaultVersionedComponentChooser method selectNewestMatchingComponent.

public void selectNewestMatchingComponent(Collection<? extends ModuleComponentResolveState> versions, BuildableComponentSelectionResult result, ModuleVersionSelector requested) {
    VersionSelector requestedVersion = versionSelectorScheme.parseSelector(requested.getVersion());
    Collection<SpecRuleAction<? super ComponentSelection>> rules = componentSelectionRules.getRules();
    for (ModuleComponentResolveState candidate : sortLatestFirst(versions)) {
        MetadataProvider metadataProvider = createMetadataProvider(candidate);
        boolean versionMatches = versionMatches(requestedVersion, candidate, metadataProvider);
        if (!metadataProvider.isUsable()) {
            applyTo(metadataProvider, result);
            return;
        }
        if (!versionMatches) {
            result.notMatched(candidate.getVersion());
            continue;
        }
        ModuleComponentIdentifier candidateIdentifier = candidate.getId();
        boolean accepted = !isRejectedByRules(candidateIdentifier, rules, metadataProvider);
        if (!metadataProvider.isUsable()) {
            applyTo(metadataProvider, result);
            return;
        }
        if (accepted) {
            result.matches(candidateIdentifier);
            return;
        }
        result.rejected(candidate.getVersion());
        if (requestedVersion.matchesUniqueVersion()) {
            // Only consider one candidate
            break;
        }
    }
    result.noMatchFound();
}
Also used : SpecRuleAction(org.gradle.internal.rules.SpecRuleAction) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ComponentSelection(org.gradle.api.artifacts.ComponentSelection) DefaultComponentSelection(org.gradle.api.internal.artifacts.DefaultComponentSelection) VersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector) ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector)

Example 2 with ComponentSelection

use of org.gradle.api.artifacts.ComponentSelection in project gradle by gradle.

the class DefaultComponentSelectionRules method createSpecRuleActionFromId.

private SpecRuleAction<? super ComponentSelection> createSpecRuleActionFromId(Object id, RuleAction<? super ComponentSelection> ruleAction) {
    final ModuleIdentifier moduleIdentifier;
    try {
        moduleIdentifier = moduleIdentifierNotationParser.parseNotation(id);
    } catch (UnsupportedNotationException e) {
        throw new InvalidUserCodeException(String.format(INVALID_SPEC_ERROR, id == null ? "null" : id.toString()), e);
    }
    Spec<ComponentSelection> spec = new ComponentSelectionMatchingSpec(moduleIdentifier);
    return new SpecRuleAction<ComponentSelection>(ruleAction, spec);
}
Also used : InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) SpecRuleAction(org.gradle.internal.rules.SpecRuleAction) UnsupportedNotationException(org.gradle.internal.typeconversion.UnsupportedNotationException) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) ComponentSelection(org.gradle.api.artifacts.ComponentSelection)

Aggregations

ComponentSelection (org.gradle.api.artifacts.ComponentSelection)2 SpecRuleAction (org.gradle.internal.rules.SpecRuleAction)2 InvalidUserCodeException (org.gradle.api.InvalidUserCodeException)1 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)1 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)1 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)1 DefaultComponentSelection (org.gradle.api.internal.artifacts.DefaultComponentSelection)1 VersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)1 UnsupportedNotationException (org.gradle.internal.typeconversion.UnsupportedNotationException)1