summaryrefslogtreecommitdiff
path: root/contrib/playlib/worker/2.6.0/src/RouteCompilerWorker.scala
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/playlib/worker/2.6.0/src/RouteCompilerWorker.scala')
-rw-r--r--contrib/playlib/worker/2.6.0/src/RouteCompilerWorker.scala58
1 files changed, 58 insertions, 0 deletions
diff --git a/contrib/playlib/worker/2.6.0/src/RouteCompilerWorker.scala b/contrib/playlib/worker/2.6.0/src/RouteCompilerWorker.scala
new file mode 100644
index 00000000..f46f8c7b
--- /dev/null
+++ b/contrib/playlib/worker/2.6.0/src/RouteCompilerWorker.scala
@@ -0,0 +1,58 @@
+package mill
+package playlib
+package worker
+
+import java.io.File
+
+import ammonite.ops.Path
+import mill.api.Result
+import mill.eval.PathRef
+import mill.playlib.api.{RouteCompilerType, RouteCompilerWorkerApi}
+import mill.scalalib.api.CompilationResult
+import play.routes.compiler.RoutesCompiler.RoutesCompilerTask
+import play.routes.compiler.{InjectedRoutesGenerator, RoutesCompiler, StaticRoutesGenerator}
+
+
+class RouteCompilerWorker extends RouteCompilerWorkerApi {
+
+ override def compile(
+ file: Path,
+ additionalImports: Seq[String],
+ forwardsRouter: Boolean,
+ reverseRouter: Boolean,
+ namespaceReverseRouter: Boolean,
+ generatorType: RouteCompilerType,
+ dest: Path)
+ (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult] = {
+ val routesGenerator = generatorType match {
+ case RouteCompilerType.InjectedGenerator => InjectedRoutesGenerator
+ case RouteCompilerType.StaticGenerator =>
+ ctx.log.error("Static generator was deprecated in 2.6.0 and will be removed in 2.7.0")
+ StaticRoutesGenerator
+ case _ => throw new Exception(s"Unrecognized generator type: $generatorType. Use injected or static")
+ }
+ ctx.log.debug(s"compiling file $file with generator $generatorType")
+ val result =
+ RoutesCompiler.compile(
+ RoutesCompilerTask(file.toIO, additionalImports, forwardsRouter, reverseRouter,
+ namespaceReverseRouter),
+ generator = routesGenerator,
+ generatedDir = dest.toIO
+ )
+ ctx.log.debug("compilation result:" + result)
+ result match {
+ case Right(_) =>
+ val zincFile = ctx.dest / 'zinc
+ Result.Success(CompilationResult(zincFile, PathRef(ctx.dest)))
+ case Left(errors) =>
+ val errorMsg = errors.map(error =>
+ s"compilation error in ${error.source.getPath} at line ${error.line.getOrElse("?")}," +
+ s" column ${error.column.getOrElse("?")}: ${error.message}".stripMargin)
+ .mkString("\n")
+ Result.Failure("Unable to compile play routes, " + errorMsg)
+ }
+ }
+}
+
+
+case class RoutesCompilationError(source: File, message: String, line: Option[Int], column: Option[Int]) \ No newline at end of file