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:
parent
8acd8b8fce
commit
80434ca7b6
4 changed files with 60 additions and 22 deletions
|
@ -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()) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.HostConfig
|
||||
import com.beust.kobalt.KobaltTest
|
||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.Version
|
||||
import com.beust.kobalt.misc.warn
|
||||
import org.testng.Assert
|
||||
import org.testng.annotations.BeforeClass
|
||||
|
@ -18,7 +20,8 @@ import kotlin.properties.Delegates
|
|||
public class DownloadTest @Inject constructor(
|
||||
val depFactory: DepFactory,
|
||||
val localRepo: LocalRepo,
|
||||
val executors: KobaltExecutors) : KobaltTest() {
|
||||
val executors: KobaltExecutors,
|
||||
val repoFinder: RepoFinder) : KobaltTest() {
|
||||
var executor: ExecutorService by Delegates.notNull()
|
||||
|
||||
@BeforeClass
|
||||
|
@ -105,5 +108,29 @@ public class DownloadTest @Inject constructor(
|
|||
Assert.assertNotNull(file)
|
||||
Assert.assertTrue(file.exists(), "Should find ${file}")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun snapshotTest() {
|
||||
val id = "org.jetbrains.spek:spek:0.1-SNAPSHOT"
|
||||
val mavenId = MavenId.create(id)
|
||||
val dep = SimpleDep(mavenId)
|
||||
|
||||
// TODO: allow tests to add their own repo. The following call requires
|
||||
// "http://repository.jetbrains.com/all" to work
|
||||
// For now, just hardcoding the result we should have received
|
||||
// val repoResult = repoFinder.findCorrectRepo(id)
|
||||
|
||||
val repoResult = RepoFinder.RepoResult(HostConfig("http://repository.jetbrains.com/all/"),
|
||||
true, Version.of("0.1-SNAPSHOT"), true, Version("0.1-SNAPSHOT", "20151011.112011-29"))
|
||||
|
||||
val jarFile = dep.toJarFile(repoResult)
|
||||
val url = repoResult.hostConfig.url + jarFile
|
||||
|
||||
val metadataXmlPath = dep.toMetadataXmlPath(false, false, "0.1-SNAPSHOT")
|
||||
|
||||
Assert.assertEquals(metadataXmlPath, "org/jetbrains/spek/spek/0.1-SNAPSHOT/maven-metadata.xml")
|
||||
Assert.assertTrue(Kurl(HostConfig(url)).exists, "Should exist: $url")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue