Search in sources :

Example 6 with VersionSelector

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

Example 7 with VersionSelector

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);
}
Also used : ModuleDependencyMetadata(org.gradle.internal.component.external.model.ModuleDependencyMetadata) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource) VersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)

Example 8 with VersionSelector

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

Example 9 with VersionSelector

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();
}
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 10 with VersionSelector

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

VersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)13 ResolvedVersionConstraint (org.gradle.api.internal.artifacts.ResolvedVersionConstraint)5 LatestVersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.LatestVersionSelector)3 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)2 Version (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version)2 VersionRef (org.gradle.vcs.internal.VersionRef)2 ComponentSelection (org.gradle.api.artifacts.ComponentSelection)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)1 VersionConstraint (org.gradle.api.artifacts.VersionConstraint)1 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)1 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)1 DefaultComponentSelection (org.gradle.api.internal.artifacts.DefaultComponentSelection)1 DefaultResolvedVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultResolvedVersionConstraint)1 CompositeVersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.CompositeVersionSelector)1 DefaultVersionComparator (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.DefaultVersionComparator)1 DefaultVersionSelectorScheme (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.DefaultVersionSelectorScheme)1 UnionVersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.UnionVersionSelector)1 DefaultModuleComponentIdentifier (org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier)1 ModuleDependencyMetadata (org.gradle.internal.component.external.model.ModuleDependencyMetadata)1