Skip to content

Commit 023b85c

Browse files
committed
Try shared class loader
1 parent 101ebf8 commit 023b85c

File tree

2 files changed

+15
-37
lines changed

2 files changed

+15
-37
lines changed

project/Build.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,7 @@ object Build {
337337
scalaLibrary,
338338
dottyLibrary,
339339
dottyCompiler,
340-
allJars,
341-
appConfiguration.value
340+
allJars
342341
)
343342
},
344343
// sbt-dotty defines `scalaInstance in doc` so we need to override it manually

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

+14-35
Original file line numberDiff line numberDiff line change
@@ -539,27 +539,30 @@ object DottyPlugin extends AutoPlugin {
539539
scalaLibraryJar,
540540
dottyLibraryJar,
541541
compilerJar,
542-
allJars,
543-
appConfiguration.value
542+
allJars
544543
)
545544
}
546545

547546
// Adapted from private mkScalaInstance in sbt
548547
def makeScalaInstance(
549-
state: State, dottyVersion: String, scalaLibrary: File, dottyLibrary: File, compiler: File, all: Seq[File], appConfiguration: AppConfiguration
548+
state: State, dottyVersion: String, scalaLibrary: File, dottyLibrary: File, compiler: File, all: Seq[File]
550549
): ScalaInstance = {
551550
/**
552551
* The compiler bridge must load the xsbti classes from the sbt
553552
* classloader, and similarly the Scala repl must load the sbt provided
554-
* jline terminal. To do so we add the `appConfiguration` loader in
555-
* the parent hierarchy of the scala 3 instance loader.
556-
*
557-
* The [[FilteringClassLoader]] ensures that the JNA, JDK and xsbti
558-
* classes only are loaded from the sbt loader. That is necessary because
559-
* the sbt class loader contains the Scala 2.12 library and compiler
560-
* bridge.
553+
* jline terminal.
561554
*/
562-
val topLoader = new FilteringClassLoader(appConfiguration.provider.loader)
555+
val topLoader = new ClassLoader(null) {
556+
val sharedPrefixes = List(
557+
"xsbti.",
558+
"org.jline."
559+
)
560+
561+
override def loadClass(name: String): Class[_] = {
562+
if (sharedPrefixes.exists(name.startsWith(_))) getClass.getClassLoader.loadClass(name)
563+
else super.loadClass(name)
564+
}
565+
}
563566

564567
val libraryJars = Array(dottyLibrary, scalaLibrary)
565568
val libraryLoader = state.classLoaderCache.cachedCustomClassloader(
@@ -583,27 +586,3 @@ object DottyPlugin extends AutoPlugin {
583586
None)
584587
}
585588
}
586-
587-
private class FilteringClassLoader(parent: ClassLoader) extends ClassLoader(parent) {
588-
private val prefixes = List(
589-
"xsbti.",
590-
"org.jline.",
591-
"java.",
592-
"sun.",
593-
"jdk.internal.reflect.",
594-
"javax."
595-
)
596-
597-
override def loadClass(name: String, resolve: Boolean): Class[_] = {
598-
if (prefixes.exists(name.startsWith(_))) super.loadClass(name, resolve)
599-
else null
600-
}
601-
602-
override def getResource(name: String): URL = {
603-
null
604-
}
605-
606-
override def getResources(name: String): Enumeration[URL] = {
607-
Collections.enumeration(Collections.emptyList());
608-
}
609-
}

0 commit comments

Comments
 (0)