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