summaryrefslogtreecommitdiff
path: root/contrib/playlib
diff options
context:
space:
mode:
authorJean Helou <jhe@codamens.fr>2019-02-14 14:49:08 +0100
committerTobias Roeser <le.petit.fou@web.de>2019-02-14 17:45:16 +0100
commitb553dfc027a9977f4a5fd802e419181e5a6f3b61 (patch)
tree53e9cbc4386d388c5870849f91feee9036029fc9 /contrib/playlib
parent15ef8e7cd52930f1591ab7a88081fc80468fed85 (diff)
downloadmill-b553dfc027a9977f4a5fd802e419181e5a6f3b61.tar.gz
mill-b553dfc027a9977f4a5fd802e419181e5a6f3b61.tar.bz2
mill-b553dfc027a9977f4a5fd802e419181e5a6f3b61.zip
better aligns RouterModule with mill's naming conventions
Diffstat (limited to 'contrib/playlib')
-rw-r--r--contrib/playlib/src/mill/playlib/RouterModule.scala31
-rw-r--r--contrib/playlib/test/resources/hello-world/core/routes/routes (renamed from contrib/playlib/test/resources/hello-world/core/conf/routes)0
-rw-r--r--contrib/playlib/test/resources/hello-world/core/routes/sub.routes (renamed from contrib/playlib/test/resources/hello-world/core/conf/sub.routes)0
-rw-r--r--contrib/playlib/test/resources/invalid/core/routes/routes (renamed from contrib/playlib/test/resources/invalid/core/conf/routes)0
-rw-r--r--contrib/playlib/test/resources/invalidsub/core/routes/routes (renamed from contrib/playlib/test/resources/invalidsub/core/conf/routes)0
-rw-r--r--contrib/playlib/test/resources/invalidsub/core/routes/sub.routes (renamed from contrib/playlib/test/resources/invalidsub/core/conf/sub.routes)0
-rw-r--r--contrib/playlib/test/src/mill/playlib/HelloWorldTests.scala11
7 files changed, 13 insertions, 29 deletions
diff --git a/contrib/playlib/src/mill/playlib/RouterModule.scala b/contrib/playlib/src/mill/playlib/RouterModule.scala
index 63433f3b..ea2593aa 100644
--- a/contrib/playlib/src/mill/playlib/RouterModule.scala
+++ b/contrib/playlib/src/mill/playlib/RouterModule.scala
@@ -7,42 +7,23 @@ 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 {
- /**
- * Defines the version of playframework to be used to compile this projects
- * routes.
- */
def playVersion: T[String]
override def generatedSources = T {
super.generatedSources() ++ Seq(compileRouter().classes)
}
- /**
- * The [[PathRef]] to the main routes file.
- *
- * This is the default path for play projects and it should be fine but you
- * can override it if needed.
- */
- def routesDirectory = T.sources {
- millSourcePath / "conf"
- }
-
- private def routesFiles = T {
- val files = routesDirectory()
- locateFilesBy(files, _.last.endsWith(".routes")) ++ locateFilesBy(files, _.last == "routes")
- }
+ def routes = T.sources { millSourcePath / 'routes }
- private def locateFilesBy(files: Seq[PathRef], p: Path => Boolean) = {
- files.flatMap(file => {
- os.walk(file.path).filter(p).map(f => PathRef(f))
- })
+ private def routeFiles = T {
+ val paths = routes().flatMap(file => os.walk(file.path))
+ val routeFiles=paths.filter(_.ext=="routes") ++ paths.filter(_.last == "routes")
+ routeFiles.map(f=>PathRef(f))
}
-
/**
* A [[Seq]] of additional imports to be added to the routes file.
* Defaults to :
@@ -88,7 +69,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),
- routesFiles().map(_.path),
+ routeFiles().map(_.path),
routesAdditionalImport,
generateForwardsRouter,
generateReverseRouter,
diff --git a/contrib/playlib/test/resources/hello-world/core/conf/routes b/contrib/playlib/test/resources/hello-world/core/routes/routes
index f71b0cdd..f71b0cdd 100644
--- a/contrib/playlib/test/resources/hello-world/core/conf/routes
+++ b/contrib/playlib/test/resources/hello-world/core/routes/routes
diff --git a/contrib/playlib/test/resources/hello-world/core/conf/sub.routes b/contrib/playlib/test/resources/hello-world/core/routes/sub.routes
index 4597a19b..4597a19b 100644
--- a/contrib/playlib/test/resources/hello-world/core/conf/sub.routes
+++ b/contrib/playlib/test/resources/hello-world/core/routes/sub.routes
diff --git a/contrib/playlib/test/resources/invalid/core/conf/routes b/contrib/playlib/test/resources/invalid/core/routes/routes
index 5c946fc6..5c946fc6 100644
--- a/contrib/playlib/test/resources/invalid/core/conf/routes
+++ b/contrib/playlib/test/resources/invalid/core/routes/routes
diff --git a/contrib/playlib/test/resources/invalidsub/core/conf/routes b/contrib/playlib/test/resources/invalidsub/core/routes/routes
index 5c946fc6..5c946fc6 100644
--- a/contrib/playlib/test/resources/invalidsub/core/conf/routes
+++ b/contrib/playlib/test/resources/invalidsub/core/routes/routes
diff --git a/contrib/playlib/test/resources/invalidsub/core/conf/sub.routes b/contrib/playlib/test/resources/invalidsub/core/routes/sub.routes
index 9c844a4a..9c844a4a 100644
--- a/contrib/playlib/test/resources/invalidsub/core/conf/sub.routes
+++ b/contrib/playlib/test/resources/invalidsub/core/routes/sub.routes
diff --git a/contrib/playlib/test/src/mill/playlib/HelloWorldTests.scala b/contrib/playlib/test/src/mill/playlib/HelloWorldTests.scala
index 20e8ce55..54e8a057 100644
--- a/contrib/playlib/test/src/mill/playlib/HelloWorldTests.scala
+++ b/contrib/playlib/test/src/mill/playlib/HelloWorldTests.scala
@@ -85,21 +85,24 @@ object HelloWorldTests extends TestSuite {
assert(unchangedEvalCount == 0)
}
- 'compileRouter - workspaceTest(HelloWorld, resourcePath = invalidResourcePath) { eval =>
+ "compileRouter invalid routes"- workspaceTest(HelloWorld, resourcePath = invalidResourcePath) {
+ eval =>
val eitherResult = eval.apply(HelloWorld.core.compileRouter)
val Left(Failure(message, x)) = eitherResult
val expectedMessage = "Unable to compile play routes\ncompilation error in " +
- HelloWorld.millSourcePath.toIO.getAbsolutePath + "/core/conf/routes at line 4, column" +
+ HelloWorld.core.millSourcePath.toIO.getAbsolutePath + "/routes/routes at line 4, " +
+ "column" +
" 1: HTTP Verb (GET, POST, ...), include (->), comment (#), or modifier line (+) expected"
assert(
message == expectedMessage
)
}
- 'compileRouter - workspaceTest(HelloWorld, resourcePath = invalidSubResourcePath) { eval =>
+ "compileRouter invalid sub.routes " - workspaceTest(HelloWorld, resourcePath = invalidSubResourcePath) {
+ eval =>
val eitherResult = eval.apply(HelloWorld.core.compileRouter)
val Left(Failure(message, x)) = eitherResult
val expectedMessage = "Unable to compile play routes\ncompilation error in " +
- HelloWorld.millSourcePath.toIO.getAbsolutePath + "/core/conf/sub.routes at line 3, column" +
+ HelloWorld.core.millSourcePath.toIO.getAbsolutePath + "/routes/sub.routes at line 3, column" +
" 1: HTTP Verb (GET, POST, ...), include (->), comment (#), or modifier line (+) expected"
assert(
message == expectedMessage