mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Generate BuildConfig.kt.
This commit is contained in:
parent
32f1f084a2
commit
c924d9bcd3
1 changed files with 26 additions and 1 deletions
|
@ -11,8 +11,33 @@ class KotlinProjectInfo : IProjectInfo {
|
|||
override val defaultSourceDirectories = hashSetOf("src/main/kotlin", "src/main/resources")
|
||||
override val defaultTestDirectories = hashSetOf("src/test/kotlin", "src/test/resources")
|
||||
|
||||
private fun generate(type: String, name: String, value: Any) =
|
||||
" val $name : $type = $value"
|
||||
|
||||
override fun generateBuildConfig(packageName: String, variant: Variant, buildConfigs: List<BuildConfig>) : String {
|
||||
return "package $packageName"
|
||||
val lines = arrayListOf<String>()
|
||||
with(lines) {
|
||||
add("package $packageName")
|
||||
add("")
|
||||
add("class BuildConfig {")
|
||||
add(" companion object {")
|
||||
if (variant.productFlavor != null) {
|
||||
add(generate("String", "PRODUCT_FLAVOR", "\"" + variant.productFlavor.name + "\""))
|
||||
}
|
||||
if (variant.buildType != null) {
|
||||
add(generate("String", "BUILD_TYPE", "\"" + variant.buildType.name + "\""))
|
||||
}
|
||||
buildConfigs.forEach {
|
||||
it.fields.forEach { field ->
|
||||
add(generate(field.type, field.name, field.value))
|
||||
}
|
||||
}
|
||||
add(" }")
|
||||
add("}")
|
||||
add("")
|
||||
}
|
||||
|
||||
return lines.joinToString("\n")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue