mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 08:38:13 -07:00
Fix tests.
This commit is contained in:
parent
b58c495bbd
commit
2fda71682f
1 changed files with 36 additions and 44 deletions
|
@ -11,7 +11,6 @@ import com.beust.kobalt.internal.PluginInfo
|
||||||
import com.beust.kobalt.internal.build.BuildSources
|
import com.beust.kobalt.internal.build.BuildSources
|
||||||
import com.beust.kobalt.misc.*
|
import com.beust.kobalt.misc.*
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
import jdk.nashorn.internal.objects.NativeArray.forEach
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.nio.file.*
|
import java.nio.file.*
|
||||||
|
@ -46,11 +45,11 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
val buildScriptUtil: BuildScriptUtil) {
|
val buildScriptUtil: BuildScriptUtil) {
|
||||||
private val profileLines = arrayListOf<String>()
|
private val profileLines = arrayListOf<String>()
|
||||||
private val activeProfiles = arrayListOf<String>()
|
private val activeProfiles = arrayListOf<String>()
|
||||||
private val KOBALT_SRC = File("kobalt/src/")
|
|
||||||
|
|
||||||
var containsProfiles = false
|
var containsProfiles = false
|
||||||
val projects = arrayListOf<Project>()
|
val projects = arrayListOf<Project>()
|
||||||
|
|
||||||
|
private fun sourceDir(root: String) = File(KFiles.joinDir(root, "kobalt", "src"))
|
||||||
|
|
||||||
private fun findFiles(file: File, accept: (File) -> Boolean) : List<File> {
|
private fun findFiles(file: File, accept: (File) -> Boolean) : List<File> {
|
||||||
val result = arrayListOf<File>()
|
val result = arrayListOf<File>()
|
||||||
|
|
||||||
|
@ -72,10 +71,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
private fun findBuildSourceFiles(root: String) : List<File> {
|
private fun findBuildSourceFiles(root: String) : List<File> {
|
||||||
val result = arrayListOf<File>()
|
val result = arrayListOf<File>()
|
||||||
|
|
||||||
val sourceDirs = arrayListOf<String>().apply { add(root + File.separator + KOBALT_SRC) }.map(::File)
|
result.addAll(findFiles(sourceDir(root), { it.name.endsWith(".kt") }))
|
||||||
sourceDirs.forEach { dir ->
|
|
||||||
result.addAll(findFiles(dir, { it.name.endsWith(".kt") }))
|
|
||||||
}
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,23 +79,20 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
* @return the new Build.kt
|
* @return the new Build.kt
|
||||||
*/
|
*/
|
||||||
fun parseBuildFiles(projectDir: String, context: KobaltContext) : File {
|
fun parseBuildFiles(projectDir: String, context: KobaltContext) : File {
|
||||||
val sourceDirs = arrayListOf<String>().apply { add(projectDir + File.separator + KOBALT_SRC) }
|
|
||||||
val map = hashMapOf<File, AnalyzedBuildFile>()
|
val map = hashMapOf<File, AnalyzedBuildFile>()
|
||||||
val newSourceDirs = arrayListOf<IncludedBuildSourceDir>()
|
val newSourceDirs = arrayListOf<IncludedBuildSourceDir>()
|
||||||
sourceDirs.forEach {
|
val filesWithBuildScript = parseBuildScriptInfos(projectDir, context)
|
||||||
val filesWithBuildScript = parseBuildScriptInfos(projectDir, context)
|
filesWithBuildScript.forEach {
|
||||||
filesWithBuildScript.forEach {
|
map.put(it.file, it)
|
||||||
map.put(it.file, it)
|
}
|
||||||
}
|
if (filesWithBuildScript.any()) {
|
||||||
if (filesWithBuildScript.any()) {
|
filesWithBuildScript.forEach { af ->
|
||||||
filesWithBuildScript.forEach { af ->
|
val bsi = af.buildScriptInfo
|
||||||
val bsi = af.buildScriptInfo
|
newSourceDirs.addAll(bsi.includedBuildSourceDirs)
|
||||||
newSourceDirs.addAll(bsi.includedBuildSourceDirs)
|
|
||||||
}
|
|
||||||
log(2, " Found buildScriptInfos: " + filesWithBuildScript)
|
|
||||||
} else {
|
|
||||||
log(2, " No buildScriptInfos")
|
|
||||||
}
|
}
|
||||||
|
log(2, " Found buildScriptInfos: " + filesWithBuildScript)
|
||||||
|
} else {
|
||||||
|
log(2, " No buildScriptInfos")
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -107,28 +100,27 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
//
|
//
|
||||||
val imports = arrayListOf<String>()
|
val imports = arrayListOf<String>()
|
||||||
val code = arrayListOf<String>()
|
val code = arrayListOf<String>()
|
||||||
sourceDirs.forEach { sourceDir ->
|
val sourceDir = sourceDir(projectDir)
|
||||||
findFiles(File(sourceDir), { it.name.endsWith(".kt") }).forEach { file ->
|
findFiles(sourceDir, { it.name.endsWith(".kt") }).forEach { file ->
|
||||||
code.add("\n// $file")
|
code.add("\n// $file")
|
||||||
val analyzedFile = map[file]
|
val analyzedFile = map[file]
|
||||||
val bsi = analyzedFile?.buildScriptInfo
|
val bsi = analyzedFile?.buildScriptInfo
|
||||||
|
|
||||||
file.readLines().forEachIndexed { lineNumber, line ->
|
file.readLines().forEachIndexed { lineNumber, line ->
|
||||||
if (bsi == null || ! bsi.isInSection(lineNumber)) {
|
if (bsi == null || ! bsi.isInSection(lineNumber)) {
|
||||||
correctProfileLine(context, line).let { cpl ->
|
correctProfileLine(context, line).let { cpl ->
|
||||||
(if (cpl.startsWith("import")) imports else code).add(cpl)
|
(if (cpl.startsWith("import")) imports else code).add(cpl)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val isd = bsi.includedBuildSourceDirsForLine(lineNumber)
|
val isd = bsi.includedBuildSourceDirsForLine(lineNumber)
|
||||||
log(2, " Skipping line $lineNumber from file $file")
|
log(2, " Skipping line $lineNumber from file $file")
|
||||||
if (isd.any()) {
|
if (isd.any()) {
|
||||||
// If we found any new buildSourceDirs, all all the files found in these directories
|
// If we found any new buildSourceDirs, all all the files found in these directories
|
||||||
// to the big Build.kt
|
// to the big Build.kt
|
||||||
val allBuildFiles = isd.flatMap { findBuildSourceFiles(projectDir + File.separator + it) }
|
val allBuildFiles = isd.flatMap { findBuildSourceFiles(projectDir + File.separator + it) }
|
||||||
val sbf = includeFileContent(context, allBuildFiles)
|
val sbf = includeFileContent(context, allBuildFiles)
|
||||||
imports.addAll(sbf.imports)
|
imports.addAll(sbf.imports)
|
||||||
code.addAll(sbf.code)
|
code.addAll(sbf.code)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +129,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
//
|
//
|
||||||
// Create the big Build.kt out of the imports and code we've found so far
|
// Create the big Build.kt out of the imports and code we've found so far
|
||||||
//
|
//
|
||||||
val result = File(KFiles.findBuildScriptDir(), "Build.kt")
|
val result = File(KFiles.findBuildScriptDir(projectDir), "Build.kt")
|
||||||
result.writeText(imports.joinToString("\n"))
|
result.writeText(imports.joinToString("\n"))
|
||||||
result.appendText(code.joinToString("\n"))
|
result.appendText(code.joinToString("\n"))
|
||||||
|
|
||||||
|
@ -160,7 +152,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
}
|
}
|
||||||
|
|
||||||
fun parseBuildScriptInfos(projectDir: String, context: KobaltContext) : List<AnalyzedBuildFile> {
|
fun parseBuildScriptInfos(projectDir: String, context: KobaltContext) : List<AnalyzedBuildFile> {
|
||||||
val root = File(projectDir + File.separator + KOBALT_SRC)
|
val root = sourceDir(projectDir)
|
||||||
val files = findBuildSourceFiles(projectDir)
|
val files = findBuildSourceFiles(projectDir)
|
||||||
val toProcess = arrayListOf<File>().apply { addAll(files) }
|
val toProcess = arrayListOf<File>().apply { addAll(files) }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue