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:
Sergey Igushkin
2017-10-02 17:47:23 +03:00
parent a2df5c38dd
commit df99c4fe28
2 changed files with 4 additions and 4 deletions
@@ -65,7 +65,7 @@ abstract class AbstractKotlinCompileTool<T : CommonToolArguments>() : AbstractCo
get() = compilerClasspath?.takeIf { it.isNotEmpty() }
?: compilerJarFile?.let {
// 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() }
?: throw IllegalStateException("Could not find Kotlin Compiler classpath. Please specify $name.compilerClasspath")
@@ -91,7 +91,7 @@ private fun findJarByClass(klass: Class<*>): File? {
private fun findKotlinModuleJar(project: Project, expectedClassName: String, moduleId: String): List<File> {
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
val entryToFind = expectedClassName.replace(".", "/") + ".class"
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? =
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
return urlClassLoader.urLs
.firstOrNull { it.toString().endsWith("kotlin-compiler-embeddable-$pluginVersion.jar") }
.firstOrNull { it.toString().endsWith("$moduleId-$moduleVersion.jar") }
?.let { File(it.toURI()) }
?.takeIf(File::exists)
}