From fd5f77d9223c7c80b613b48931a020e2646a0348 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 26 Mar 2017 12:44:45 -0700 Subject: [PATCH] CheckVersions fix attempt. --- .../com/beust/kobalt/ResolveDependency.kt | 2 +- .../maven/aether/KobaltMavenResolver.kt | 2 +- .../com/beust/kobalt/misc/CheckVersions.kt | 25 ++++++------------- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt index 7c848461..a14f993c 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt @@ -34,7 +34,7 @@ class ResolveDependency @Inject constructor( private fun latestMavenArtifact(group: String, artifactId: String, extension: String = "jar"): DependencyNode { val artifact = DefaultArtifact(group, artifactId, extension, "(0,]") - val resolved = aether.resolveVersion(artifact) + val resolved = aether.resolveRange(artifact) if (resolved != null) { val newArtifact = DefaultArtifact(artifact.groupId, artifact.artifactId, artifact.extension, resolved.highestVersion.toString()) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt index 0320d456..4e8cfae2 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt @@ -74,7 +74,7 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, directDependencies(id, scope) } - fun resolveVersion(artifact: Artifact): VersionRangeResult? { + fun resolveRange(artifact: Artifact): VersionRangeResult? { val request = VersionRangeRequest(artifact, kobaltRepositories, null) val result = system.resolveVersionRange(session, request) return result diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt index 657bc6f7..d15e8056 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt @@ -6,7 +6,6 @@ import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.MavenId import com.beust.kobalt.maven.aether.AetherDependency import com.beust.kobalt.maven.aether.KobaltMavenResolver -import java.util.* import javax.inject.Inject /** @@ -27,24 +26,14 @@ class CheckVersions @Inject constructor(val depManager: DependencyManager, try { val latestDep = depManager.create(dep.shortId, false, project.directory) val artifact = (latestDep as AetherDependency).artifact - val versions = resolver.resolveVersion(artifact) - val releases = versions?.versions?.filter { !it.toString().contains("SNAP")} - val highestRelease = - if (releases != null) { - val strings = releases.map { it.toString() } - val c = strings.contains("1.0.8") - val sv = releases.map { StringVersion(it.toString()) } - Collections.sort(sv, Collections.reverseOrder()) - if (sv.any()) sv[0] else null - } else { - null + val rangeResult = resolver.resolveRange(artifact) + + if (rangeResult != null) { + val highest = rangeResult.highestVersion?.toString() + if (highest != null && highest != dep.id + && StringVersion(highest) > StringVersion(dep.version)) { + newVersions.add(artifact.groupId + ":" + artifact.artifactId + ":" + highest) } - - val highest = highestRelease ?: versions?.highestVersion.toString() - - if (highest != dep.id - && StringVersion(highest.toString()) > StringVersion(dep.version)) { - newVersions.add(artifact.groupId + ":" + artifact.artifactId + ":" + highest) } } catch(e: KobaltException) { kobaltLog(1, " Cannot resolve ${dep.shortId}. ignoring")