Search in sources :

Example 1 with SpecRuleAction

use of org.gradle.internal.rules.SpecRuleAction 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)

Example 2 with SpecRuleAction

use of org.gradle.internal.rules.SpecRuleAction 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 3 with SpecRuleAction

use of org.gradle.internal.rules.SpecRuleAction in project gradle by gradle.

the class DefaultComponentMetadataHandler method createSpecRuleActionForModule.

private SpecRuleAction<? super ComponentMetadataDetails> createSpecRuleActionForModule(Object id, RuleAction<? super ComponentMetadataDetails> ruleAction) {
    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<ComponentMetadataDetails> spec = new ComponentMetadataDetailsMatchingSpec(moduleIdentifier);
    return new SpecRuleAction<ComponentMetadataDetails>(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) ComponentMetadataDetails(org.gradle.api.artifacts.ComponentMetadataDetails)

Example 4 with SpecRuleAction

use of org.gradle.internal.rules.SpecRuleAction in project gradle by gradle.

the class DefaultVersionedComponentChooser method selectNewestMatchingComponent.

public void selectNewestMatchingComponent(Collection<? extends ModuleComponentResolveState> versions, ComponentSelectionContext result, VersionSelector requestedVersionMatcher, VersionSelector rejectedVersionSelector) {
    Collection<SpecRuleAction<? super ComponentSelection>> rules = componentSelectionRules.getRules();
    // Loop over all listed versions, sorted by LATEST first
    for (ModuleComponentResolveState candidate : sortLatestFirst(versions)) {
        MetadataProvider metadataProvider = createMetadataProvider(candidate);
        boolean versionMatches = versionMatches(requestedVersionMatcher, candidate, metadataProvider);
        if (metadataIsNotUsable(result, metadataProvider)) {
            return;
        }
        String version = candidate.getVersion().getSource();
        if (!versionMatches) {
            result.notMatched(version);
            continue;
        }
        if (rejectedVersionSelector != null && rejectedVersionSelector.accept(version)) {
            // Mark this version as rejected and continue
            result.rejected(version);
            continue;
        } else {
            ModuleComponentIdentifier candidateIdentifier = candidate.getId();
            if (!isRejectedByRules(candidateIdentifier, rules, metadataProvider)) {
                result.matches(candidateIdentifier);
                return;
            }
        }
        // Mark this version as rejected
        result.rejected(version);
        if (requestedVersionMatcher.matchesUniqueVersion()) {
            // Only consider one candidate, because matchesUniqueVersion means that there's no ambiguity on the version number
            break;
        }
    }
    // 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 : 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)

Aggregations

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