@@ -34,13 +34,11 @@ class UnshadingClassLoader(parent: ClassLoader) extends ClassLoader(parent) {
3434 if (loaded != null ) return loaded
3535
3636 try {
37- // Load the shaded class bytes from parent
3837 val is = getParent.getResourceAsStream((SHADED_PREFIX + name).replace('.' , '/' ) + " .class" )
3938
4039 if (is != null ) {
4140 try {
4241 val bytes = is.readAllBytes()
43- // Define the class with the unshaded name
4442 val clazz = defineClass(name, bytes, 0 , bytes.length)
4543 if (resolve) resolveClass(clazz)
4644 return clazz
@@ -64,27 +62,25 @@ class UnshadingClassLoader(parent: ClassLoader) extends ClassLoader(parent) {
6462 */
6563object EmbeddedReplMain {
6664 def main (args : Array [String ]): Unit = {
67- val argsWithClasspath = if (args.exists(arg => arg == " -classpath" || arg == " -cp" )) {
68- args // Already has classpath
69- } else {
70- Array (" -classpath" , System .getProperty(" java.class.path" )) ++ args
71- }
65+ val argsWithClasspath =
66+ if (args.exists(arg => arg == " -classpath" || arg == " -cp" )) args
67+ else Array (" -classpath" , System .getProperty(" java.class.path" )) ++ args
7268
73- // Create the unshading classloader with the current classloader as parent
74- // This ensures it has access to all dependencies in the shaded jar
7569 val unshadingClassLoader = new UnshadingClassLoader (getClass.getClassLoader)
70+ try {
7671
77- val replDriverClass = unshadingClassLoader.loadClass(" dotty.tools.repl.ReplDriver" )
78- val constructor = replDriverClass.getConstructors().head
72+ val replDriverClass = unshadingClassLoader.loadClass(" dotty.tools.repl.ReplDriver" )
73+ val constructor = replDriverClass.getConstructors().head
7974
80- // Create the ReplDriver instance with classpath argument
81- val replDriver = constructor.newInstance(
82- argsWithClasspath, // settings: Array[String] (now includes -classpath)
83- System .out, // out: PrintStream
84- Option (getClass.getClassLoader), // classLoader: Option[ClassLoader]
85- " " // extraPredef: String
86- )
75+ // Create the ReplDriver instance with classpath argument
76+ val replDriver = constructor.newInstance(
77+ argsWithClasspath, // settings: Array[String] (now includes -classpath)
78+ System .out, // out: PrintStream
79+ Option (getClass.getClassLoader), // classLoader: Option[ClassLoader]
80+ " " // extraPredef: String
81+ )
8782
88- replDriverClass.getMethod(" tryRunning" ).invoke(replDriver)
83+ replDriverClass.getMethod(" tryRunning" ).invoke(replDriver)
84+ }finally unshadingClassLoader.close
8985 }
9086}
0 commit comments