mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-25 16:07:12 -07:00
BlockExtractorTest.
This commit is contained in:
parent
9f249822ba
commit
255e17d88b
2 changed files with 42 additions and 2 deletions
|
@ -138,6 +138,12 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
|||
return SplitBuildFile(imports, code, containsProfiles)
|
||||
}
|
||||
|
||||
companion object {
|
||||
val BUILD_SCRIPT_REGEXP: Pattern = Pattern.compile("^val.*buildScript.*\\{")
|
||||
val BLOCK_EXTRACTOR = BlockExtractor(BUILD_SCRIPT_REGEXP, '{', '}')
|
||||
|
||||
}
|
||||
|
||||
fun parseBuildScriptInfos(projectDir: String, context: KobaltContext, profiles: Profiles)
|
||||
: List<BuildFileWithBuildScript> {
|
||||
val root = sourceDir(projectDir)
|
||||
|
@ -149,8 +155,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
|||
toProcess.forEach { buildFile ->
|
||||
val splitBuildFile = profiles.applyProfiles(buildFile.readLines())
|
||||
containsProfiles = containsProfiles or splitBuildFile.containsProfiles
|
||||
val bsi = BlockExtractor(Pattern.compile("^val.*buildScript.*\\{"), '{', '}')
|
||||
.extractBlock(buildFile, (splitBuildFile.imports + splitBuildFile.code))
|
||||
val bsi = BLOCK_EXTRACTOR.extractBlock(buildFile, (splitBuildFile.imports + splitBuildFile.code))
|
||||
if (bsi != null) analyzedFiles.add(BuildFileWithBuildScript(buildFile, bsi))
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.TestModule
|
||||
import com.beust.kobalt.app.BuildFiles
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.testng.annotations.Guice
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
|
||||
@Guice(modules = arrayOf(TestModule::class))
|
||||
class BlockExtractorTest {
|
||||
|
||||
@Test
|
||||
fun verifyExtraction() {
|
||||
val imports = listOf("import com.beust.kobalt.*", "import com . beust.kobalt.api.*")
|
||||
val topLines = listOf("", "val VERSION = \"6.11.1-SNAPSHOT\"", "")
|
||||
val buildScript = listOf(
|
||||
"val bs = buildScript {",
|
||||
" repos(\"https://dl.bintray.com/cbeust/maven\")",
|
||||
"}"
|
||||
)
|
||||
val allLines = imports + topLines + buildScript
|
||||
|
||||
val be = BuildFiles.BLOCK_EXTRACTOR
|
||||
val bsi = be.extractBlock(File(""), allLines)
|
||||
if (bsi != null) {
|
||||
assertThat(bsi.sections.size).isEqualTo(1)
|
||||
assertThat(bsi.sections[0].start).isEqualTo(5)
|
||||
assertThat(bsi.sections[0].end).isEqualTo(7)
|
||||
assertThat(bsi.topLines).isEqualTo(topLines)
|
||||
} else {
|
||||
throw AssertionError("Should have found a buildScript{}")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue