@@ -21,6 +21,7 @@ import java.io.File
21
21
import java.io.OutputStream
22
22
import java.io.PrintStream
23
23
import java.net.URI
24
+ import java.net.URL
24
25
import java.nio.file.Files
25
26
import java.nio.file.Path
26
27
import java.nio.file.Paths
@@ -62,8 +63,6 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
62
63
)
63
64
var compilerPlugins: List <ComponentRegistrar > = emptyList()
64
65
65
-
66
-
67
66
/* *
68
67
* Legacy compiler plugins that should be added to the compilation.
69
68
* This option will be removed in the future; you should migrate to [CompilerPluginRegistrar].
@@ -273,23 +272,26 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
273
272
}
274
273
275
274
protected fun getResourcesPath (): String {
276
- val resourceName = " META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar"
277
275
return this ::class .java.classLoader.getResources(resourceName)
278
276
.asSequence()
279
- .mapNotNull { url ->
280
- val uri = URI .create(url.toString().removeSuffix(" /$resourceName " ))
281
- when (uri.scheme) {
282
- " jar" -> Paths .get(URI .create(uri.rawSchemeSpecificPart.removeSuffix(" !" )))
283
- " file" -> Paths .get(uri)
284
- else -> return @mapNotNull null
285
- }.toAbsolutePath()
286
- }
277
+ .mapNotNull { url -> urlToResourcePath(url) }
287
278
.find { resourcesPath ->
288
279
ServiceLoaderLite .findImplementations(CompilerPluginRegistrar ::class .java, listOf (resourcesPath.toFile()))
289
280
.any { implementation -> implementation == MainComponentAndPluginRegistrar ::class .java.name }
290
281
}?.toString() ? : throw AssertionError (" Could not get path to CompilerPluginRegistrar service from META-INF" )
291
282
}
292
283
284
+ /* * Maps a URL resource for a class from a JAR or file to an absolute Path on disk */
285
+ internal fun urlToResourcePath (url : URL ): Path ? {
286
+ val uri = url.toURI()
287
+ val uriPath = when (uri.scheme) {
288
+ " jar" -> uri.rawSchemeSpecificPart.removeSuffix(" !/$resourceName " )
289
+ " file" -> uri.toString().removeSuffix(" /$resourceName " )
290
+ else -> return null
291
+ }
292
+ return Paths .get(URI .create(uriPath)).toAbsolutePath()
293
+ }
294
+
293
295
/* * Searches compiler log for known errors that are hard to debug for the user */
294
296
protected fun searchSystemOutForKnownErrors (compilerSystemOut : String ) {
295
297
if (compilerSystemOut.contains(" No enum constant com.sun.tools.javac.main.Option.BOOT_CLASS_PATH" )) {
@@ -340,8 +342,11 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
340
342
protected fun error (s : String ) = internalMessageStream.println (" error: $s " )
341
343
342
344
internal val internalMessageStreamAccess: PrintStream get() = internalMessageStream
345
+
346
+ internal val resourceName = " META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar"
343
347
}
344
348
349
+ @ExperimentalCompilerApi
345
350
internal fun convertKotlinExitCode (code : ExitCode ) = when (code) {
346
351
ExitCode .OK -> KotlinCompilation .ExitCode .OK
347
352
ExitCode .INTERNAL_ERROR -> KotlinCompilation .ExitCode .INTERNAL_ERROR
0 commit comments