Search in sources :

Example 11 with VersionSelector

use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector in project gradle by gradle.

the class DefaultVcsVersionWorkingDirResolver method selectVersionFromRepository.

private VersionRef selectVersionFromRepository(VersionControlRepositoryConnection repository, VersionConstraint constraint) {
    if (constraint.getBranch() != null) {
        return repository.getBranch(constraint.getBranch());
    }
    String version = constraint.getRequiredVersion();
    VersionSelector versionSelector = versionSelectorScheme.parseSelector(version);
    if (versionSelector instanceof LatestVersionSelector && ((LatestVersionSelector) versionSelector).getSelectorStatus().equals("integration")) {
        return repository.getDefaultBranch();
    }
    if (versionSelector.requiresMetadata()) {
        // TODO - implement this by moving this resolver to live alongside the external resolvers
        return null;
    }
    Set<VersionRef> versions = inMemoryCache.getVersionsForRepo(repository);
    if (versions == null) {
        versions = repository.getAvailableVersions();
        inMemoryCache.putVersionsForRepo(repository, versions);
    }
    Version bestVersion = null;
    VersionRef bestCandidate = null;
    for (VersionRef candidate : versions) {
        Version candidateVersion = versionParser.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 12 with VersionSelector

use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector in project gradle by gradle.

the class SelectorStateResolverResults method selectorAcceptsCandidate.

private static boolean selectorAcceptsCandidate(ResolvableSelectorState dep, ComponentIdResolveResult candidate, boolean candidateIsFromLock) {
    if (hasFailure(candidate)) {
        return false;
    }
    ResolvedVersionConstraint versionConstraint = dep.getVersionConstraint();
    if (versionConstraint == null) {
        return dep.getSelector().matchesStrictly(candidate.getId());
    }
    VersionSelector versionSelector = versionConstraint.getRequiredSelector();
    if (versionSelector != null && (candidateIsFromLock || versionSelector.canShortCircuitWhenVersionAlreadyPreselected())) {
        if (candidateIsFromLock && versionSelector instanceof LatestVersionSelector) {
            // Always assume a candidate from a lock will satisfy the latest version selector
            return true;
        }
        String version = candidate.getModuleVersionId().getVersion();
        if (StringUtils.isEmpty(version)) {
            return false;
        }
        return versionSelector.accept(version);
    }
    return false;
}
Also used : ResolvedVersionConstraint(org.gradle.api.internal.artifacts.ResolvedVersionConstraint) 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 13 with VersionSelector

use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector in project gradle by gradle.

the class TestModuleSelectorState method resolvePrefer.

@Override
public ComponentIdResolveResult resolvePrefer(VersionSelector allRejects) {
    VersionSelector preferredSelector = resolvedVersionConstraint.getPreferredSelector();
    if (preferredSelector == null) {
        return null;
    }
    preferResult = doResolve(preferredSelector, allRejects, preferResult);
    return preferResult;
}
Also used : 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