@@ -11,7 +11,11 @@ import scala.quoted.{Expr, Type}
1111import scala .quoted .Toolbox
1212import java .net .URLClassLoader
1313
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 {
1519 import tpd ._
1620
1721 private [this ] val contextBase : ContextBase = new ContextBase
@@ -32,7 +36,9 @@ class QuoteDriver extends Driver {
3236 val driver = new QuoteCompiler
3337 driver.newRun(ctx).compileExpr(expr)
3438
35- val classLoader = new AbstractFileClassLoader (outDir, this .getClass.getClassLoader)
39+ assert(! ctx.reporter.hasErrors)
40+
41+ val classLoader = new AbstractFileClassLoader (outDir, appClassloader)
3642
3743 val clazz = classLoader.loadClass(driver.outputClassName.toString)
3844 val method = clazz.getMethod(" apply" )
@@ -82,7 +88,7 @@ class QuoteDriver extends Driver {
8288
8389 override def initCtx : Context = {
8490 val ictx = contextBase.initialCtx
85- ictx.settings.classpath.update(QuoteDriver .currentClasspath)(ictx)
91+ ictx.settings.classpath.update(QuoteDriver .currentClasspath(appClassloader) )(ictx)
8692 ictx
8793 }
8894
@@ -94,9 +100,9 @@ class QuoteDriver extends Driver {
94100
95101object QuoteDriver {
96102
97- def currentClasspath : String = {
103+ def currentClasspath ( cl : ClassLoader ) : String = {
98104 val classpath0 = System .getProperty(" java.class.path" )
99- this .getClass.getClassLoader match {
105+ cl match {
100106 case cl : URLClassLoader =>
101107 // Loads the classes loaded by this class loader
102108 // When executing `run` or `test` in sbt the classpath is not in the property java.class.path
0 commit comments