~~ [JPS] Prevent parent ClassLoader services from loading
diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/CompilerRunnerUtil.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/CompilerRunnerUtil.kt
index c9b40c8..0ca4d3f 100644
--- a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/CompilerRunnerUtil.kt
+++ b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/CompilerRunnerUtil.kt
@@ -69,7 +69,7 @@
)
ourClassLoaderRef = SoftReference(classLoader)
}
- return classLoader!!
+ return JpsPluginClassLoader(classLoader!!)
}
fun getLibPath(paths: KotlinPaths, messageCollector: MessageCollector): File? {
diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsPluginClassLoader.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsPluginClassLoader.kt
new file mode 100644
index 0000000..81267eb
--- /dev/null
+++ b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsPluginClassLoader.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
+ */
+
+package org.jetbrains.kotlin.compilerRunner
+
+import java.net.URL
+import java.util.*
+
+/**
+ ClassLoader that prevents a [ServiceLoader] from loading services available in parent [ClassLoader]s.
+ */
+class JpsPluginClassLoader(parent: ClassLoader) : ClassLoader(parent) {
+ private companion object {
+ private const val SERVICE_DIRECTORY_LOCATION = "META-INF/services/"
+ }
+
+ override fun getResource(name: String): URL? {
+ if (name.startsWith(SERVICE_DIRECTORY_LOCATION)) {
+ return findResource(name)
+ }
+
+ return super.getResource(name)
+ }
+
+ override fun getResources(name: String): Enumeration<URL> {
+ if (name.startsWith(SERVICE_DIRECTORY_LOCATION)) {
+ return findResources(name)
+ }
+
+ return super.getResources(name)
+ }
+}
\ No newline at end of file