Skip to content

Commit 4bbfe06

Browse files
committed
drop the dotty.tools.runner package in the compiler
1 parent 5e99614 commit 4bbfe06

File tree

6 files changed

+36
-133
lines changed

6 files changed

+36
-133
lines changed

compiler/src/dotty/tools/MainGenericCompiler.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import java.io.File
77
import java.lang.Thread
88
import scala.annotation.internal.sharable
99
import dotty.tools.dotc.util.ClasspathFromClassloader
10-
import dotty.tools.runner.ObjectRunner
1110
import dotty.tools.dotc.config.Properties.envOrNone
1211
import dotty.tools.io.Jar
13-
import dotty.tools.runner.ScalaClassLoader
1412
import java.nio.file.Paths
1513
import dotty.tools.dotc.config.CommandLineParser
1614
import dotty.tools.scripting.StringDriver

compiler/src/dotty/tools/runner/ObjectRunner.scala

Lines changed: 0 additions & 48 deletions
This file was deleted.

compiler/src/dotty/tools/runner/ScalaClassLoader.scala

Lines changed: 0 additions & 81 deletions
This file was deleted.

repl/src/dotty/tools/repl/DependencyResolver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ object DependencyResolver:
9191
import dotty.tools.dotc.core.SymbolLoaders
9292
import dotty.tools.dotc.core.Symbols.defn
9393
import dotty.tools.io.*
94-
import dotty.tools.runner.ScalaClassLoader.fromURLsParallelCapable
94+
import dotty.tools.repl.ScalaClassLoader.fromURLsParallelCapable
9595

9696
// Create a classloader with all the resolved JAR files
9797
val urls = files.map(_.toURI.toURL).toArray

repl/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import dotc.util.{SourceFile, SourcePosition}
3434
import dotc.{CompilationUnit, Driver}
3535
import dotc.config.CompilerCommand
3636
import dotty.tools.io.{AbstractFileClassLoader => _, *}
37-
import dotty.tools.runner.ScalaClassLoader.*
37+
import dotty.tools.repl.ScalaClassLoader.*
3838

3939
import org.jline.reader.*
4040

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dotty.tools.repl
2+
3+
import java.lang.ClassLoader
4+
import java.lang.invoke.{MethodHandles, MethodType}
5+
import java.lang.reflect.Modifier
6+
import java.net.{ URL, URLClassLoader }
7+
import java.lang.reflect.{ InvocationTargetException, UndeclaredThrowableException }
8+
9+
import scala.annotation.internal.sharable
10+
import scala.annotation.tailrec
11+
import scala.util.control.Exception.catching
12+
13+
object ScalaClassLoader {
14+
def setContext(cl: ClassLoader) = Thread.currentThread.setContextClassLoader(cl)
15+
16+
def fromURLsParallelCapable(urls: Seq[URL], parent: ClassLoader | Null = null): URLClassLoader =
17+
new URLClassLoader(urls.toArray, if parent == null then bootClassLoader else parent)
18+
19+
@sharable private val bootClassLoader: ClassLoader | Null =
20+
if scala.util.Properties.isJavaAtLeast("9") then
21+
try
22+
ClassLoader.getSystemClassLoader.getParent
23+
catch case _: Throwable => null
24+
else null
25+
26+
extension (classLoader: ClassLoader)
27+
/** Execute an action with this classloader as context classloader. */
28+
def asContext[T](action: => T): T =
29+
val saved = Thread.currentThread.getContextClassLoader
30+
try
31+
setContext(classLoader)
32+
action
33+
finally setContext(saved)
34+
}

0 commit comments

Comments
 (0)