Search in sources :

Example 1 with VersionSelector

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();
}
Also used : SpecRuleAction(org.gradle.internal.rules.SpecRuleAction) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ComponentSelection(org.gradle.api.artifacts.ComponentSelection) DefaultComponentSelection(org.gradle.api.internal.artifacts.DefaultComponentSelection) VersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector) ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector)

Example 2 with VersionSelector

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

Example 3 with VersionSelector

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

Example 4 with VersionSelector

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

Example 5 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)

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