in project/ReflectiveCodeGen.scala [98:147]
def loadAndSetGenerator(
classpath: Classpath,
languages0: Seq[String],
sources0: Seq[String],
extraGenerators0: Seq[String],
targetPath: File,
generatorSettings: Seq[String],
targets: ListBuffer[Target],
scalaBinaryVersion: String): Unit = {
val languages = languages0.mkString(", ")
val sources = sources0.mkString(", ")
val extraGenerators = extraGenerators0.mkString(", ")
val generatorSettings1 = generatorSettings.mkString("\"", "\", \"", "\"")
val cp = classpath.map(_.data)
// ensure to set right parent classloader, so that protocbridge.ProtocCodeGenerator etc are
// compatible with what is already accessible from this sbt build
val loader = ClasspathUtil.toLoader(cp, classOf[protocbridge.ProtocCodeGenerator].getClassLoader)
import scala.reflect.runtime.universe
import scala.tools.reflect.ToolBox
val tb = universe.runtimeMirror(loader).mkToolBox()
val source =
s"""import org.apache.pekko.grpc.sbt.PekkoGrpcPlugin
|import org.apache.pekko.grpc.sbt.GeneratorBridge
|import PekkoGrpcPlugin.autoImport._
|import PekkoGrpc._
|import org.apache.pekko.grpc.gen.scaladsl._
|import org.apache.pekko.grpc.gen.javadsl._
|import org.apache.pekko.grpc.gen.CodeGenerator.ScalaBinaryVersion
|
|val languages: Seq[PekkoGrpc.Language] = Seq($languages)
|val sources: Seq[PekkoGrpc.GeneratedSource] = Seq($sources)
|val scalaBinaryVersion = ScalaBinaryVersion("$scalaBinaryVersion")
|
|val logger = org.apache.pekko.grpc.gen.StdoutLogger
|
|(targetPath: java.io.File, settings: Seq[String]) => {
| val generators =
| PekkoGrpcPlugin.generatorsFor(sources, languages, scalaBinaryVersion, logger) ++
| Seq($extraGenerators).map(gen => GeneratorBridge.sandboxedGenerator(gen, scalaBinaryVersion, org.apache.pekko.grpc.gen.StdoutLogger))
| PekkoGrpcPlugin.targetsFor(targetPath, settings, generators)
|}
""".stripMargin
val generatorsF = tb.eval(tb.parse(source)).asInstanceOf[(File, Seq[String]) => Seq[Target]]
val generators = generatorsF(targetPath, generatorSettings)
targets.clear()
targets ++= generators.asInstanceOf[Seq[Target]]
}