1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

CheckVersions fix attempt.

This commit is contained in:
Cedric Beust 2017-03-26 12:44:45 -07:00
parent f7673cba46
commit fd5f77d922
3 changed files with 9 additions and 20 deletions

View file

@ -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())

View file

@ -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

View file

@ -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")