@@ -20,7 +20,9 @@ import java.io.File
2020import java.io.OutputStream
2121import java.io.PrintStream
2222import java.net.URI
23+ import java.net.URL
2324import java.nio.file.Files
25+ import java.nio.file.Path
2426import java.nio.file.Paths
2527
2628/* *
@@ -239,23 +241,26 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
239241 }
240242
241243 protected fun getResourcesPath (): String {
242- val resourceName = " META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"
243244 return this ::class .java.classLoader.getResources(resourceName)
244245 .asSequence()
245- .mapNotNull { url ->
246- val uri = URI .create(url.toString().removeSuffix(" /$resourceName " ))
247- when (uri.scheme) {
248- " jar" -> Paths .get(URI .create(uri.schemeSpecificPart.removeSuffix(" !" )))
249- " file" -> Paths .get(uri)
250- else -> return @mapNotNull null
251- }.toAbsolutePath()
252- }
246+ .mapNotNull { url -> urlToResourcePath(url) }
253247 .find { resourcesPath ->
254248 ServiceLoaderLite .findImplementations(ComponentRegistrar ::class .java, listOf (resourcesPath.toFile()))
255249 .any { implementation -> implementation == MainComponentRegistrar ::class .java.name }
256250 }?.toString() ? : throw AssertionError (" Could not get path to ComponentRegistrar service from META-INF" )
257251 }
258252
253+ /* * Maps a URL resource for a class from a JAR or file to an absolute Path on disk */
254+ internal fun urlToResourcePath (url : URL ): Path ? {
255+ val uri = url.toURI()
256+ val uriPath = when (uri.scheme) {
257+ " jar" -> uri.rawSchemeSpecificPart.removeSuffix(" !/$resourceName " )
258+ " file" -> uri.toString().removeSuffix(" /$resourceName " )
259+ else -> return null
260+ }
261+ return Paths .get(URI .create(uriPath)).toAbsolutePath()
262+ }
263+
259264 /* * Searches compiler log for known errors that are hard to debug for the user */
260265 protected fun searchSystemOutForKnownErrors (compilerSystemOut : String ) {
261266 if (compilerSystemOut.contains(" No enum constant com.sun.tools.javac.main.Option.BOOT_CLASS_PATH" )) {
@@ -306,6 +311,8 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
306311 protected fun error (s : String ) = internalMessageStream.println (" error: $s " )
307312
308313 internal val internalMessageStreamAccess: PrintStream get() = internalMessageStream
314+
315+ private val resourceName = " META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"
309316}
310317
311318@ExperimentalCompilerApi
0 commit comments