From f5458e25063c880ed13cec1a742f33cbc9a738dd Mon Sep 17 00:00:00 2001 From: Jean Helou Date: Tue, 26 Feb 2019 23:12:08 +0100 Subject: Reworks version specific keys and extraction Route compilation workers are specific to play minor version but still added a patch level version in the key. The playMinorVersion used to compute the version part of the key had to add a useless trailing `.0`, this is now fixed. --- build.sc | 11 ++- contrib/playlib/api/src/Versions.scala | 4 +- contrib/playlib/src/mill/playlib/Version.scala | 2 +- .../worker/2.6.0/src/RouteCompilerWorker.scala | 91 ---------------------- .../worker/2.6/src/RouteCompilerWorker.scala | 91 ++++++++++++++++++++++ .../worker/2.7.0/src/RouteCompilerWorker.scala | 83 -------------------- .../worker/2.7/src/RouteCompilerWorker.scala | 83 ++++++++++++++++++++ 7 files changed, 182 insertions(+), 183 deletions(-) delete mode 100644 contrib/playlib/worker/2.6.0/src/RouteCompilerWorker.scala create mode 100644 contrib/playlib/worker/2.6/src/RouteCompilerWorker.scala delete mode 100644 contrib/playlib/worker/2.7.0/src/RouteCompilerWorker.scala create mode 100644 contrib/playlib/worker/2.7/src/RouteCompilerWorker.scala diff --git a/build.sc b/build.sc index 992210bd..65f68c51 100755 --- a/build.sc +++ b/build.sc @@ -252,8 +252,8 @@ object contrib extends MillModule { def testArgs = T { val mapping = Map( - "MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_6_0" -> worker("2.6.0").compile().classes.path, - "MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_7_0" -> worker("2.7.0").compile().classes.path + "MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_6" -> worker("2.6").compile().classes.path, + "MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_7" -> worker("2.7").compile().classes.path ) scalalib.worker.testArgs() ++ @@ -264,18 +264,17 @@ object contrib extends MillModule { object api extends MillApiModule { def moduleDeps = Seq(scalalib) } - - object worker extends Cross[WorkerModule]( "2.6.0", "2.7.0") + object worker extends Cross[WorkerModule]( "2.6", "2.7") class WorkerModule(scalajsBinary: String) extends MillApiModule { def moduleDeps = Seq(playlib.api) def ivyDeps = scalajsBinary match { - case "2.6.0" => + case "2.6"=> Agg( ivy"com.typesafe.play::routes-compiler::2.6.0" ) - case "2.7.0" => + case "2.7" => Agg( ivy"com.typesafe.play::routes-compiler::2.7.0" ) diff --git a/contrib/playlib/api/src/Versions.scala b/contrib/playlib/api/src/Versions.scala index 25e7026e..8c58f6e0 100644 --- a/contrib/playlib/api/src/Versions.scala +++ b/contrib/playlib/api/src/Versions.scala @@ -2,6 +2,6 @@ package mill package playlib package api object Versions { - val PLAY_2_6="2.6.0" - val PLAY_2_7="2.7.0" + val PLAY_2_6="2.6" + val PLAY_2_7="2.7" } diff --git a/contrib/playlib/src/mill/playlib/Version.scala b/contrib/playlib/src/mill/playlib/Version.scala index ae441a8a..24e11666 100644 --- a/contrib/playlib/src/mill/playlib/Version.scala +++ b/contrib/playlib/src/mill/playlib/Version.scala @@ -9,7 +9,7 @@ private[playlib] trait Version extends Module{ def playVersion: T[String] private[playlib] def playMinorVersion: T[String] = T { - playVersion().split("\\.").take(2).mkString("", ".", ".0") + playVersion().split("\\.").take(2).mkString(".") } private[playlib] def component(id: String): Task[Dep] = T.task { diff --git a/contrib/playlib/worker/2.6.0/src/RouteCompilerWorker.scala b/contrib/playlib/worker/2.6.0/src/RouteCompilerWorker.scala deleted file mode 100644 index 83de5e42..00000000 --- a/contrib/playlib/worker/2.6.0/src/RouteCompilerWorker.scala +++ /dev/null @@ -1,91 +0,0 @@ -package mill -package playlib -package worker - -import java.io.File - -import ammonite.ops.Path -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._ - - -private[playlib] class RouteCompilerWorker extends RouteCompilerWorkerApi { - - override def compile(files: Seq[Path], - additionalImports: Seq[String], - forwardsRouter: Boolean, - reverseRouter: Boolean, - namespaceReverseRouter: Boolean, - generatorType: RouteCompilerType, - dest: Path) - (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult] = { - generatorType match { - case RouteCompilerType.InjectedGenerator => - val result = compileWithPlay(files, additionalImports, forwardsRouter, reverseRouter, - namespaceReverseRouter, dest, ctx, InjectedRoutesGenerator) - asMillResult(ctx, result) - case RouteCompilerType.StaticGenerator => - ctx.log.error("Static generator was deprecated in 2.6.0 and will be removed in 2.7.0") - val result = compileWithPlay(files, additionalImports, forwardsRouter, reverseRouter, - namespaceReverseRouter, dest, ctx, StaticRoutesGenerator) - asMillResult(ctx, result) - case _ => throw new Exception(s"Unrecognized generator type: $generatorType. Use injected or static") - } - } - - 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): Either[Seq[compiler.RoutesCompilationError], Seq[File]] = { - ctx.log.debug(s"compiling $file with play generator $routesGenerator") - val result = - RoutesCompiler.compile( - RoutesCompilerTask(file.toIO, additionalImports, forwardsRouter, reverseRouter, - namespaceReverseRouter), - generator = routesGenerator, - generatedDir = dest.toIO - ) - ctx.log.debug(s"compilation result: $result") - result - } - - private def asMillResult(ctx: Ctx, result: Either[Seq[RoutesCompilationError], Seq[File]]): Result[CompilationResult] = { - 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}") - .mkString("\n") - Result.Failure("Unable to compile play routes\n" + errorMsg) - } - } -} \ No newline at end of file diff --git a/contrib/playlib/worker/2.6/src/RouteCompilerWorker.scala b/contrib/playlib/worker/2.6/src/RouteCompilerWorker.scala new file mode 100644 index 00000000..83de5e42 --- /dev/null +++ b/contrib/playlib/worker/2.6/src/RouteCompilerWorker.scala @@ -0,0 +1,91 @@ +package mill +package playlib +package worker + +import java.io.File + +import ammonite.ops.Path +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._ + + +private[playlib] class RouteCompilerWorker extends RouteCompilerWorkerApi { + + override def compile(files: Seq[Path], + additionalImports: Seq[String], + forwardsRouter: Boolean, + reverseRouter: Boolean, + namespaceReverseRouter: Boolean, + generatorType: RouteCompilerType, + dest: Path) + (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult] = { + generatorType match { + case RouteCompilerType.InjectedGenerator => + val result = compileWithPlay(files, additionalImports, forwardsRouter, reverseRouter, + namespaceReverseRouter, dest, ctx, InjectedRoutesGenerator) + asMillResult(ctx, result) + case RouteCompilerType.StaticGenerator => + ctx.log.error("Static generator was deprecated in 2.6.0 and will be removed in 2.7.0") + val result = compileWithPlay(files, additionalImports, forwardsRouter, reverseRouter, + namespaceReverseRouter, dest, ctx, StaticRoutesGenerator) + asMillResult(ctx, result) + case _ => throw new Exception(s"Unrecognized generator type: $generatorType. Use injected or static") + } + } + + 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): Either[Seq[compiler.RoutesCompilationError], Seq[File]] = { + ctx.log.debug(s"compiling $file with play generator $routesGenerator") + val result = + RoutesCompiler.compile( + RoutesCompilerTask(file.toIO, additionalImports, forwardsRouter, reverseRouter, + namespaceReverseRouter), + generator = routesGenerator, + generatedDir = dest.toIO + ) + ctx.log.debug(s"compilation result: $result") + result + } + + private def asMillResult(ctx: Ctx, result: Either[Seq[RoutesCompilationError], Seq[File]]): Result[CompilationResult] = { + 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}") + .mkString("\n") + Result.Failure("Unable to compile play routes\n" + errorMsg) + } + } +} \ No newline at end of file diff --git a/contrib/playlib/worker/2.7.0/src/RouteCompilerWorker.scala b/contrib/playlib/worker/2.7.0/src/RouteCompilerWorker.scala deleted file mode 100644 index 3e5a1b68..00000000 --- a/contrib/playlib/worker/2.7.0/src/RouteCompilerWorker.scala +++ /dev/null @@ -1,83 +0,0 @@ -package mill -package playlib -package worker - -import java.io.File - -import ammonite.ops.Path -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} - - -private[playlib] class RouteCompilerWorker extends RouteCompilerWorkerApi { - - override def compile(files: Seq[Path], - additionalImports: Seq[String], - forwardsRouter: Boolean, - reverseRouter: Boolean, - namespaceReverseRouter: Boolean, - generatorType: RouteCompilerType, - dest: Path) - (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult] = { - generatorType match { - case RouteCompilerType.InjectedGenerator => - val result = compileWithPlay(files, additionalImports, forwardsRouter, reverseRouter, - namespaceReverseRouter, dest, ctx, InjectedRoutesGenerator) - asMillResult(ctx, result) - case RouteCompilerType.StaticGenerator => - Result.Failure("Static generator was deprecated in 2.6.0 then removed in 2.7.x, see https://www.playframework.com/documentation/2.7.x/Migration27#StaticRoutesGenerator-removed") - } - } - - // 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 = - RoutesCompiler.compile( - RoutesCompilerTask(file.toIO, additionalImports, forwardsRouter, reverseRouter, - namespaceReverseRouter), - generator = routesGenerator, - generatedDir = dest.toIO - ) - ctx.log.debug(s"compilation result: $result") - result - } - - private def asMillResult(ctx: Ctx, result: Either[Seq[RoutesCompilationError], Seq[File]]): Result[CompilationResult] = { - 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}") - .mkString("\n") - Result.Failure("Unable to compile play routes, " + errorMsg) - } - } -} \ No newline at end of file diff --git a/contrib/playlib/worker/2.7/src/RouteCompilerWorker.scala b/contrib/playlib/worker/2.7/src/RouteCompilerWorker.scala new file mode 100644 index 00000000..3e5a1b68 --- /dev/null +++ b/contrib/playlib/worker/2.7/src/RouteCompilerWorker.scala @@ -0,0 +1,83 @@ +package mill +package playlib +package worker + +import java.io.File + +import ammonite.ops.Path +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} + + +private[playlib] class RouteCompilerWorker extends RouteCompilerWorkerApi { + + override def compile(files: Seq[Path], + additionalImports: Seq[String], + forwardsRouter: Boolean, + reverseRouter: Boolean, + namespaceReverseRouter: Boolean, + generatorType: RouteCompilerType, + dest: Path) + (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult] = { + generatorType match { + case RouteCompilerType.InjectedGenerator => + val result = compileWithPlay(files, additionalImports, forwardsRouter, reverseRouter, + namespaceReverseRouter, dest, ctx, InjectedRoutesGenerator) + asMillResult(ctx, result) + case RouteCompilerType.StaticGenerator => + Result.Failure("Static generator was deprecated in 2.6.0 then removed in 2.7.x, see https://www.playframework.com/documentation/2.7.x/Migration27#StaticRoutesGenerator-removed") + } + } + + // 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 = + RoutesCompiler.compile( + RoutesCompilerTask(file.toIO, additionalImports, forwardsRouter, reverseRouter, + namespaceReverseRouter), + generator = routesGenerator, + generatedDir = dest.toIO + ) + ctx.log.debug(s"compilation result: $result") + result + } + + private def asMillResult(ctx: Ctx, result: Either[Seq[RoutesCompilationError], Seq[File]]): Result[CompilationResult] = { + 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}") + .mkString("\n") + Result.Failure("Unable to compile play routes, " + errorMsg) + } + } +} \ No newline at end of file -- cgit v1.2.3