@@ -11,7 +11,11 @@ import scala.quoted.{Expr, Type}
11
11
import scala .quoted .Toolbox
12
12
import java .net .URLClassLoader
13
13
14
- class QuoteDriver extends Driver {
14
+ /** Driver to compile quoted code
15
+ *
16
+ * @param appClassloader classloader of the application that generated the quotes
17
+ */
18
+ class QuoteDriver (appClassloader : ClassLoader ) extends Driver {
15
19
import tpd ._
16
20
17
21
private [this ] val contextBase : ContextBase = new ContextBase
@@ -32,7 +36,9 @@ class QuoteDriver extends Driver {
32
36
val driver = new QuoteCompiler
33
37
driver.newRun(ctx).compileExpr(expr)
34
38
35
- val classLoader = new AbstractFileClassLoader (outDir, this .getClass.getClassLoader)
39
+ assert(! ctx.reporter.hasErrors)
40
+
41
+ val classLoader = new AbstractFileClassLoader (outDir, appClassloader)
36
42
37
43
val clazz = classLoader.loadClass(driver.outputClassName.toString)
38
44
val method = clazz.getMethod(" apply" )
@@ -82,7 +88,7 @@ class QuoteDriver extends Driver {
82
88
83
89
override def initCtx : Context = {
84
90
val ictx = contextBase.initialCtx
85
- ictx.settings.classpath.update(QuoteDriver .currentClasspath)(ictx)
91
+ ictx.settings.classpath.update(QuoteDriver .currentClasspath(appClassloader) )(ictx)
86
92
ictx
87
93
}
88
94
@@ -94,9 +100,9 @@ class QuoteDriver extends Driver {
94
100
95
101
object QuoteDriver {
96
102
97
- def currentClasspath : String = {
103
+ def currentClasspath ( cl : ClassLoader ) : String = {
98
104
val classpath0 = System .getProperty(" java.class.path" )
99
- this .getClass.getClassLoader match {
105
+ cl match {
100
106
case cl : URLClassLoader =>
101
107
// Loads the classes loaded by this class loader
102
108
// When executing `run` or `test` in sbt the classpath is not in the property java.class.path
0 commit comments