1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-25 07:57:12 -07:00

Fix the topLines bug.

This commit is contained in:
Cedric Beust 2017-03-30 13:16:17 -07:00
parent da85ec31f1
commit a7553279cf
2 changed files with 8 additions and 6 deletions

View file

@ -10,7 +10,7 @@ class Section(val start: Int, val end: Int) {
class IncludedBuildSourceDir(val line: Int, val dirs: List<String>)
class BuildScriptInfo(val file: File, val fullBuildFile: List<String>, val sections: List<Section>,
val imports: List<String>) {
val imports: List<String>, val topLines: List<String>) {
fun isInSection(lineNumber: Int): Boolean {
sections.forEach {
if (lineNumber >= it.start && lineNumber <= it.end) return true
@ -42,6 +42,7 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char)
var count = 0
val buildScript = arrayListOf<String>()
val topLines = arrayListOf<String>()
val finalTopLines = arrayListOf<String>()
fun updateCount(line: String) {
val currentLine = StringBuffer()
@ -72,7 +73,7 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char)
foundKeyword = true
count = 1
buildScript.add(line)
topLines.add(line)
finalTopLines.addAll(topLines)
} else {
if (line.startsWith("import")) {
if (isAllowedImport(line)) {
@ -99,7 +100,7 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char)
if (sections.isNotEmpty()) {
val result = (imports.distinct() + buildScript).joinToString("\n") + "\n"
return BuildScriptInfo(file, lines, sections, imports)
return BuildScriptInfo(file, lines, sections, imports, finalTopLines)
} else {
return null
}

View file

@ -157,13 +157,14 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
// Run every buildScriptInfo section in its own source file
var counter = 0
analyzedFiles.forEach { af ->
af.buildScriptInfo.sections.forEach { section ->
val buildScriptInfo = af.buildScriptInfo
buildScriptInfo.sections.forEach { section ->
//
// Create a source file with just this buildScriptInfo{}
//
val bs = af.file.readLines().subList(section.start, section.end + 1)
val source = (af.buildScriptInfo.imports + bs).joinToString("\n")
val source = (buildScriptInfo.imports + buildScriptInfo.topLines + bs).joinToString("\n")
val sourceFile = Files.createTempFile(null, ".kt").toFile().apply {
writeText(source)
}
@ -197,7 +198,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
val newDirs = arrayListOf<String>().apply { addAll(Kobalt.buildSourceDirs) }
newDirs.removeAll(currentDirs)
if (newDirs.any()) {
af.buildScriptInfo.includedBuildSourceDirs.add(IncludedBuildSourceDir(section.start, newDirs))
buildScriptInfo.includedBuildSourceDirs.add(IncludedBuildSourceDir(section.start, newDirs))
}
}