-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10171 from playframework/mergify/bp/2.8.x/pr-10153
Correctly handle "_root_." prefix in routes file (needed for namespaceReverseRouter) (bp #10153)
- Loading branch information
Showing
24 changed files
with
188 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...plugin/routes-compiler-namespace-reverse-router/app/utils/JavaScriptRouterGenerator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package utils | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
|
||
object JavaScriptRouterGenerator extends App { | ||
|
||
val jsFile = play.api.routing | ||
.JavaScriptReverseRouter( | ||
"jsRoutes", | ||
None, | ||
"localhost", | ||
router.controllers.routes.javascript.Assets.versioned, | ||
) | ||
.body | ||
|
||
// Add module exports for node | ||
val jsModule = jsFile + | ||
""" | ||
|module.exports = jsRoutes | ||
""".stripMargin | ||
|
||
val path = Paths.get(args(0)) | ||
Files.createDirectories(path.getParent) | ||
Files.write(path, jsModule.getBytes("UTF-8")) | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...bt-plugin/src/sbt-test/play-sbt-plugin/routes-compiler-namespace-reverse-router/build.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
// | ||
lazy val root = (project in file(".")) | ||
.enablePlugins(PlayScala) | ||
|
||
namespaceReverseRouter := true | ||
|
||
libraryDependencies ++= Seq(guice, specs2 % Test) | ||
|
||
scalaVersion := sys.props("scala.version") | ||
updateOptions := updateOptions.value.withLatestSnapshots(false) | ||
evictionWarningOptions in update ~= (_.withWarnTransitiveEvictions(false).withWarnDirectEvictions(false)) | ||
|
||
// can't use test directory since scripted calls its script "test" | ||
sourceDirectory in Test := baseDirectory.value / "tests" | ||
|
||
scalaSource in Test := baseDirectory.value / "tests" | ||
|
||
// Generate a js router so we can test it with mocha | ||
val generateJsRouter = TaskKey[Seq[File]]("generate-js-router") | ||
|
||
generateJsRouter := { | ||
(runMain in Compile).toTask(" utils.JavaScriptRouterGenerator target/web/jsrouter/jsRoutes.js").value | ||
Seq(target.value / "web" / "jsrouter" / "jsRoutes.js") | ||
} | ||
|
||
resourceGenerators in TestAssets += Def.task(generateJsRouter.value).taskValue | ||
managedResourceDirectories in TestAssets += target.value / "web" / "jsrouter" | ||
|
||
// We don't want source position mappers is this will make it very hard to debug | ||
sourcePositionMappers := Nil | ||
|
||
play.sbt.routes.RoutesKeys.routesImport := Nil | ||
ScriptedTools.dumpRoutesSourceOnCompilationFailure | ||
|
||
scalacOptions ++= { | ||
Seq( | ||
"-deprecation", | ||
"-encoding", | ||
"UTF-8", | ||
"-feature", | ||
"-language:existentials", | ||
"-language:higherKinds", | ||
"-language:implicitConversions", | ||
"-unchecked", | ||
"-Xfatal-warnings", | ||
"-Xlint", | ||
"-Yno-adapted-args", | ||
"-Ywarn-dead-code", | ||
"-Ywarn-numeric-widen", | ||
"-Ywarn-value-discard", | ||
"-Xfuture" | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
...-plugin/src/sbt-test/play-sbt-plugin/routes-compiler-namespace-reverse-router/conf/routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# | ||
# Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
# | ||
|
||
GET /public/*file _root_.controllers.Assets.versioned(path="/public", file: _root_.controllers.Assets.Asset) |
8 changes: 8 additions & 0 deletions
8
...src/sbt-test/play-sbt-plugin/routes-compiler-namespace-reverse-router/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// | ||
// Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
// | ||
|
||
updateOptions := updateOptions.value.withLatestSnapshots(false) | ||
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % sys.props("project.version")) | ||
addSbtPlugin("com.typesafe.play" % "sbt-scripted-tools" % sys.props("project.version")) | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.2") |
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions
1
...sbt-test/play-sbt-plugin/routes-compiler-namespace-reverse-router/public/css/main.css.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
abcd1234 |
Empty file.
1 change: 1 addition & 0 deletions
1
...t/play-sbt-plugin/routes-compiler-namespace-reverse-router/public/css/minmain-min.css.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
abcd1234 |
Empty file.
Empty file.
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions
5
...ode/sbt-plugin/src/sbt-test/play-sbt-plugin/routes-compiler-namespace-reverse-router/test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Stage it, so it's easier to debug | ||
> playRoutes | ||
> compile | ||
> test:compile | ||
> test |
38 changes: 38 additions & 0 deletions
38
.../sbt-test/play-sbt-plugin/routes-compiler-namespace-reverse-router/tests/RouterSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package test | ||
|
||
import play.api.test._ | ||
|
||
object RouterSpec extends PlaySpecification { | ||
|
||
"document the router" in new WithApplication() { | ||
val someRoute = implicitApp.injector | ||
.instanceOf[play.api.routing.Router] | ||
.documentation | ||
.find(r => r._1 == "GET" && r._2.startsWith("/public/")) | ||
someRoute must beSome[(String, String, String)] | ||
val route = someRoute.get | ||
route._2 must_== "/public/$file<.+>" | ||
route._3 must startWith("""_root_.controllers.Assets.versioned(path:String = "/public", file:_root_.controllers.Assets.Asset)""") | ||
} | ||
|
||
"The assets reverse route support" should { | ||
"fingerprint assets" in new WithApplication() { | ||
router.controllers.routes.Assets.versioned("css/main.css").url must_== "/public/css/abcd1234-main.css" | ||
} | ||
"selected the minified version" in new WithApplication() { | ||
router.controllers.routes.Assets.versioned("css/minmain.css").url must_== "/public/css/abcd1234-minmain-min.css" | ||
} | ||
"work for non fingerprinted assets" in new WithApplication() { | ||
router.controllers.routes.Assets.versioned("css/nonfingerprinted.css").url must_== "/public/css/nonfingerprinted.css" | ||
} | ||
"selected the minified non fingerprinted version" in new WithApplication() { | ||
router.controllers.routes.Assets | ||
.versioned("css/nonfingerprinted-minmain.css") | ||
.url must_== "/public/css/nonfingerprinted-minmain-min.css" | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...-sbt-plugin/routes-compiler-namespace-reverse-router/tests/assets/JavaScriptRouterSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
var assert = require("assert"); | ||
var jsRoutes = require("./jsRoutes"); | ||
|
||
describe("The JavaScript router", function() { | ||
it("should generate a url for assets", function() { | ||
var data = jsRoutes.router.controllers.Assets.versioned('hello.png'); | ||
assert.equal("/public/hello.png", data.url); | ||
}); | ||
it("should provide the GET method for assets", function() { | ||
var data = jsRoutes.router.controllers.Assets.versioned(); | ||
assert.equal("GET", data.method); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters