summaryrefslogtreecommitdiff
path: root/contrib/playlib/src
diff options
context:
space:
mode:
authorJean Helou <jhe@codamens.fr>2019-02-13 23:29:33 +0100
committerTobias Roeser <le.petit.fou@web.de>2019-02-14 17:45:16 +0100
commit316fab29c7a87e89fa253fd09504b8b54b66911e (patch)
tree75236af55f55858320e0ad075485ea99ee9dcfec /contrib/playlib/src
parent1afcfcafe0ed45aeae52f41768797bb6ab39a4d0 (diff)
downloadmill-316fab29c7a87e89fa253fd09504b8b54b66911e.tar.gz
mill-316fab29c7a87e89fa253fd09504b8b54b66911e.tar.bz2
mill-316fab29c7a87e89fa253fd09504b8b54b66911e.zip
switch to T.sources for the routesFiles setting
Diffstat (limited to 'contrib/playlib/src')
-rw-r--r--contrib/playlib/src/mill/playlib/RouteCompilerWorkerApi.scala7
-rw-r--r--contrib/playlib/src/mill/playlib/RouterModule.scala29
2 files changed, 27 insertions, 9 deletions
diff --git a/contrib/playlib/src/mill/playlib/RouteCompilerWorkerApi.scala b/contrib/playlib/src/mill/playlib/RouteCompilerWorkerApi.scala
index 6e9f68ed..6be0f3f6 100644
--- a/contrib/playlib/src/mill/playlib/RouteCompilerWorkerApi.scala
+++ b/contrib/playlib/src/mill/playlib/RouteCompilerWorkerApi.scala
@@ -35,7 +35,7 @@ class RouteCompilerWorker {
def compile(routerClasspath: Agg[Path],
- file: Path,
+ files: Seq[Path],
additionalImports: Seq[String],
forwardsRouter: Boolean,
reverseRouter: Boolean,
@@ -43,9 +43,11 @@ class RouteCompilerWorker {
generatorType: RouteCompilerType,
dest: Path)(implicit ctx: Ctx)
: Result[CompilationResult] = {
+ //the routes file must come last as it can include the routers generated
+ //by the others
bridge(routerClasspath)
.compile(
- file,
+ files,
additionalImports,
forwardsRouter,
reverseRouter,
@@ -56,6 +58,7 @@ class RouteCompilerWorker {
}
+
}
object RouteCompilerWorkerModule extends ExternalModule {
diff --git a/contrib/playlib/src/mill/playlib/RouterModule.scala b/contrib/playlib/src/mill/playlib/RouterModule.scala
index ac1f71ff..a1dce169 100644
--- a/contrib/playlib/src/mill/playlib/RouterModule.scala
+++ b/contrib/playlib/src/mill/playlib/RouterModule.scala
@@ -7,6 +7,7 @@ import mill.playlib.api.RouteCompilerType
import mill.scalalib.Lib.resolveDependencies
import mill.scalalib._
import mill.scalalib.api._
+import os.Path
trait RouterModule extends mill.Module with ScalaModule {
@@ -16,7 +17,9 @@ trait RouterModule extends mill.Module with ScalaModule {
*/
def playVersion: T[String]
- override def generatedSources = T{ super.generatedSources() ++ Seq(compileRouter().classes) }
+ override def generatedSources = T {
+ super.generatedSources() ++ Seq(compileRouter().classes)
+ }
/**
* The [[PathRef]] to the main routes file.
@@ -24,11 +27,22 @@ trait RouterModule extends mill.Module with ScalaModule {
* This is the default path for play projects and it should be fine but you
* can override it if needed.
*/
- def routesFile: T[PathRef] = T {
- val routesPath = millSourcePath / "conf" / "routes"
- PathRef(routesPath)
+ def routesDirectory = T.sources {
+ millSourcePath / "conf"
+ }
+
+ private def routesFiles = T {
+ val files = routesDirectory()
+ locateFilesBy(files, _.last.endsWith(".routes")) ++ locateFilesBy(files, _.last == "routes")
}
+ private def locateFilesBy(files: Seq[PathRef], p: Path => Boolean) = {
+ files.flatMap(file => {
+ os.walk(file.path).filter(p).map(f => PathRef(f))
+ })
+ }
+
+
/**
* A [[Seq]] of additional imports to be added to the routes file.
* Defaults to :
@@ -51,9 +65,10 @@ trait RouterModule extends mill.Module with ScalaModule {
/**
* The routes compiler type to be used. Can only be one of:
* <ul>
- * <li>[[RouteCompilerType.InjectedGenerator]]
- * <li>[[RouteCompilerType.StaticGenerator]]
+ * <li>[[RouteCompilerType.InjectedGenerator]]
+ * <li>[[RouteCompilerType.StaticGenerator]]
* </ul>
+ *
* @return
*/
def generatorType: RouteCompilerType = RouteCompilerType.InjectedGenerator
@@ -75,7 +90,7 @@ trait RouterModule extends mill.Module with ScalaModule {
T.ctx().log.debug(s"compiling play routes with ${playVersion()} worker")
RouteCompilerWorkerModule.routeCompilerWorker().compile(
toolsClasspath().map(_.path),
- routesFile().path,
+ routesFiles().map(_.path),
routesAdditionalImport,
generateForwardsRouter,
generateReverseRouter,