mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Evaluate variables in version tags.
This commit is contained in:
parent
901dbd1b95
commit
a3c9792c12
3 changed files with 44 additions and 26 deletions
|
@ -1,7 +1,7 @@
|
||||||
package com.beust.kobalt.maven
|
package com.beust.kobalt.maven
|
||||||
|
|
||||||
import com.beust.kobalt.misc.log
|
|
||||||
import com.beust.kobalt.misc.toString
|
import com.beust.kobalt.misc.toString
|
||||||
|
import com.beust.kobalt.misc.warn
|
||||||
import com.google.inject.assistedinject.Assisted
|
import com.google.inject.assistedinject.Assisted
|
||||||
import kotlinx.dom.childElements
|
import kotlinx.dom.childElements
|
||||||
import org.w3c.dom.Element
|
import org.w3c.dom.Element
|
||||||
|
@ -18,6 +18,33 @@ class Pom @javax.inject.Inject constructor(@Assisted val id: String,
|
||||||
var artifactId: String? = null
|
var artifactId: String? = null
|
||||||
var packaging: String? = null
|
var packaging: String? = null
|
||||||
var version: String? = null
|
var version: String? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the version is a string, extract it, look it up and evaluate it if we find it. Otherwise, error.
|
||||||
|
*/
|
||||||
|
private fun calculateVersion(s: String) : String {
|
||||||
|
val v = extractVar(s)
|
||||||
|
if (v != null) {
|
||||||
|
val value = properties[v]
|
||||||
|
if (value != null) {
|
||||||
|
return value
|
||||||
|
} else {
|
||||||
|
warn("Unknown variable for version: " + s)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun extractVar(s: String) : String? {
|
||||||
|
if (s.startsWith("\${") && s.endsWith("}")) {
|
||||||
|
return s.substring(2, s.length - 1)
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var name: String? = null
|
var name: String? = null
|
||||||
var properties = sortedMapOf<String, String>()
|
var properties = sortedMapOf<String, String>()
|
||||||
var repositories = listOf<String>()
|
var repositories = listOf<String>()
|
||||||
|
@ -29,28 +56,9 @@ class Pom @javax.inject.Inject constructor(@Assisted val id: String,
|
||||||
data class Dependency(val groupId: String, val artifactId: String, val packaging: String?,
|
data class Dependency(val groupId: String, val artifactId: String, val packaging: String?,
|
||||||
val version: String, val optional: Boolean = false, val scope: String? = null) {
|
val version: String, val optional: Boolean = false, val scope: String? = null) {
|
||||||
|
|
||||||
/** When a variable is used in a maven file, e.g. ${version} */
|
|
||||||
private val VAR = "$" + "{"
|
|
||||||
|
|
||||||
val mustDownload: Boolean
|
val mustDownload: Boolean
|
||||||
get() = !optional && "provided" != scope && "test" != scope
|
get() = !optional && "provided" != scope && "test" != scope
|
||||||
|
|
||||||
val isValid: Boolean
|
|
||||||
get() {
|
|
||||||
var result = false
|
|
||||||
if (version.contains(VAR)) {
|
|
||||||
log(3, "Skipping variable version ${this}")
|
|
||||||
} else if (groupId.contains(VAR)) {
|
|
||||||
log(3, "Skipping variable groupId ${this}")
|
|
||||||
} else if (artifactId.contains(VAR)) {
|
|
||||||
log(3, "Skipping variable artifactId ${this}")
|
|
||||||
} else {
|
|
||||||
result = true
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
val id: String = "$groupId:$artifactId:$version"
|
val id: String = "$groupId:$artifactId:$version"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +89,7 @@ class Pom @javax.inject.Inject constructor(@Assisted val id: String,
|
||||||
var groupId: String? = null
|
var groupId: String? = null
|
||||||
var artifactId: String? = null
|
var artifactId: String? = null
|
||||||
var packaging: String? = null
|
var packaging: String? = null
|
||||||
var version: String = ""
|
var readVersion: String = ""
|
||||||
var optional: Boolean? = false
|
var optional: Boolean? = false
|
||||||
var scope: String? = null
|
var scope: String? = null
|
||||||
for (j in 0..d.length - 1) {
|
for (j in 0..d.length - 1) {
|
||||||
|
@ -91,16 +99,17 @@ class Pom @javax.inject.Inject constructor(@Assisted val id: String,
|
||||||
"groupId" -> groupId = e.textContent
|
"groupId" -> groupId = e.textContent
|
||||||
"artifactId" -> artifactId = e.textContent
|
"artifactId" -> artifactId = e.textContent
|
||||||
"type" -> packaging = e.textContent
|
"type" -> packaging = e.textContent
|
||||||
"version" -> version = e.textContent
|
"version" -> readVersion = e.textContent
|
||||||
"optional" -> optional = "true".equals(e.textContent, true)
|
"optional" -> optional = "true".equals(e.textContent, true)
|
||||||
"scope" -> scope = e.textContent
|
"scope" -> scope = e.textContent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val version = calculateVersion(readVersion)
|
||||||
val tmpDependency = Dependency(groupId!!, artifactId!!, packaging, version, optional!!, scope)
|
val tmpDependency = Dependency(groupId!!, artifactId!!, packaging, version, optional!!, scope)
|
||||||
dependencies.add(tmpDependency)
|
dependencies.add(tmpDependency)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString() = toString("Pom", id, "id")
|
override fun toString() = toString("Pom", "id", id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,8 +120,9 @@ class MavenDependency @Inject constructor(
|
||||||
override fun directDependencies() : List<IClasspathDependency> {
|
override fun directDependencies() : List<IClasspathDependency> {
|
||||||
val result = arrayListOf<IClasspathDependency>()
|
val result = arrayListOf<IClasspathDependency>()
|
||||||
try {
|
try {
|
||||||
pomFactory.create(id, pomFile.get()).dependencies.filter {
|
val pom = pomFactory.create(id, pomFile.get())
|
||||||
it.mustDownload && it.isValid
|
pom.dependencies.filter {
|
||||||
|
it.mustDownload
|
||||||
}.forEach {
|
}.forEach {
|
||||||
result.add(create(MavenId.toId(it.groupId, it.artifactId, it.packaging, it.version)))
|
result.add(create(MavenId.toId(it.groupId, it.artifactId, it.packaging, it.version)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ class DownloadTest @Inject constructor(
|
||||||
val depFactory: DepFactory,
|
val depFactory: DepFactory,
|
||||||
val localRepo: LocalRepo,
|
val localRepo: LocalRepo,
|
||||||
val mdFactory: MavenDependency.IFactory,
|
val mdFactory: MavenDependency.IFactory,
|
||||||
val finderFactory: RepoFinderCallable.IFactory,
|
val dependencyManager: DependencyManager,
|
||||||
val executors: KobaltExecutors) : KobaltTest() {
|
val executors: KobaltExecutors) : KobaltTest() {
|
||||||
private var executor: ExecutorService by Delegates.notNull()
|
private var executor: ExecutorService by Delegates.notNull()
|
||||||
|
|
||||||
|
@ -165,5 +165,13 @@ class DownloadTest @Inject constructor(
|
||||||
// Assert.assertEquals(results.size, 1)
|
// Assert.assertEquals(results.size, 1)
|
||||||
// Assert.assertEquals(results[0].version, "1.1.0")
|
// Assert.assertEquals(results[0].version, "1.1.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun variablesShouldBeExpanded() {
|
||||||
|
val dep = dependencyManager.createMaven("org.mapdb:mapdb:3.0.0-M3")
|
||||||
|
val closure = dependencyManager.transitiveClosure(listOf(dep))
|
||||||
|
val d = closure.filter { it.id.contains("eclipse-collections-api")}
|
||||||
|
Assert.assertEquals(d.size, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue