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

add some more testing around pom importing

This commit is contained in:
evanchooly 2015-10-09 22:21:18 -04:00
parent 59e6776e03
commit f2aa5435ed
4 changed files with 89 additions and 23 deletions

View file

@ -19,6 +19,15 @@ import java.util.HashMap
* Generate a new project.
*/
public class ProjectGenerator : KobaltLogger {
companion object {
/**
* Turns a dot property into a proper Kotlin identifier, e.g. common.version -> commonVersion
*/
fun translate(key: String): String {
return key.split('.').mapIndexed( { index, value -> if (index == 0) value else value.upperFirst() }).join("")
}
}
fun run(args: Args) {
if (File(args.buildFile).exists()) {
log(1, "Build file ${args.buildFile} already exists, not overwriting it")
@ -52,7 +61,7 @@ public class ProjectGenerator : KobaltLogger {
map.put("mainDependencies", mainDeps)
map.put("testDependencies", testDeps)
File("pom.xml").let {
if (it.exists()) {
if (it.absoluteFile.exists()) {
importPom(it, mainDeps, testDeps, map)
}
}
@ -68,13 +77,13 @@ public class ProjectGenerator : KobaltLogger {
private fun importPom(pomFile: File, mainDeps: ArrayList<Dependency>, testDeps: ArrayList<Dependency>,
map: HashMap<String, Any?>) {
var pom = Pom("imported", pomFile)
var pom = Pom("imported", pomFile.absoluteFile)
with(map) {
put("group", pom.groupId ?: "com.example")
put("artifactId", pom.artifactId ?: "com.example")
put("version", pom.version ?: "0.1")
put("name", pom.name ?: pom.artifactId)
put("repositories", pom.repos.map({ "\"${it}\"" }).join(","))
put("repositories", pom.repositories.map({ "\"${it}\"" }).join(","))
}
val properties = pom.properties
@ -102,18 +111,6 @@ public class ProjectGenerator : KobaltLogger {
dep
}
/**
* Turns a dot property into a proper Kotlin identifier, e.g. common.version -> commonVersion
*/
private fun translate(key: String) =
key.split('.').mapIndexed( { index, value -> if (index == 0) value else value.upperFirst() }).join("")
private fun String.upperFirst() =
if (this.isBlank()) {
this
} else {
this.substring(0, 1).toUpperCase() + this.substring(1)
}
/**
* Detect all the languages contained in this project.
@ -130,3 +127,7 @@ public class ProjectGenerator : KobaltLogger {
return result.map { it.first }
}
}
private fun String.upperFirst(): String {
return if (this.isBlank()) this else this.substring(0, 1).toUpperCase() + this.substring(1)
}

View file

@ -19,7 +19,7 @@ public class Pom @javax.inject.Inject constructor(@Assisted val id: String,
var version: String? = null
var name: String? = null
var properties = sortedMapOf<String, String>()
var repos = listOf<String>()
var repositories = listOf<String>()
public interface IFactory {
fun create(@Assisted id: String, @Assisted documentFile : java.io.File) : Pom
@ -63,13 +63,15 @@ public class Pom @javax.inject.Inject constructor(@Assisted val id: String,
artifactId = XPATH.compile("/project/artifactId").evaluate(document)
version = XPATH.compile("/project/version").evaluate(document)
name = XPATH.compile("/project/name").evaluate(document)
var list = XPATH.compile("/project/repositories").evaluate(document, XPathConstants.NODESET) as NodeList
var elem = list.item(0) as Element?
repos = elem.childElements()
.map({ it.getElementsByTagName("url").item(0).textContent })
var repositoriesList = XPATH.compile("/project/repositories").evaluate(document, XPathConstants.NODESET) as NodeList
// if (repositoriesList.getLength() != 0) {
var elem = repositoriesList.item(0) as Element?
repositories = elem.childElements()
.map({ it.getElementsByTagName("url").item(0).textContent })
// }
list = XPATH.compile("/project/properties").evaluate(document, XPathConstants.NODESET) as NodeList
elem = list.item(0) as Element?
val propertiesList = XPATH.compile("/project/properties").evaluate(document, XPathConstants.NODESET) as NodeList
/*var*/ elem = propertiesList.item(0) as Element?
elem.childElements().forEach {
properties.put(it.nodeName, it.textContent)
}