diff options
author | Jean Helou <jhe@codamens.fr> | 2019-02-13 23:29:33 +0100 |
---|---|---|
committer | Tobias Roeser <le.petit.fou@web.de> | 2019-02-14 17:45:16 +0100 |
commit | 316fab29c7a87e89fa253fd09504b8b54b66911e (patch) | |
tree | 75236af55f55858320e0ad075485ea99ee9dcfec /contrib/playlib/worker/2.7.0/src/RouteCompilerWorker.scala | |
parent | 1afcfcafe0ed45aeae52f41768797bb6ab39a4d0 (diff) | |
download | mill-316fab29c7a87e89fa253fd09504b8b54b66911e.tar.gz mill-316fab29c7a87e89fa253fd09504b8b54b66911e.tar.bz2 mill-316fab29c7a87e89fa253fd09504b8b54b66911e.zip |
switch to T.sources for the routesFiles setting
Diffstat (limited to 'contrib/playlib/worker/2.7.0/src/RouteCompilerWorker.scala')
-rw-r--r-- | contrib/playlib/worker/2.7.0/src/RouteCompilerWorker.scala | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/contrib/playlib/worker/2.7.0/src/RouteCompilerWorker.scala b/contrib/playlib/worker/2.7.0/src/RouteCompilerWorker.scala index 99e2b493..616ab943 100644 --- a/contrib/playlib/worker/2.7.0/src/RouteCompilerWorker.scala +++ b/contrib/playlib/worker/2.7.0/src/RouteCompilerWorker.scala @@ -9,13 +9,14 @@ import mill.api.{Ctx, Result} import mill.eval.PathRef import mill.playlib.api.{RouteCompilerType, RouteCompilerWorkerApi} import mill.scalalib.api.CompilationResult +import play.routes.compiler import play.routes.compiler.RoutesCompiler.RoutesCompilerTask import play.routes.compiler.{InjectedRoutesGenerator, RoutesCompilationError, RoutesCompiler, RoutesGenerator} class RouteCompilerWorker extends RouteCompilerWorkerApi { - override def compile(file: Path, + override def compile(files: Seq[Path], additionalImports: Seq[String], forwardsRouter: Boolean, reverseRouter: Boolean, @@ -25,7 +26,7 @@ class RouteCompilerWorker extends RouteCompilerWorkerApi { (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult] = { generatorType match { case RouteCompilerType.InjectedGenerator => - val result = compileWithPlay(file, additionalImports, forwardsRouter, reverseRouter, + val result = compileWithPlay(files, additionalImports, forwardsRouter, reverseRouter, namespaceReverseRouter, dest, ctx, InjectedRoutesGenerator) asMillResult(ctx, result) case RouteCompilerType.StaticGenerator => @@ -36,6 +37,23 @@ class RouteCompilerWorker extends RouteCompilerWorkerApi { // the following code is duplicated between play worker versions because it depends on play types // which are not guaranteed to stay the same between versions even though they are currently // identical + private def compileWithPlay(files: Seq[Path], + additionalImports: Seq[String], + forwardsRouter: Boolean, + reverseRouter: Boolean, + namespaceReverseRouter: Boolean, + dest: Path, + ctx: Ctx, + routesGenerator: RoutesGenerator): Either[Seq[compiler.RoutesCompilationError], Seq[File]] = { + val seed: Either[Seq[compiler.RoutesCompilationError], List[File]] = Right(List.empty[File]) + files.map(file => compileWithPlay(file, additionalImports, forwardsRouter, reverseRouter, + namespaceReverseRouter, dest, ctx, routesGenerator)).foldLeft(seed) { + case (Right(accFiles), Right(files)) => Right(accFiles ++ files) + case (Right(accFiles), Left(errors)) => Left(errors) + case (left@Left(errors), _) => left + } + } + private def compileWithPlay(file: Path, additionalImports: Seq[String], forwardsRouter: Boolean, reverseRouter: Boolean, namespaceReverseRouter: Boolean, dest: Path, ctx: Ctx, routesGenerator: RoutesGenerator) = { ctx.log.debug(s"compiling file $file with play generator $routesGenerator") val result = @@ -56,9 +74,10 @@ class RouteCompilerWorker extends RouteCompilerWorkerApi { Result.Success(CompilationResult(zincFile, PathRef(ctx.dest))) case Left(errors) => val errorMsg = errors.map(error => - s"""compilation error in ${error.source.getName} at line${error.line}, column ${error.column}: ${error.message}"""") + s"compilation error in ${error.source.getPath} at line ${error.line.getOrElse("?")}, " + + s"column ${error.column.getOrElse("?")}: ${error.message}") .mkString("\n") - Result.Failure("Unable to compile play routes" + errorMsg) + Result.Failure("Unable to compile play routes, " + errorMsg) } } }
\ No newline at end of file |