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

maven pom importing

This commit is contained in:
evanchooly 2015-10-06 21:14:33 -04:00
parent ac7215ac12
commit 5f739035e0
6 changed files with 216 additions and 3 deletions

View file

@ -55,6 +55,7 @@ private class Main @Inject constructor(
println(Banner.get() + Kobalt.version + "\n")
// runTest()
runWithArgs(jc, args)
log(1, "************ shutting down executors")
executors.shutdown()
debug("All done")
})

View file

@ -75,14 +75,46 @@ public class ProjectGenerator : KobaltLogger {
put("version", pom.version ?: "0.1")
put("name", pom.name ?: pom.artifactId)
}
val properties = pom.properties
val mapped = properties.entrySet().toMap({it.key}, {translate(it.key)})
map.put("properties", properties
.entrySet()
.map({ Pair(mapped.get(it.key), it.value) }))
val partition = pom.dependencies.groupBy { it.scope }
.flatMap { it.value }
.map { updateVersion(it, mapped) }
.sortedBy { it.groupId + ":" + it.artifactId }
.partition { it.scope != "test" }
mainDeps.addAll(partition.first)
testDeps.addAll(partition.second)
}
private fun updateVersion(dep: Dependency, mapped: Map<String, String>): Dependency {
if ( dep.version.startsWith("\${")) {
val property = dep.version.substring(2, dep.version.length() - 1)
println("property = ${property}")
return Dependency(dep.groupId, dep.artifactId, "\${${mapped.get(property)}}", dep.optional, dep.scope)
} else {
return dep
}
}
private fun translate(key: String) : String {
val split = key.split('.')
return split.mapIndexed( { index, value -> if (index == 0) value else value.upperFirst() }).join("")
}
private fun String.upperFirst(): String {
if (this.isBlank()) {
return this
} else {
return this.substring(0, 1).toUpperCase() + this.substring(1)
}
}
/**
* Detect all the languages contained in this project.
*/

View file

@ -5,12 +5,10 @@ import com.beust.kobalt.misc.ToString
import com.google.inject.assistedinject.Assisted
import org.w3c.dom.Element
import org.w3c.dom.NodeList
import org.w3c.dom.Text
import org.xml.sax.InputSource
import java.io.FileReader
import javax.xml.xpath.XPathConstants
import kotlin.dom.get
import kotlin.dom.toXmlString
import kotlin.dom.childElements
public class Pom @javax.inject.Inject constructor(@Assisted val id: String,
@Assisted documentFile: java.io.File) : KobaltLogger {
@ -65,6 +63,12 @@ public class Pom @javax.inject.Inject constructor(@Assisted val id: String,
version = XPATH.compile("/project/version").evaluate(document)
name = XPATH.compile("/project/name").evaluate(document)
var list = XPATH.compile("/project/properties").evaluate(document, XPathConstants.NODESET) as NodeList
var elem = list.item(0) as Element?
elem.childElements().forEach {
properties.put(it.nodeName, it.textContent)
}
val deps = DEPENDENCIES.evaluate(document, XPathConstants.NODESET) as NodeList
for (i in 0..deps.getLength() - 1) {
val d = deps.item(i) as NodeList

View file

@ -2,7 +2,12 @@ import com.beust.kobalt.*
import com.beust.kobalt.plugin.packaging.assemble
{{imports}}
{{#properties}}
val {{first}} = {{second}}
{{/properties}}
val p = {{directive}} {
name = "{{name}}"
group = "{{group}}"
artifactId = name