8000 twirl that works with scala API · rockjam/mill@0daf9ca · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 0daf9ca

Browse files
committed
twirl that works with scala API
1 parent 0ea7902 commit 0daf9ca

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

twirllib/src/mill/twirllib/TwirlModule.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ trait TwirlModule extends mill.Module {
2323
MavenRepository("https://repo1.maven.org/maven2")
2424
),
2525
Lib.depToDependency(_, "2.12.4"),
26-
Seq(ivy"com.typesafe.play::twirl-compiler:${twirlVersion()}")
26+
Seq(
27+
ivy"com.typesafe.play::twirl-compiler:${twirlVersion()}",
28+
ivy"org.scala-lang.modules::scala-parser-combinators:1.0.5"
29+
)
2730
)
2831
}
2932

twirllib/src/mill/twirllib/TwirlWorker.scala

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TwirlWorker {
2323
case Some((sig, instance)) if sig == classloaderSig => instance
2424
case _ =>
2525
val cl = new URLClassLoader(twirlClasspath.map(_.toIO.toURI.toURL).toArray)
26-
val twirlCompilerClass = cl.loadClass("play.japi.twirl.compiler.TwirlCompiler")
26+
val twirlCompilerClass = cl.loadClass("play.twirl.compiler.TwirlCompiler")
2727
// Use the Java API (available in Twirl 1.3+)
2828
// Using reflection on a method with "Seq[String] = Nil" parameter type does not seem to work.
2929

@@ -34,8 +34,16 @@ class TwirlWorker {
3434
classOf[java.io.File],
3535
classOf[java.io.File],
3636
classOf[java.lang.String],
37-
classOf[util.Collection[java.lang.String]],
38-
classOf[util.List[java.lang.String]])
37+
cl.loadClass("scala.collection.Seq"),
38+
cl.loadClass("scala.collection.Seq"),
39+
cl.loadClass("scala.io.Codec"),
40+
classOf[Boolean]
41+
)
42+
43+
val defaultAdditionalImportsMethod = twirlCompilerClass.getMethod("compile$default$5")
44+
val defaultConstructorAnnotationsMethod = twirlCompilerClass.getMethod("compile$default$6")
45+
val defaultCodecMethod = twirlCompilerClass.getMethod("compile$default$7")
46+
val defaultFlagMethod = twirlCompilerClass.getMethod("compile$default$8")
3947

4048
val instance = new TwirlWorkerApi {
4149
override def compileTwirl(source: File,
@@ -48,8 +56,11 @@ class TwirlWorker {
4856
sourceDirectory,
4957
generatedDirectory,
5058
formatterType,
51-
additionalImports.asJava,
52-
constructorAnnotations.asJava)
59+
defaultAdditionalImportsMethod.invoke(null),
60+
defaultConstructorAnnotationsMethod.invoke(null),
61+
defaultCodecMethod.invoke(null),
62+
defaultFlagMethod.invoke(null)
63+
)
5364
}
5465
}
5566
twirlInstanceCache = Some((classloaderSig, instance))

0 commit comments

Comments
 (0)
0