Search in sources :

Example 1 with ResolvedVersionConstraint

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;
}
Also used : ResolvedVersionConstraint(org.gradle.api.internal.artifacts.ResolvedVersionConstraint) VersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)

Example 2 with ResolvedVersionConstraint

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);
}
Also used : ResolvedVersionConstraint(org.gradle.api.internal.artifacts.ResolvedVersionConstraint) VersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)

Example 3 with ResolvedVersionConstraint

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();
}
Also used : CompositeVersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.CompositeVersionSelector) CompositeVersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.CompositeVersionSelector) VersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector) ResolvedVersionConstraint(org.gradle.api.internal.artifacts.ResolvedVersionConstraint)

Example 4 with ResolvedVersionConstraint

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);
        }
    }
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultResolvedVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultResolvedVersionConstraint) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) ResolvedVersionConstraint(org.gradle.api.internal.artifacts.ResolvedVersionConstraint) ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultResolvedVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultResolvedVersionConstraint) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier) VersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)

Aggregations

ResolvedVersionConstraint (org.gradle.api.internal.artifacts.ResolvedVersionConstraint)4 VersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)4 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 VersionConstraint (org.gradle.api.artifacts.VersionConstraint)1 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)1 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)1 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)1 DefaultResolvedVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultResolvedVersionConstraint)1 CompositeVersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.CompositeVersionSelector)1 DefaultModuleComponentIdentifier (org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier)1