summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Helou <jhe@codamens.fr>2019-02-15 11:43:45 +0100
committerTobias Roeser <le.petit.fou@web.de>2019-03-11 07:41:03 +0100
commitd721e56f29464f2d20d519bf8e6be6ea7b3df31f (patch)
tree452fffdb50020dc0988235bfc6ebdd44f926921c
parente480953743e03aa7f93861278f67d6eb3aae9ede (diff)
downloadmill-d721e56f29464f2d20d519bf8e6be6ea7b3df31f.tar.gz
mill-d721e56f29464f2d20d519bf8e6be6ea7b3df31f.tar.bz2
mill-d721e56f29464f2d20d519bf8e6be6ea7b3df31f.zip
Integrate Router module and add a trait to configure it for play
-rw-r--r--contrib/playlib/src/mill/playlib/Router.scala6
-rw-r--r--contrib/playlib/src/mill/playlib/RouterModule.scala29
2 files changed, 19 insertions, 16 deletions
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