Skip to content

Commit cc71591

Browse files
authored
Cross-compile to Play 2.8 (#10)
1 parent 6578db6 commit cc71591

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

build.sbt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ def playModuleJsonErrorHandler(includePlayVersion: String): Project = {
4343
case Play_2_5 => "25"
4444
case Play_2_6 => "26"
4545
case Play_2_7 => "27"
46+
case Play_2_8 => "28"
4647
}
4748
val scalaVersions = includePlayVersion match {
4849
case Play_2_5 => Seq(Scala_2_11)
4950
case Play_2_6 => Seq(Scala_2_11, Scala_2_12)
5051
case Play_2_7 => Seq(Scala_2_11, Scala_2_12, Scala_2_13)
52+
case Play_2_8 => Seq(Scala_2_12, Scala_2_13)
5153
}
5254
val projectPath = "code"
5355
commonProject(s"play$playSuffix-module-json-error-handler", s"play$playSuffix")
@@ -72,3 +74,8 @@ def playModuleJsonErrorHandler(includePlayVersion: String): Project = {
7274
lazy val play25 = playModuleJsonErrorHandler(Play_2_5)
7375
lazy val play26 = playModuleJsonErrorHandler(Play_2_6)
7476
lazy val play27 = playModuleJsonErrorHandler(Play_2_7)
77+
lazy val play28 = playModuleJsonErrorHandler(Play_2_8).settings(
78+
// this artifact is new, so don't try to download older artifacts
79+
mimaPreviousArtifacts := Set(),
80+
mimaFailOnNoPrevious := false,
81+
)

code/src/main/scala/com/rallyhealth/playmodule/jsonerrors/JsonHttpErrorConfig.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ case class JsonHttpErrorConfig(showDevErrors: Boolean, showRoutes: Boolean, play
1313

1414
object JsonHttpErrorConfig {
1515

16+
// This only exists for source compatibility with Play 2.8 and older verions of Play Config
17+
private implicit class ConfigSourceCompat(private val config: Configuration) extends AnyVal {
18+
def getString(path: String): Option[String] = {
19+
if (config.underlying.hasPath(path)) Some(config.underlying.getString(path))
20+
else None
21+
}
22+
}
23+
1624
def fromEnvironment(env: Environment, config: Configuration): JsonHttpErrorConfig = {
1725
val isDev = env.mode != Mode.Prod
1826
val editor = config.getString("play.editor")

code/src/test/scala/com/rallyhealth/playmodule/jsonerrors/PlayJsonHttpErrorHandlerSpec.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.rallyhealth.playmodule.jsonerrors
22

3+
import akka.util.ByteString
34
import org.scalatest.freespec.AsyncFreeSpec
45
import play.api.http._
56
import play.api.libs.json.{JsObject, Json}
7+
import play.api.libs.streams.Accumulator
68
import play.api.mvc._
79
import play.api.routing.Router
810
import play.api.routing.Router.Routes
@@ -94,8 +96,8 @@ class PlayJsonHttpErrorHandlerSpec extends AsyncFreeSpec with AsyncResultExtract
9496

9597
s"$it should return a list of routes for 404 when $showDevErrorIsSet and $showRoutesIsSet" in {
9698
val fixture = newFixture(DocumentedRouter.fromRegexMap(
97-
("GET", "/unmatched/1".r, "test 1 documentation") -> Action(Results.Ok),
98-
("GET", "/unmatched/2".r, "test 2 documentation") -> Action(Results.Ok)
99+
("GET", "/unmatched/1".r, "test 1 documentation") -> PlayAction(Results.Ok),
100+
("GET", "/unmatched/2".r, "test 2 documentation") -> PlayAction(Results.Ok)
99101
))
100102
import fixture._
101103
val expectedMessage = "test exception"
@@ -294,3 +296,8 @@ object DocumentedRouter {
294296
new DocumentedRouter(Function.unlift(router), documentation)
295297
}
296298
}
299+
300+
// Used for source compatibility with Play 2.8 and earlier versions that used Action.apply()
301+
object PlayAction {
302+
def apply(result: => Result): EssentialAction = EssentialAction(_ => Accumulator.done(result))
303+
}

project/Dependencies.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ object Dependencies {
99
final val Play_2_5 = "2.5.18"
1010
final val Play_2_6 = "2.6.19"
1111
final val Play_2_7 = "2.7.9"
12+
final val Play_2_8 = "2.8.8"
1213

1314
private final val guice4Version = "4.2.3"
1415
private final val play25JsonVersion = Play_2_5
1516
private final val play26JsonVersion = "2.6.9"
1617
private final val play27JsonVersion = "2.7.4"
18+
private final val play28JsonVersion = "2.8.1"
1719
private final val playTestOpsVersion = "1.5.0"
1820
private final val scalatestVersion = "3.2.7"
1921

@@ -30,6 +32,7 @@ object Dependencies {
3032
case Play_2_5 => play25JsonVersion
3133
case Play_2_6 => play26JsonVersion
3234
case Play_2_7 => play27JsonVersion
35+
case Play_2_8 => play28JsonVersion
3336
}
3437
"com.typesafe.play" %% "play-json" % version
3538
}
@@ -43,6 +46,7 @@ object Dependencies {
4346
case Play_2_5 => "25"
4447
case Play_2_6 => "26"
4548
case Play_2_7 => "27"
49+
case Play_2_8 => "28"
4650
}
4751
"com.rallyhealth" %% s"play$playSuffix-test-ops-core" % playTestOpsVersion
4852
}

0 commit comments

Comments
 (0)