From d721e56f29464f2d20d519bf8e6be6ea7b3df31f Mon Sep 17 00:00:00 2001 From: Jean Helou Date: Fri, 15 Feb 2019 11:43:45 +0100 Subject: Integrate Router module and add a trait to configure it for play --- contrib/playlib/src/mill/playlib/Router.scala | 6 +++++ .../playlib/src/mill/playlib/RouterModule.scala | 29 ++++++++++------------ 2 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 contrib/playlib/src/mill/playlib/Router.scala (limited to 'contrib/playlib/src') diff --git a/contrib/playlib/src/mill/playlib/Router.scala b/contrib/playlib/src/mill/playlib/Router.scala new file mode 100644 index 00000000..da3ef1dc --- /dev/null +++ b/contrib/playlib/src/mill/playlib/Router.scala @@ -0,0 +1,6 @@ +package mill +package playlib + +private[playlib] trait Router extends RouterModule with Layout { + override def routes = T{ conf() } +} diff --git a/contrib/playlib/src/mill/playlib/RouterModule.scala b/contrib/playlib/src/mill/playlib/RouterModule.scala index ea2593aa..22912453 100644 --- a/contrib/playlib/src/mill/playlib/RouterModule.scala +++ b/contrib/playlib/src/mill/playlib/RouterModule.scala @@ -2,21 +2,15 @@ package mill package playlib import coursier.{Cache, MavenRepository} -import mill.api.Loose +import mill.eval.PathRef import mill.playlib.api.RouteCompilerType import mill.scalalib.Lib.resolveDependencies import mill.scalalib._ import mill.scalalib.api._ -trait RouterModule extends mill.Module with ScalaModule { +trait RouterModule extends ScalaModule with Version { - def playVersion: T[String] - - override def generatedSources = T { - super.generatedSources() ++ Seq(compileRouter().classes) - } - - def routes = T.sources { millSourcePath / 'routes } + def routes: T[Seq[PathRef]] = T.sources { millSourcePath / 'routes } private def routeFiles = T { val paths = routes().flatMap(file => os.walk(file.path)) @@ -52,7 +46,7 @@ trait RouterModule extends mill.Module with ScalaModule { */ def generatorType: RouteCompilerType = RouteCompilerType.InjectedGenerator - def routerClasspath: T[Loose.Agg[PathRef]] = T { + def routerClasspath: T[Agg[PathRef]] = T { resolveDependencies( Seq( Cache.ivy2Local, @@ -65,7 +59,7 @@ trait RouterModule extends mill.Module with ScalaModule { ) } - final def compileRouter: T[CompilationResult] = T { + final def compileRouter: T[CompilationResult] = T.persistent { T.ctx().log.debug(s"compiling play routes with ${playVersion()} worker") RouteCompilerWorkerModule.routeCompilerWorker().compile( toolsClasspath().map(_.path), @@ -78,14 +72,9 @@ trait RouterModule extends mill.Module with ScalaModule { T.ctx().dest) } - private def playMinorVersion: T[String] = T { - playVersion().split("\\.").take(2).mkString("", ".", ".0") - } - private def playRouteCompilerWorkerClasspath = T { val workerKey = "MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_" + playMinorVersion().replace(".", "_") - T.ctx.log.debug(s"classpath worker key: $workerKey") //While the following seems to work (tests pass), I am not completely //confident that the strings I used for artifact and resolveFilter are @@ -101,4 +90,12 @@ trait RouterModule extends mill.Module with ScalaModule { private def toolsClasspath = T { playRouteCompilerWorkerClasspath() ++ routerClasspath() } + + def routerClasses = T{ + Seq(compileRouter().classes) + } + + override def generatedSources = T { + super.generatedSources() ++ routerClasses() + } } \ No newline at end of file -- cgit v1.2.3