mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Fix the topLines bug.
This commit is contained in:
parent
da85ec31f1
commit
a7553279cf
2 changed files with 8 additions and 6 deletions
|
@ -10,7 +10,7 @@ class Section(val start: Int, val end: Int) {
|
||||||
class IncludedBuildSourceDir(val line: Int, val dirs: List<String>)
|
class IncludedBuildSourceDir(val line: Int, val dirs: List<String>)
|
||||||
|
|
||||||
class BuildScriptInfo(val file: File, val fullBuildFile: List<String>, val sections: List<Section>,
|
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 {
|
fun isInSection(lineNumber: Int): Boolean {
|
||||||
sections.forEach {
|
sections.forEach {
|
||||||
if (lineNumber >= it.start && lineNumber <= it.end) return true
|
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
|
var count = 0
|
||||||
val buildScript = arrayListOf<String>()
|
val buildScript = arrayListOf<String>()
|
||||||
val topLines = arrayListOf<String>()
|
val topLines = arrayListOf<String>()
|
||||||
|
val finalTopLines = arrayListOf<String>()
|
||||||
|
|
||||||
fun updateCount(line: String) {
|
fun updateCount(line: String) {
|
||||||
val currentLine = StringBuffer()
|
val currentLine = StringBuffer()
|
||||||
|
@ -72,7 +73,7 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char)
|
||||||
foundKeyword = true
|
foundKeyword = true
|
||||||
count = 1
|
count = 1
|
||||||
buildScript.add(line)
|
buildScript.add(line)
|
||||||
topLines.add(line)
|
finalTopLines.addAll(topLines)
|
||||||
} else {
|
} else {
|
||||||
if (line.startsWith("import")) {
|
if (line.startsWith("import")) {
|
||||||
if (isAllowedImport(line)) {
|
if (isAllowedImport(line)) {
|
||||||
|
@ -99,7 +100,7 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char)
|
||||||
if (sections.isNotEmpty()) {
|
if (sections.isNotEmpty()) {
|
||||||
val result = (imports.distinct() + buildScript).joinToString("\n") + "\n"
|
val result = (imports.distinct() + buildScript).joinToString("\n") + "\n"
|
||||||
|
|
||||||
return BuildScriptInfo(file, lines, sections, imports)
|
return BuildScriptInfo(file, lines, sections, imports, finalTopLines)
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,13 +157,14 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
// Run every buildScriptInfo section in its own source file
|
// Run every buildScriptInfo section in its own source file
|
||||||
var counter = 0
|
var counter = 0
|
||||||
analyzedFiles.forEach { af ->
|
analyzedFiles.forEach { af ->
|
||||||
af.buildScriptInfo.sections.forEach { section ->
|
val buildScriptInfo = af.buildScriptInfo
|
||||||
|
buildScriptInfo.sections.forEach { section ->
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create a source file with just this buildScriptInfo{}
|
// Create a source file with just this buildScriptInfo{}
|
||||||
//
|
//
|
||||||
val bs = af.file.readLines().subList(section.start, section.end + 1)
|
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 {
|
val sourceFile = Files.createTempFile(null, ".kt").toFile().apply {
|
||||||
writeText(source)
|
writeText(source)
|
||||||
}
|
}
|
||||||
|
@ -197,7 +198,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
val newDirs = arrayListOf<String>().apply { addAll(Kobalt.buildSourceDirs) }
|
val newDirs = arrayListOf<String>().apply { addAll(Kobalt.buildSourceDirs) }
|
||||||
newDirs.removeAll(currentDirs)
|
newDirs.removeAll(currentDirs)
|
||||||
if (newDirs.any()) {
|
if (newDirs.any()) {
|
||||||
af.buildScriptInfo.includedBuildSourceDirs.add(IncludedBuildSourceDir(section.start, newDirs))
|
buildScriptInfo.includedBuildSourceDirs.add(IncludedBuildSourceDir(section.start, newDirs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue