use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector 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.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector in project gradle by gradle.
the class DependencyGraphBuilder method allSelectorsAgreeWith.
/**
* Check if all of the supplied selectors agree with the version chosen
*/
private static boolean allSelectorsAgreeWith(Collection<SelectorState> allSelectors, String version, Predicate<SelectorState> filter) {
boolean atLeastOneAgrees = false;
for (SelectorState selectorState : allSelectors) {
if (filter.apply(selectorState)) {
ResolvedVersionConstraint versionConstraint = selectorState.getVersionConstraint();
if (versionConstraint != null) {
VersionSelector candidateSelector = versionConstraint.getPreferredSelector();
if (candidateSelector == null || !candidateSelector.canShortCircuitWhenVersionAlreadyPreselected() || !candidateSelector.accept(version)) {
return false;
}
candidateSelector = versionConstraint.getRejectedSelector();
if (candidateSelector != null && candidateSelector.accept(version)) {
return false;
}
atLeastOneAgrees = true;
}
}
}
return atLeastOneAgrees;
}
use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector in project gradle by gradle.
the class DependencyGraphBuilder method selectorAgreesWith.
private static boolean selectorAgreesWith(SelectorState selectorState, String version) {
ResolvedVersionConstraint versionConstraint = selectorState.getVersionConstraint();
if (versionConstraint == null || versionConstraint.getPreferredSelector() == null) {
return false;
}
VersionSelector candidateSelector = versionConstraint.getPreferredSelector();
return !candidateSelector.requiresMetadata() && candidateSelector.canShortCircuitWhenVersionAlreadyPreselected() && candidateSelector.accept(version);
}
use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector in project gradle by gradle.
the class VcsDependencyResolver method selectVersionFromRepository.
private VersionRef selectVersionFromRepository(VersionControlSpec spec, VersionControlSystem versionControlSystem, VersionConstraint constraint) {
if (constraint.getBranch() != null) {
return versionControlSystem.getBranch(spec, constraint.getBranch());
}
String version = constraint.getPreferredVersion();
VersionSelector versionSelector = versionSelectorScheme.parseSelector(version);
if (versionSelector instanceof LatestVersionSelector && ((LatestVersionSelector) versionSelector).getSelectorStatus().equals("integration")) {
return versionControlSystem.getDefaultBranch(spec);
}
if (versionSelector.requiresMetadata()) {
// TODO - implement this by moving this resolver to live alongside the external resolvers
return null;
}
Set<VersionRef> versions = versionControlSystem.getAvailableVersions(spec);
Version bestVersion = null;
VersionRef bestCandidate = null;
for (VersionRef candidate : versions) {
Version candidateVersion = VersionParser.INSTANCE.transform(candidate.getVersion());
if (versionSelector.accept(candidateVersion)) {
if (bestCandidate == null || versionComparator.asVersionComparator().compare(candidateVersion, bestVersion) > 0) {
bestVersion = candidateVersion;
bestCandidate = candidate;
}
}
}
return bestCandidate;
}
use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector in project gradle by gradle.
the class GradlePomModuleDescriptorParser method parsePomForSelector.
private PomReader parsePomForSelector(DescriptorParseContext parseContext, ModuleComponentSelector selector, Map<String, String> childProperties) throws IOException, SAXException {
ModuleDependencyMetadata moduleDependencyMetadata = toDependencyMetadata(selector);
VersionSelector acceptor = mavenVersionSelectorScheme.parseSelector(selector.getVersion());
LocallyAvailableExternalResource localResource = parseContext.getMetaDataArtifact(moduleDependencyMetadata, acceptor, ArtifactType.MAVEN_POM);
return parsePomResource(parseContext, localResource, childProperties);
}
Aggregations