@@ -20,7 +20,9 @@ import java.io.File
20
20
import java.io.OutputStream
21
21
import java.io.PrintStream
22
22
import java.net.URI
23
+ import java.net.URL
23
24
import java.nio.file.Files
25
+ import java.nio.file.Path
24
26
import java.nio.file.Paths
25
27
26
28
/* *
@@ -239,23 +241,26 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
239
241
}
240
242
241
243
protected fun getResourcesPath (): String {
242
- val resourceName = " META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"
243
244
return this ::class .java.classLoader.getResources(resourceName)
244
245
.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) }
253
247
.find { resourcesPath ->
254
248
ServiceLoaderLite .findImplementations(ComponentRegistrar ::class .java, listOf (resourcesPath.toFile()))
255
249
.any { implementation -> implementation == MainComponentRegistrar ::class .java.name }
256
250
}?.toString() ? : throw AssertionError (" Could not get path to ComponentRegistrar service from META-INF" )
257
251
}
258
252
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
+
259
264
/* * Searches compiler log for known errors that are hard to debug for the user */
260
265
protected fun searchSystemOutForKnownErrors (compilerSystemOut : String ) {
261
266
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
306
311
protected fun error (s : String ) = internalMessageStream.println (" error: $s " )
307
312
308
313
internal val internalMessageStreamAccess: PrintStream get() = internalMessageStream
314
+
315
+ private val resourceName = " META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"
309
316
}
310
317
311
318
@ExperimentalCompilerApi
0 commit comments