Skip to content

Commit

Permalink
Kill VersionComparator
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX committed Feb 21, 2020
1 parent b21206c commit caa6aa2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ import static org.gradle.api.specs.Specs.SATISFIES_ALL
class Resolver {
final Project project
final Action<? super ResolutionStrategyWithCurrent> resolutionStrategy
final boolean useSelectionRules
final boolean collectProjectUrls
final boolean checkConstraints
final ConcurrentMap<ModuleVersionIdentifier, ProjectUrl> projectUrls

Expand All @@ -69,11 +67,6 @@ class Resolver {
this.project = project
this.checkConstraints = checkConstraints

useSelectionRules = new VersionComparator(project)
.compare(project.gradle.gradleVersion, '2.2') >= 0
collectProjectUrls = new VersionComparator(project)
.compare(project.gradle.gradleVersion, '2.0') >= 0

logRepositories()
}

Expand Down Expand Up @@ -140,23 +133,19 @@ class Resolver {
copy.dependencies.clear()
copy.dependencies.addAll(latest)

if (useSelectionRules) {
addRevisionFilter(copy, revision)
addCustomResolutionStrategy(copy, currentCoordinates)
}
return copy
}

/** Returns a variant of the provided dependency used for querying the latest version. */
@TypeChecked(SKIP)
private Dependency createQueryDependency(Dependency dependency, String revision) {
String versionQuery = useSelectionRules ? '+' : "latest.${revision}"

// If no version was specified then it may be intended to be resolved by another plugin
// (e.g. the dependency-management-plugin for BOMs) or is an explicit file (e.g. libs/*.jar).
// In the case of another plugin we use '+' in the hope that the plugin will not restrict the
// query (see issue #97). Otherwise if its a file then use 'none' to pass it through.
String version = (dependency.version == null) ? (dependency.artifacts.empty ? '+' : 'none') : versionQuery
String version = (dependency.version == null) ? (dependency.artifacts.empty ? '+' : 'none') : '+'

return project.dependencies.create("${dependency.group}:${dependency.name}:${version}") {
transitive = false
Expand All @@ -166,10 +155,8 @@ class Resolver {
/** Returns a variant of the provided dependency used for querying the latest version. */
@TypeChecked(SKIP)
private Dependency createQueryDependency(DependencyConstraint dependency, String revision) {
String versionQuery = useSelectionRules ? '+' : "latest.${revision}"

// If no version was specified then use 'none' to pass it through.
String version = dependency.version == null ? 'none' : versionQuery
String version = dependency.version == null ? 'none' : '+'

return project.dependencies.create("${dependency.group}:${dependency.name}:${version}") {
transitive = false
Expand Down Expand Up @@ -288,7 +275,7 @@ class Resolver {
}

private String getProjectUrl(ModuleVersionIdentifier id) {
if (!collectProjectUrls || project.getGradle().startParameter.isOffline()) {
if (project.getGradle().startParameter.isOffline()) {
return null
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package com.github.benmanes.gradle.versions.updates

import groovy.transform.CompileStatic
import org.gradle.api.Project
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.DefaultVersionComparator
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionParser

/**
* A mapping of which versions are out of date, up to date, or exceed the latest found.
Expand All @@ -31,12 +33,12 @@ class VersionMapping {
final SortedSet<Coordinate> current = new TreeSet<>()
final SortedSet<Coordinate> latest = new TreeSet<>()

final VersionComparator comparator
final Comparator<String> comparator
final Project project

VersionMapping(Project project, Set<DependencyStatus> statuses) {
this.project = project
this.comparator = new VersionComparator(project)
this.comparator = makeVersionComparator()
statuses.each { status ->
current.add(status.coordinate)
if (status.unresolved == null) {
Expand Down Expand Up @@ -73,4 +75,16 @@ class VersionMapping {
}
}
}

private Comparator<String> makeVersionComparator() {
def baseComparator = new DefaultVersionComparator().asVersionComparator()
def versionParser = new VersionParser()
return new Comparator<String>() {
int compare(String string1, String string2) {
return baseComparator.compare(
versionParser.transform(string1),
versionParser.transform(string2))
}
}
}
}

0 comments on commit caa6aa2

Please sign in to comment.