CLI, Ant: add kotlin-reflect.jar to classpath by default, support "-no-reflect"
Note that now "-no-stdlib" implies "-no-reflect". #KT-13237 Fixed
This commit is contained in:
@@ -26,6 +26,8 @@ class Kotlin2JvmTask : KotlinCompilerBaseTask() {
|
||||
var includeRuntime: Boolean = true
|
||||
var moduleName: String? = null
|
||||
|
||||
var noReflect: Boolean = false
|
||||
|
||||
private var compileClasspath: Path? = null
|
||||
|
||||
fun setClasspath(classpath: Path) {
|
||||
@@ -68,6 +70,7 @@ class Kotlin2JvmTask : KotlinCompilerBaseTask() {
|
||||
}
|
||||
|
||||
if (noStdlib) args.add("-no-stdlib")
|
||||
if (noReflect) args.add("-no-reflect")
|
||||
if (includeRuntime) args.add("-include-runtime")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.io.File
|
||||
import java.lang.ref.SoftReference
|
||||
import java.net.JarURLConnection
|
||||
|
||||
object KotlinAntTaskUtil {
|
||||
internal object KotlinAntTaskUtil {
|
||||
private var classLoaderRef = SoftReference<ClassLoader?>(null)
|
||||
|
||||
private val libPath: File by lazy {
|
||||
@@ -37,19 +37,16 @@ object KotlinAntTaskUtil {
|
||||
antTaskJarPath.parentFile
|
||||
}
|
||||
|
||||
val compilerJar: File by lazy {
|
||||
File(libPath, "kotlin-compiler.jar").assertExists()
|
||||
}
|
||||
val compilerJar: File by jar("kotlin-compiler.jar")
|
||||
val runtimeJar: File by jar("kotlin-runtime.jar")
|
||||
val reflectJar: File by jar("kotlin-reflect.jar")
|
||||
|
||||
val runtimeJar: File by lazy {
|
||||
File(libPath, "kotlin-runtime.jar").assertExists()
|
||||
}
|
||||
|
||||
private fun File.assertExists(): File {
|
||||
if (!this.exists()) {
|
||||
throw IllegalStateException("${name} is not found in the directory of Kotlin Ant task")
|
||||
private fun jar(name: String) = lazy {
|
||||
File(libPath, name).apply {
|
||||
if (!exists()) {
|
||||
throw IllegalStateException("File is not found in the directory of Kotlin Ant task: $name")
|
||||
}
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@@ -65,8 +62,7 @@ object KotlinAntTaskUtil {
|
||||
|
||||
return classLoader
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val Task.defaultModuleName: String?
|
||||
get() = owningTarget?.name ?: project?.name
|
||||
internal val Task.defaultModuleName: String?
|
||||
get() = owningTarget?.name ?: project?.name
|
||||
|
||||
@@ -31,6 +31,7 @@ class KotlinCompilerAdapter : Javac13() {
|
||||
|
||||
var additionalArguments: MutableList<Commandline.Argument> = ArrayList(0)
|
||||
|
||||
@Suppress("unused") // Used via reflection by Ant
|
||||
fun createCompilerArg(): Commandline.Argument {
|
||||
val argument = Commandline.Argument()
|
||||
additionalArguments.add(argument)
|
||||
@@ -94,15 +95,22 @@ class KotlinCompilerAdapter : Javac13() {
|
||||
}
|
||||
|
||||
private fun addRuntimeToJavacClasspath(kotlinc: Kotlin2JvmTask) {
|
||||
for (arg in kotlinc.args) {
|
||||
// If "-no-stdlib" was specified explicitly, probably the user also wanted the javac classpath to not have it
|
||||
if ("-no-stdlib" == arg) return
|
||||
}
|
||||
// If "-no-stdlib" (or "-no-reflect") was specified explicitly, probably the user also wanted the javac classpath to not have it
|
||||
val addStdlib = "-no-stdlib" !in kotlinc.args
|
||||
val addReflect = "-no-reflect" !in kotlinc.args
|
||||
|
||||
if (!addStdlib && !addReflect) return
|
||||
|
||||
if (compileClasspath == null) {
|
||||
compileClasspath = Path(getProject())
|
||||
}
|
||||
compileClasspath.add(Path(getProject(), KotlinAntTaskUtil.runtimeJar.absolutePath))
|
||||
if (addStdlib) {
|
||||
compileClasspath.add(Path(getProject(), KotlinAntTaskUtil.runtimeJar.absolutePath))
|
||||
}
|
||||
// "-no-stdlib" implies "-no-reflect", see K2JVMCompiler.Companion.getClasspath
|
||||
if (addReflect && addStdlib) {
|
||||
compileClasspath.add(Path(getProject(), KotlinAntTaskUtil.reflectJar.absolutePath))
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkAntVersion() {
|
||||
|
||||
Reference in New Issue
Block a user