use of org.gradle.api.internal.artifacts.ResolvedVersionConstraint 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.ResolvedVersionConstraint 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.ResolvedVersionConstraint 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.ResolvedVersionConstraint 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