use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector in project gradle by gradle.
the class SelectorStateResolver method selectBest.
public T selectBest(ModuleIdentifier moduleId, ModuleSelectors<? extends ResolvableSelectorState> selectors) {
VersionSelector allRejects = createAllRejects(selectors);
List<T> candidates = resolveSelectors(selectors, allRejects);
assert !candidates.isEmpty();
// If the module matches, add the root component into the mix
if (moduleId.equals(rootModuleId) && !candidates.contains(rootComponent)) {
candidates = new ArrayList<>(candidates);
candidates.add(rootComponent);
}
// If we have a single common resolution, no conflicts to resolve
if (candidates.size() == 1) {
return candidates.get(0);
}
if (resolveOptimizations.mayHaveForcedPlatforms()) {
List<T> allowed = candidates.stream().filter(SelectorStateResolverResults::isVersionAllowedByPlatform).collect(Collectors.toList());
if (!allowed.isEmpty()) {
if (allowed.size() == 1) {
return allowed.get(0);
}
candidates = allowed;
}
}
// Perform conflict resolution
return resolveConflicts(candidates);
}
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);
}
use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector in project gradle by gradle.
the class DefaultMutableVersionConstraint method doStrict.
private void doStrict() {
// When strict version is used, we need to parse the preferred selector early, in order to compute its complement.
// Hopefully this shouldn't happen too often. If it happens to become a performance problem, we need to reconsider
// how we compute the "reject" clause
DefaultVersionSelectorScheme versionSelectorScheme = new DefaultVersionSelectorScheme(new DefaultVersionComparator());
VersionSelector preferredSelector = versionSelectorScheme.parseSelector(prefer);
VersionSelector rejectedSelector = versionSelectorScheme.complementForRejection(preferredSelector);
this.rejects.clear();
this.rejects.add(rejectedSelector.getSelector());
}
use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector in project gradle by gradle.
the class RejectedModuleMessageBuilder method renderVersionConstraint.
private static String renderVersionConstraint(ResolvedVersionConstraint constraint) {
if (isRejectAll(constraint)) {
return "rejects all versions";
}
VersionSelector preferredSelector = constraint.getPreferredSelector();
VersionSelector rejectedSelector = constraint.getRejectedSelector();
StringBuilder sb = new StringBuilder("prefers ");
sb.append('\'');
sb.append(preferredSelector.getSelector());
sb.append('\'');
if (rejectedSelector != null) {
sb.append(", rejects ");
if (rejectedSelector instanceof CompositeVersionSelector) {
sb.append("any of \"");
int i = 0;
for (VersionSelector selector : ((CompositeVersionSelector) rejectedSelector).getSelectors()) {
if (i++ > 0) {
sb.append(", ");
}
sb.append('\'');
sb.append(selector.getSelector());
sb.append('\'');
}
sb.append("\"");
} else {
sb.append('\'');
sb.append(rejectedSelector.getSelector());
sb.append('\'');
}
}
return sb.toString();
}
use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector in project gradle by gradle.
the class RepositoryChainDependencyToComponentIdResolver method resolve.
public void resolve(DependencyMetadata dependency, ResolvedVersionConstraint resolvedVersionConstraint, BuildableComponentIdResolveResult result) {
ComponentSelector componentSelector = dependency.getSelector();
if (componentSelector instanceof ModuleComponentSelector) {
ModuleComponentSelector module = (ModuleComponentSelector) componentSelector;
if (resolvedVersionConstraint == null) {
// TODO:DAZ This shouldn't be required, but `ExternalResourceResolverDescriptorParseContext` does not provide a resolved constraint
VersionConstraint raw = module.getVersionConstraint();
resolvedVersionConstraint = new DefaultResolvedVersionConstraint(raw, versionSelectorScheme);
}
VersionSelector preferredSelector = resolvedVersionConstraint.getPreferredSelector();
if (preferredSelector.isDynamic()) {
dynamicRevisionResolver.resolve(toModuleDependencyMetadata(dependency), preferredSelector, resolvedVersionConstraint.getRejectedSelector(), result);
} else {
String version = resolvedVersionConstraint.getPreferredVersion();
ModuleComponentIdentifier id = new DefaultModuleComponentIdentifier(module.getGroup(), module.getModule(), version);
ModuleVersionIdentifier mvId = moduleIdentifierFactory.moduleWithVersion(module.getGroup(), module.getModule(), version);
result.resolved(id, mvId);
}
}
}
Aggregations