From a0fccbf115d58e0794d33a06ef871a570fcf643e Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Thu, 7 Nov 2019 13:34:32 +0100 Subject: Better function to guess the build folder in plugin. --- .../main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'kvision-tools/kvision-compiler-plugin') diff --git a/kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt b/kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt index 43d83aef..e09c9021 100644 --- a/kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt +++ b/kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt @@ -61,9 +61,17 @@ class KVProcessor : AbstractProcessor() { if (it is Element.ClassElement && it.classDescriptor.name.asString().startsWith("I") && it.classDescriptor.name.asString().endsWith("Service") ) { + tailrec fun findBuildFolder(path: String): String { + val preSrcDir = path.substringBeforeLast("/src") + return if (path == preSrcDir || File(preSrcDir, "build").isDirectory) { + "$preSrcDir/build" + } else { + findBuildFolder(preSrcDir) + } + } + val cl = it.classDescriptor - val projectFolder = cl.canonicalFilePath()?.split("/src")?.get(0) ?: "" - val buildFolder = "$projectFolder/build" + val buildFolder = cl.canonicalFilePath()?.let { path -> findBuildFolder(path) } val genRootDir = File(buildFolder, "generated-src").apply { mkdirs() } -- cgit