Skip to content

Commit

Permalink
use scala library from mill to avoid awkward reflective calls for cla…
Browse files Browse the repository at this point in the history
…sses from scala library
  • Loading branch information
rockjam committed Apr 30, 2018
1 parent 0daf9ca commit dc546f6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions twirllib/src/mill/twirllib/TwirlWorker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ class TwirlWorker {
twirlInstanceCache match {
case Some((sig, instance)) if sig == classloaderSig => instance
case _ =>
val cl = new URLClassLoader(twirlClasspath.map(_.toIO.toURI.toURL).toArray)
val cpWithoutScalaLib = twirlClasspath.filter { p =>
!p.toString.contains("scala-library")
}.map(_.toIO.toURI.toURL).toArray
val cl = new URLClassLoader(cpWithoutScalaLib, getClass.getClassLoader)
val twirlCompilerClass = cl.loadClass("play.twirl.compiler.TwirlCompiler")
// Use the Java API (available in Twirl 1.3+)
// Using reflection on a method with "Seq[String] = Nil" parameter type does not seem to work.

// REMIND: Unable to call the compile method with a primitive boolean
// codec and inclusiveDot will not be available
val compileMethod = twirlCompilerClass.getMethod("compile",
classOf[java.io.File],
classOf[java.io.File],
Expand Down Expand Up @@ -56,10 +55,10 @@ class TwirlWorker {
sourceDirectory,
generatedDirectory,
formatterType,
defaultAdditionalImportsMethod.invoke(null),
defaultConstructorAnnotationsMethod.invoke(null),
defaultCodecMethod.invoke(null),
defaultFlagMethod.invoke(null)
additionalImports,
constructorAnnotations,
Codec("UTF-8"), // may provide as parameter too.
scala.Boolean.box(false)
)
}
}
Expand Down

0 comments on commit dc546f6

Please sign in to comment.