Implement diagnostics for ignored compiler arguments on script compilation

This commit is contained in:
Ilya Chernikov
2019-01-23 16:33:30 +01:00
parent 7ee9801c5f
commit 95d782b6ca
4 changed files with 127 additions and 24 deletions
@@ -71,25 +71,26 @@ private fun splitJarUrl(url: String): Pair<String, String>? {
return Pair(jarPath, resourcePath)
}
fun getResourcePathForClass(aClass: Class<*>): File {
fun tryGetResourcePathForClass(aClass: Class<*>): File? {
val path = "/" + aClass.name.replace('.', '/') + ".class"
val resourceRoot = getResourceRoot(aClass, path) ?: throw IllegalStateException("Resource not found: $path")
return File(resourceRoot).absoluteFile
}
fun tryGetResourcePathForClassByName(name: String, classLoader: ClassLoader): File? = try {
classLoader.loadClass(name)?.let {
val path = "/" + name.replace('.', '/') + ".class"
getResourceRoot(it, path)
}?.let {
return getResourceRoot(aClass, path)?.let {
File(it).absoluteFile
}
} catch (_: ClassNotFoundException) {
null
} catch (_: NoClassDefFoundError) {
null
}
fun getResourcePathForClass(aClass: Class<*>): File {
return tryGetResourcePathForClass(aClass) ?: throw IllegalStateException("Resource for class: ${aClass.name} not found")
}
fun tryGetResourcePathForClassByName(name: String, classLoader: ClassLoader): File? =
try {
classLoader.loadClass(name)?.let(::tryGetResourcePathForClass)
} catch (_: ClassNotFoundException) {
null
} catch (_: NoClassDefFoundError) {
null
}
internal fun URL.toFile() =
try {
File(toURI().schemeSpecificPart)
@@ -187,14 +187,16 @@ object KotlinJars {
}
fun getLib(propertyName: String, jarName: String, markerClass: KClass<*>): File? =
System.getProperty(propertyName)?.let(::File)?.takeIf(File::exists)
?: explicitCompilerClasspath?.firstOrNull { it.matchMaybeVersionedFile(jarName) }?.takeIf(File::exists)
getExplicitLib(propertyName, jarName)
?: getResourcePathForClass(markerClass.java).takeIf(File::exists)
fun getLib(propertyName: String, jarName: String, markerClassName: String): File? =
getExplicitLib(propertyName, jarName)
?: tryGetResourcePathForClassByName(markerClassName, Thread.currentThread().contextClassLoader)?.takeIf(File::exists)
private fun getExplicitLib(propertyName: String, jarName: String) =
System.getProperty(propertyName)?.let(::File)?.takeIf(File::exists)
?: explicitCompilerClasspath?.firstOrNull { it.matchMaybeVersionedFile(jarName) }?.takeIf(File::exists)
?: tryGetResourcePathForClassByName(markerClassName, Thread.currentThread().contextClassLoader)?.takeIf(File::exists)
val stdlibOrNull: File? by lazy {
System.getProperty(KOTLIN_STDLIB_JAR_PROPERTY)?.let(::File)?.takeIf(File::exists)
@@ -214,7 +216,7 @@ object KotlinJars {
getLib(
KOTLIN_REFLECT_JAR_PROPERTY,
KOTLIN_JAVA_REFLECT_JAR,
"kotlin.reflect.full.IllegalCallableAccessException"
"kotlin.reflect.full.KClasses" // using a class that is a part of the kotlin-reflect.jar
)
}