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

Fix snapshot resolution.

This commit is contained in:
Cedric Beust 2015-12-18 21:54:52 +04:00
parent 8acd8b8fce
commit 80434ca7b6
4 changed files with 60 additions and 22 deletions

View file

@ -28,7 +28,7 @@ public class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
}
data class RepoResult(val hostConfig: HostConfig, val found: Boolean, val version: Version? = null,
val hasJar: Boolean = true, val snapshotVersion: Version? = null)
val hasJar: Boolean = true, val snapshotVersion: Version? = null)
private val FOUND_REPOS: LoadingCache<String, RepoResult> = CacheBuilder.newBuilder()
.build(object : CacheLoader<String, RepoResult>() {
@ -98,10 +98,15 @@ public class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
if (version.isSnapshot()) {
val dep = SimpleDep(mavenId)
val isLocal = repoUrl.startsWith(FileDependency.PREFIX_FILE)
val snapshotVersion = if (isLocal) version
else findSnapshotVersion(dep.toMetadataXmlPath(false, isLocal, version.version), repoUrl)
val metadataXmlPath = dep.toMetadataXmlPath(false, isLocal, version.version)
val snapshotVersion =
if (isLocal) version
else findSnapshotVersion(metadataXmlPath, repoUrl, mavenId.version)
if (snapshotVersion != null) {
return RepoResult(repo, true, version, true /* hasJar, potential bug here */,
val url = repoUrl + metadataXmlPath
val kurl = Kurl(HostConfig(url))
val found = kurl.exists
return RepoResult(repo, found, version, true /* hasJar, potential bug here */,
snapshotVersion)
} else {
return RepoResult(repo, false)
@ -184,7 +189,7 @@ public class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
return null
}
fun findSnapshotVersion(metadataPath: String, repoUrl: String): Version? {
fun findSnapshotVersion(metadataPath: String, repoUrl: String, snapshotVersion: String): Version? {
val timestamp = XPATH.compile("/metadata/versioning/snapshot/timestamp")
val buildNumber = XPATH.compile("/metadata/versioning/snapshot/buildNumber")
// No version in this dependency, find out the most recent one by parsing maven-metadata.xml, if it exists
@ -194,7 +199,7 @@ public class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
val ts = timestamp.evaluate(doc, XPathConstants.STRING)
val bn = buildNumber.evaluate(doc, XPathConstants.STRING)
if (! Strings.isEmpty(ts.toString()) && ! Strings.isEmpty(bn.toString())) {
return Version.of(ts.toString() + "-" + bn.toString())
return Version(snapshotVersion, ts.toString() + "-" + bn.toString())
} else {
val lastUpdated = XPATH.compile("/metadata/versioning/lastUpdated")
if (! lastUpdated.toString().isEmpty()) {

View file

@ -1,6 +1,6 @@
package com.beust.kobalt.maven
import com.beust.kobalt.misc.Strings
import com.beust.kobalt.misc.Version
open class SimpleDep(open val mavenId: MavenId) : UnversionedDep(mavenId.groupId, mavenId.artifactId) {
companion object {
@ -11,23 +11,29 @@ open class SimpleDep(open val mavenId: MavenId) : UnversionedDep(mavenId.groupId
val version: String get() = mavenId.version!!
private fun toFile(v: String, snapshotVersion: String?, suffix: String) : String {
val fv = if (v.contains("SNAPSHOT")) v.replace("SNAPSHOT", "") else v
val result = Strings.join("/", arrayListOf(toDirectory(v, false) +
artifactId + "-" + fv + (snapshotVersion ?: "") + suffix))
return result
private fun toFile(version: Version, suffix: String): String {
val list =
if (version.snapshotTimestamp != null) {
listOf(toDirectory(version.version, false),
artifactId + "-" + version.noSnapshotVersion + "-" + version.snapshotTimestamp + suffix)
} else {
listOf(toDirectory(version.version, false), artifactId + "-" + version.version + suffix)
}
return list.joinToString("/")
}
fun toPomFile(v: String) = toFile(v, "", ".pom")
fun toPomFile(v: String) = toFile(Version.of(v), ".pom")
fun toPomFile(r: RepoFinder.RepoResult) = toFile(r.version!!.version, r.snapshotVersion?.version, ".pom")
fun toPomFile(r: RepoFinder.RepoResult) = toFile(r.snapshotVersion ?: r.version!!, ".pom")
fun toJarFile(v: String = version) = toFile(v, "", suffix)
fun toJarFile(v: String = version) = toFile(Version.of(v), suffix)
fun toJarFile(r: RepoFinder.RepoResult) = toFile(r.version!!.version, r.snapshotVersion?.version, suffix)
fun toJarFile(v: Version) = toFile(v, suffix)
fun toPomFileName() = "$artifactId-$version.pom"
fun toJarFile(r: RepoFinder.RepoResult) = toFile(r.snapshotVersion ?: r.version!!, suffix)
val suffix : String
get() {
val packaging = mavenId.packaging

View file

@ -3,10 +3,7 @@ package com.beust.kobalt.misc
import com.beust.kobalt.maven.MavenId
import com.google.common.base.CharMatcher
import java.math.BigInteger
import java.util.Arrays
import java.util.Comparator
import java.util.Locale
import java.util.TreeMap
import java.util.*
public class Versions {
companion object {
@ -39,7 +36,7 @@ public class Versions {
}
}
class Version(val version: String): Comparable<Version> {
class Version(val version: String, val snapshotTimestamp: String? = null): Comparable<Version> {
companion object {
private val comparator = VersionComparator()
@ -48,6 +45,9 @@ class Version(val version: String): Comparable<Version> {
}
}
val noSnapshotVersion: String
get() = version.replace("-SNAPSHOT", "")
internal val items: List<Item>
private var hash: Int = -1