Fix compiler classpath discovery:
* Fix accidental filtering out the stdlib and reflect * Fix module search in classpath: use moduleId instead of k-c-embeddable
This commit is contained in:
+1
-1
@@ -65,7 +65,7 @@ abstract class AbstractKotlinCompileTool<T : CommonToolArguments>() : AbstractCo
|
|||||||
get() = compilerClasspath?.takeIf { it.isNotEmpty() }
|
get() = compilerClasspath?.takeIf { it.isNotEmpty() }
|
||||||
?: compilerJarFile?.let {
|
?: compilerJarFile?.let {
|
||||||
// a hack to remove compiler jar from the cp, will be dropped when compilerJarFile will be removed
|
// a hack to remove compiler jar from the cp, will be dropped when compilerJarFile will be removed
|
||||||
listOf(it) + findKotlinCompilerClasspath(project).filter { it.name.startsWith("kotlin-compiler") }
|
listOf(it) + findKotlinCompilerClasspath(project).filter { !it.name.startsWith("kotlin-compiler") }
|
||||||
}
|
}
|
||||||
?: findKotlinCompilerClasspath(project).takeIf { it.isNotEmpty() }
|
?: findKotlinCompilerClasspath(project).takeIf { it.isNotEmpty() }
|
||||||
?: throw IllegalStateException("Could not find Kotlin Compiler classpath. Please specify $name.compilerClasspath")
|
?: throw IllegalStateException("Could not find Kotlin Compiler classpath. Please specify $name.compilerClasspath")
|
||||||
|
|||||||
+3
-3
@@ -91,7 +91,7 @@ private fun findJarByClass(klass: Class<*>): File? {
|
|||||||
private fun findKotlinModuleJar(project: Project, expectedClassName: String, moduleId: String): List<File> {
|
private fun findKotlinModuleJar(project: Project, expectedClassName: String, moduleId: String): List<File> {
|
||||||
val pluginVersion = pluginVersionFromAppliedPlugin(project)
|
val pluginVersion = pluginVersionFromAppliedPlugin(project)
|
||||||
|
|
||||||
val filesToCheck = sequenceOf(pluginVersion?.let(::getCompilerFromClassLoader)) +
|
val filesToCheck = sequenceOf(pluginVersion?.let { version -> getModuleFromClassLoader(moduleId, version) }) +
|
||||||
Sequence { findPotentialModuleJars(project, moduleId).iterator() } //call the body only when queried
|
Sequence { findPotentialModuleJars(project, moduleId).iterator() } //call the body only when queried
|
||||||
val entryToFind = expectedClassName.replace(".", "/") + ".class"
|
val entryToFind = expectedClassName.replace(".", "/") + ".class"
|
||||||
return filesToCheck.filterNotNull().firstOrNull { it.hasEntry(entryToFind) }?.let { listOf(it) } ?: emptyList()
|
return filesToCheck.filterNotNull().firstOrNull { it.hasEntry(entryToFind) }?.let { listOf(it) } ?: emptyList()
|
||||||
@@ -100,10 +100,10 @@ private fun findKotlinModuleJar(project: Project, expectedClassName: String, mod
|
|||||||
private fun pluginVersionFromAppliedPlugin(project: Project): String? =
|
private fun pluginVersionFromAppliedPlugin(project: Project): String? =
|
||||||
project.plugins.filterIsInstance<KotlinBasePluginWrapper>().firstOrNull()?.kotlinPluginVersion
|
project.plugins.filterIsInstance<KotlinBasePluginWrapper>().firstOrNull()?.kotlinPluginVersion
|
||||||
|
|
||||||
private fun getCompilerFromClassLoader(pluginVersion: String): File? {
|
private fun getModuleFromClassLoader(moduleId: String, moduleVersion: String): File? {
|
||||||
val urlClassLoader = KotlinPlugin::class.java.classLoader as? URLClassLoader ?: return null
|
val urlClassLoader = KotlinPlugin::class.java.classLoader as? URLClassLoader ?: return null
|
||||||
return urlClassLoader.urLs
|
return urlClassLoader.urLs
|
||||||
.firstOrNull { it.toString().endsWith("kotlin-compiler-embeddable-$pluginVersion.jar") }
|
.firstOrNull { it.toString().endsWith("$moduleId-$moduleVersion.jar") }
|
||||||
?.let { File(it.toURI()) }
|
?.let { File(it.toURI()) }
|
||||||
?.takeIf(File::exists)
|
?.takeIf(File::exists)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user