Search in sources :

Example 1 with LatestVersionSelector

use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.LatestVersionSelector 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 2 with LatestVersionSelector

use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.LatestVersionSelector 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 3 with LatestVersionSelector

use of org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.LatestVersionSelector 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)

Aggregations

LatestVersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.LatestVersionSelector)3 VersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)3 Version (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version)2 VersionRef (org.gradle.vcs.internal.VersionRef)2 ResolvedVersionConstraint (org.gradle.api.internal.artifacts.ResolvedVersionConstraint)1