Remove hacky PluginURLClassLoader

It was once needed for the compiler plugins bundled straight into the compiler (read: kapt1). Since there are no bundled plugins anymore, the parent-last plugin classloader itself is not needed anymore.
This commit is contained in:
Yan Zhulanow
2018-10-29 09:27:43 +09:00
parent 02340a4fe3
commit b6aecf3933
3 changed files with 3 additions and 53 deletions
+1
View File
@@ -3,6 +3,7 @@
<words>
<w>debuggee</w>
<w>deserializes</w>
<w>hacky</w>
<w>impls</w>
<w>kapt</w>
<w>parceler</w>
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil
import org.jetbrains.kotlin.compiler.plugin.*
import org.jetbrains.kotlin.config.CompilerConfiguration
import java.io.File
import java.net.URLClassLoader
import java.util.*
object PluginCliParser {
@@ -58,7 +59,7 @@ object PluginCliParser {
@JvmStatic
fun loadPlugins(pluginClasspaths: Iterable<String>?, pluginOptions: Iterable<String>?, configuration: CompilerConfiguration) {
val classLoader = PluginURLClassLoader(
val classLoader = URLClassLoader(
pluginClasspaths
?.map { File(it).toURI().toURL() }
?.toTypedArray()
@@ -1,52 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.cli.jvm.plugins
import java.net.URL
import java.net.URLClassLoader
import java.util.*
internal class PluginURLClassLoader(urls: Array<URL>, parent: ClassLoader) : ClassLoader(Thread.currentThread().contextClassLoader) {
private val childClassLoader: SelfThenParentURLClassLoader = SelfThenParentURLClassLoader(urls, parent)
@Synchronized
override fun loadClass(name: String, resolve: Boolean): Class<*> {
return try {
childClassLoader.findClass(name)
} catch (e: ClassNotFoundException) {
super.loadClass(name, resolve)
}
}
override fun getResources(name: String): Enumeration<URL> = childClassLoader.getResources(name)
private class SelfThenParentURLClassLoader(urls: Array<URL>, private val onFail: ClassLoader) : URLClassLoader(urls, null) {
public override fun findClass(name: String): Class<*> {
val loaded = findLoadedClass(name)
if (loaded != null) {
return loaded
}
return try {
super.findClass(name)
} catch (e: ClassNotFoundException) {
onFail.loadClass(name)
}
}
}
}