From ccbca535e8bf7aefea07541e5f0aefcfc0418898 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 18 Dec 2015 02:27:09 +0400 Subject: [PATCH] Generate a random .kotlin_module for each compilation. --- .../com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index 467d8cb5..de965ccc 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.cli.common.CLICompiler import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler import java.io.File +import java.util.* import javax.inject.Inject import javax.inject.Singleton import kotlin.properties.Delegates @@ -71,7 +72,8 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo, * There are plenty of ways in which this method can break but this will be immediately * apparent if it happens. */ - private fun invokeCompiler(cp: List, allArgs: Array): Boolean { + private fun invokeCompiler(cp: List, args: Array): Boolean { + val allArgs = listOf("-module-name", "module" + Random().nextInt()) + args log(2, "Calling kotlinc " + allArgs.joinToString(" ")) val result : Boolean = if (true) { @@ -82,11 +84,11 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo, }.get(0) val kCompiler = classLoader.loadClass("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler") val compilerInstance = kCompiler.newInstance() - val exitCode = compilerMain.invoke(null, compilerInstance, allArgs) + val exitCode = compilerMain.invoke(null, compilerInstance, allArgs.toTypedArray()) val nameMethod = exitCode.javaClass.getMethod("name") "OK" == nameMethod.invoke(exitCode).toString() } else { - val exitCode = CLICompiler.doMainNoExit(K2JVMCompiler(), allArgs) + val exitCode = CLICompiler.doMainNoExit(K2JVMCompiler(), allArgs.toTypedArray()) exitCode == ExitCode.OK } return result