From 872a0d3961b79bf59a03abe21ee5ca2c2395b43c Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 12 Dec 2015 02:23:44 +0400 Subject: [PATCH] Fix maven-metadata-local.xml. --- src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt | 9 ++++++++- .../kotlin/com/beust/kobalt/maven/UnversionedDep.kt | 10 ++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt b/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt index 6d50105a..d48e75e7 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt @@ -91,7 +91,8 @@ public class RepoFinder @Inject constructor(val executors: KobaltExecutors) { if (version!!.contains("SNAPSHOT")) { val dep = SimpleDep(mavenId) val isLocal = repoUrl.startsWith(FileDependency.PREFIX_FILE) - val snapshotVersion = findSnapshotVersion(dep.toMetadataXmlPath(false, isLocal), repoUrl) + val snapshotVersion = if (isLocal) version!! + else findSnapshotVersion(dep.toMetadataXmlPath(false, isLocal, version), repoUrl) if (snapshotVersion != null) { return RepoResult(repo, true, version, true /* hasJar, potential bug here */, snapshotVersion) @@ -154,6 +155,12 @@ public class RepoFinder @Inject constructor(val executors: KobaltExecutors) { val bn = buildNumber.evaluate(doc, XPathConstants.STRING) if (! Strings.isEmpty(ts.toString()) && ! Strings.isEmpty(bn.toString())) { return ts.toString() + "-" + bn.toString() + } else { + val lastUpdated = XPATH.compile("/metadata/versioning/lastUpdated") + if (! lastUpdated.toString().isEmpty()) { + return lastUpdated.toString() + } + } } catch(ex: Exception) { log(2, "Couldn't find metadata at $url") diff --git a/src/main/kotlin/com/beust/kobalt/maven/UnversionedDep.kt b/src/main/kotlin/com/beust/kobalt/maven/UnversionedDep.kt index 0b8c1c18..ed76b1d3 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/UnversionedDep.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/UnversionedDep.kt @@ -8,8 +8,14 @@ import java.io.File * eventually resolve to the latest version of the artifact. */ open class UnversionedDep(open val groupId: String, open val artifactId: String) { - open fun toMetadataXmlPath(fileSystem: Boolean = true, isLocal: Boolean) = - toDirectory("", fileSystem) + if (isLocal) "maven-metadata-local.xml" else "maven-metadata.xml" + open fun toMetadataXmlPath(fileSystem: Boolean = true, isLocal: Boolean, version: String? = null) : String { + var result = toDirectory("", fileSystem) + if (isLocal) "maven-metadata-local.xml" else "maven-metadata.xml" + if (! File(result).exists() && version != null) { + result = toDirectory("", fileSystem) + version + File.separator + + if (isLocal) "maven-metadata-local.xml" else "maven-metadata.xml" + } + return result + } /** * Turn this dependency to a directory. If fileSystem is true, use the file system