Skip to content

Commit

Permalink
Support Play Framework 3.0 and 2.9 (#2772)
Browse files Browse the repository at this point in the history
- Update Play 2.8 to 2.8.20
- Add default `twirlVersion` for play based on `playVersion`
- Add default `twirlScalaVersion` based on `twirlVersion`

Pull request: #2772
  • Loading branch information
lolgab authored Nov 7, 2023
1 parent 0718394 commit d7859ca
Show file tree
Hide file tree
Showing 21 changed files with 312 additions and 226 deletions.
22 changes: 18 additions & 4 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ object Deps {
val testScala30Version = "3.0.2"
val testScala31Version = "3.1.3"
val testScala32Version = "3.2.0"
val testScala33Version = "3.3.1"

object Scalajs_1 {
val scalaJsVersion = "1.14.0"
Expand All @@ -84,7 +85,11 @@ object Deps {
trait Play {
def playVersion: String
def playBinVersion: String = playVersion.split("[.]").take(2).mkString(".")
def routesCompiler = ivy"com.typesafe.play::routes-compiler::$playVersion"
def routesCompiler = playBinVersion match {
case "2.6" | "2.7" | "2.8" => ivy"com.typesafe.play::routes-compiler::$playVersion"
case "2.9" => ivy"com.typesafe.play::play-routes-compiler::$playVersion"
case _ => ivy"org.playframework::play-routes-compiler::$playVersion"
}
def scalaVersion: String = Deps.scalaVersion
}
object Play_2_6 extends Play {
Expand All @@ -95,9 +100,15 @@ object Deps {
val playVersion = "2.7.9"
}
object Play_2_8 extends Play {
val playVersion = "2.8.19"
val playVersion = "2.8.20"
}
object Play_2_9 extends Play {
val playVersion = "2.9.0"
}
object Play_3_0 extends Play {
val playVersion = "3.0.0"
}
val play = Seq(Play_2_8, Play_2_7, Play_2_6).map(p => (p.playBinVersion, p)).toMap
val play = Seq(Play_3_0, Play_2_9, Play_2_8, Play_2_7, Play_2_6).map(p => (p.playBinVersion, p)).toMap

val acyclic = ivy"com.lihaoyi:::acyclic:0.3.9"
val ammoniteVersion = "3.0.0-M0-53-084f7f4e"
Expand Down Expand Up @@ -352,6 +363,7 @@ trait MillBaseTestsModule extends MillJavaModule with TestModule {
s"-DTEST_SCALA_3_0_VERSION=${Deps.testScala30Version}",
s"-DTEST_SCALA_3_1_VERSION=${Deps.testScala31Version}",
s"-DTEST_SCALA_3_2_VERSION=${Deps.testScala32Version}",
s"-DTEST_SCALA_3_3_VERSION=${Deps.testScala33Version}",
s"-DTEST_SCALAJS_VERSION=${Deps.Scalajs_1.scalaJsVersion}",
s"-DTEST_SCALANATIVE_VERSION=${Deps.Scalanative_0_4.scalanativeVersion}",
s"-DTEST_UTEST_VERSION=${Deps.utest.dep.version}",
Expand Down Expand Up @@ -739,7 +751,9 @@ object contrib extends Module {
Seq(
s"-DTEST_PLAY_VERSION_2_6=${Deps.Play_2_6.playVersion}",
s"-DTEST_PLAY_VERSION_2_7=${Deps.Play_2_7.playVersion}",
s"-DTEST_PLAY_VERSION_2_8=${Deps.Play_2_8.playVersion}"
s"-DTEST_PLAY_VERSION_2_8=${Deps.Play_2_8.playVersion}",
s"-DTEST_PLAY_VERSION_2_9=${Deps.Play_2_9.playVersion}",
s"-DTEST_PLAY_VERSION_3_0=${Deps.Play_3_0.playVersion}"
)
}

Expand Down
2 changes: 2 additions & 0 deletions contrib/playlib/api/src/mill/playlib/api/Versions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public class Versions {
public static final String PLAY_2_6 = "2.6";
public static final String PLAY_2_7 = "2.7";
public static final String PLAY_2_8 = "2.8";
public static final String PLAY_2_9 = "2.9";
public static final String PLAY_3_0 = "3.0";
}
45 changes: 21 additions & 24 deletions contrib/playlib/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._
object core extends PlayModule {
//config
override def scalaVersion= T{"2.13.8"}
override def playVersion= T{"2.8.16"}
override def twirlVersion= T{"1.5.1"}
// config
override def scalaVersion = T { "2.13.12" }
override def playVersion = T { "2.8.20" }
object test extends PlayTests
}
Expand Down Expand Up @@ -108,18 +107,18 @@ ivy"com.typesafe.play::play-akka-http-server:${playVersion()}"
=== Using `PlayApiModule`

The `PlayApiModule` trait behaves the same as the `PlayModule` trait but it won't process .scala
.html files and you don't need to define the `twirlVersion:
.html files:

.`build.sc`
[source,scala]
----
import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:$MILL_VERSION`, mill.playlib._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._
object core extends PlayApiModule {
//config
override def scalaVersion= T{"2.13.8"}
override def playVersion= T{"2.8.16"}
// config
override def scalaVersion = T { "2.13.12" }
override def playVersion = T { "2.8.20" }
object test extends PlayTests
}
Expand Down Expand Up @@ -154,9 +153,9 @@ import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:$MILL_VERSION`, mill.playlib._
object core extends PlayApiModule {
//config
override def scalaVersion= T{"2.13.8"}
override def playVersion= T{"2.8.16"}
// config
override def scalaVersion = T{ "2.13.12" }
override def playVersion = T{ "2.8.20" }
object test extends PlayTests
Expand Down Expand Up @@ -192,13 +191,12 @@ Looking back at the sample build definition in <<_using_playmodule>>:
[source,scala]
----
import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:$MILL_VERSION`, mill.playlib._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._
object core extends PlayModule {
//config
override def scalaVersion= T{"2.13.8"}
override def playVersion= T{"2.8.16"}
override def twirlVersion= T{"1.5.1"}
// config
override def scalaVersion = T { "2.13.12" }
override def playVersion = T { "2.8.20" }
object test extends PlayTests
}
Expand Down Expand Up @@ -236,10 +234,9 @@ import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._
object core extends PlayModule with SingleModule {
//config
override def scalaVersion= T{"2.13.8"}
override def playVersion= T{"2.8.16"}
override def twirlVersion= T{"1.5.1"}
// config
override def scalaVersion = T { "2.13.12" }
override def playVersion = T { "2.8.20" }
object test extends PlayTests
}
Expand Down Expand Up @@ -281,8 +278,8 @@ import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._
object app extends ScalaModule with RouterModule {
def playVersion= T{"2.8.16"}
def scalaVersion= T{"2.13.8"}
def playVersion = T{ "2.8.20" }
def scalaVersion = T { "2.13.12" }
}
----

Expand Down Expand Up @@ -336,7 +333,7 @@ import mill.scalalib._
import $ivy.`com.lihaoyi::mill-contrib-playlib:$MILL_VERSION`, mill.playlib._
object app extends ScalaModule with RouterModule {
def playVersion = "2.8.16"
def playVersion = "2.8.20"
override def routesAdditionalImport = Seq("my.additional.stuff._", "my.other.stuff._")
}
----
14 changes: 13 additions & 1 deletion contrib/playlib/src/mill/playlib/PlayModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ trait PlayApiModule extends Dependencies with Router with Server {
case Versions.PLAY_2_6 => "3.1.3"
case Versions.PLAY_2_7 => "4.0.3"
case Versions.PLAY_2_8 => "5.1.0"
case Versions.PLAY_2_9 => "6.0.0"
case _ => "7.0.0"
}
Agg(ivy"org.scalatestplus.play::scalatestplus-play::${scalatestPlusPlayVersion}")
}
Expand All @@ -21,4 +23,14 @@ trait PlayApiModule extends Dependencies with Router with Server {
def start(args: Task[Args] = T.task(Args())) = T.command { run(args) }

}
trait PlayModule extends PlayApiModule with Static with Twirl
trait PlayModule extends PlayApiModule with Static with Twirl {
override def twirlVersion = T {
playMinorVersion() match {
case "2.6" => "1.3.16"
case "2.7" => "1.4.2"
case "2.8" => "1.5.1"
case "2.9" => "1.6.2"
case _ => "2.0.1"
}
}
}
9 changes: 8 additions & 1 deletion contrib/playlib/src/mill/playlib/RouterModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ trait RouterModule extends ScalaModule with Version {
def routerClasspath: T[Agg[PathRef]] = T {
resolveDeps(T.task {
val bind = bindDependency()
Agg(ivy"com.typesafe.play::routes-compiler:${playVersion()}").map(bind)
playMinorVersion() match {
case "2.6" | "2.7" | "2.8" =>
Agg(ivy"com.typesafe.play::routes-compiler:${playVersion()}").map(bind)
case "2.9" =>
Agg(ivy"com.typesafe.play::play-routes-compiler:${playVersion()}").map(bind)
case _ =>
Agg(ivy"org.playframework::play-routes-compiler:${playVersion()}").map(bind)
}
})()
}

Expand Down
8 changes: 6 additions & 2 deletions contrib/playlib/src/mill/playlib/Version.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ private[playlib] trait Version extends Module {
def playVersion: T[String]

private[playlib] def playMinorVersion: T[String] = T {
playVersion().split("\\.").take(2).mkString(".")
playVersion().split('.').take(2).mkString(".")
}

private[playlib] def playOrganization: T[String] = T.task {
if (playVersion().startsWith("2.")) "com.typesafe.play" else "org.playframework"
}

private[playlib] def component(id: String) = T.task {
ivy"com.typesafe.play::$id::${playVersion()}"
ivy"${playOrganization()}::$id::${playVersion()}"
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
GET / controllers.HomeController.index
GET / controllers.HomeController.index()
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
-> /sub sub.Routes
2 changes: 1 addition & 1 deletion contrib/playlib/test/resources/invalid/core/routes/routes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GET / controllers.HomeController.index
GET / controllers.HomeController.index()
-> /sub sub.Routes
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
BOB =error controllers.HomeController.error(foo)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GET / controllers.HomeController.index
GET / controllers.HomeController.index()
-> /sub sub.Routes
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
BOB =error controllers.HomeController.error(foo)
2 changes: 1 addition & 1 deletion contrib/playlib/test/resources/playmulti/core/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ~~~~

# An example controller showing a sample home page
GET / controllers.HomeController.index
GET / controllers.HomeController.index()

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
2 changes: 1 addition & 1 deletion contrib/playlib/test/resources/playsingle/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ~~~~

# An example controller showing a sample home page
GET / controllers.HomeController.index
GET / controllers.HomeController.index()

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
2 changes: 1 addition & 1 deletion contrib/playlib/test/resources/playsingleapi/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ~~~~

# An example controller showing a sample home page
GET / controllers.HomeController.index
GET / controllers.HomeController.index()

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
75 changes: 39 additions & 36 deletions contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ object PlayModuleTests extends TestSuite with PlayTestSuite {
val (crossScalaVersion, crossPlayVersion) = (crossValue, crossValue2)
override def playVersion = crossPlayVersion
override def scalaVersion = crossScalaVersion
override def twirlVersion = "1.5.1"
override def twirlScalaVersion = sys.props.getOrElse("MILL_SCALA_2_13_VERSION", ???)
object test extends PlayTests
override def ivyDeps = T { super.ivyDeps() ++ Agg(ws()) }
}
Expand Down Expand Up @@ -77,41 +75,46 @@ object PlayModuleTests extends TestSuite with PlayTestSuite {
}
test("compile") {
matrix.foreach { case (scalaVersion, playVersion) =>
workspaceTest(playmulti) { eval =>
val eitherResult = eval.apply(playmulti.core(scalaVersion, playVersion).compile)
val Right((result, evalCount)) = eitherResult
val outputFiles = os.walk(result.classes.path).filter(os.isFile)
val expectedClassfiles = Seq[os.RelPath](
os.RelPath("controllers/HomeController.class"),
os.RelPath("controllers/ReverseAssets.class"),
os.RelPath("controllers/ReverseHomeController.class"),
os.RelPath("controllers/routes.class"),
os.RelPath("controllers/routes$javascript.class"),
os.RelPath("controllers/javascript/ReverseHomeController.class"),
os.RelPath("controllers/javascript/ReverseAssets.class"),
os.RelPath("router/Routes$$anonfun$routes$1.class"),
os.RelPath("router/Routes.class"),
os.RelPath("router/RoutesPrefix$.class"),
os.RelPath("router/RoutesPrefix.class"),
os.RelPath("views/html/index$.class"),
os.RelPath("views/html/index.class"),
os.RelPath("views/html/main$.class"),
os.RelPath("views/html/main.class")
).map(
eval.outPath / "core" / scalaVersion / playVersion / "compile.dest" / "classes" / _
)
assert(
result.classes.path == eval.outPath / "core" / scalaVersion / playVersion / "compile.dest" / "classes",
outputFiles.nonEmpty,
outputFiles.forall(expectedClassfiles.contains),
outputFiles.size == 15,
evalCount > 0
)
skipUnsupportedVersions(playVersion) {
workspaceTest(playmulti) { eval =>
val eitherResult = eval.apply(playmulti.core(scalaVersion, playVersion).compile)
val Right((result, evalCount)) = eitherResult
val outputClassFiles =
os.walk(result.classes.path).filter(f => os.isFile(f) && f.ext == "class")

// don't recompile if nothing changed
val Right((_, unchangedEvalCount)) =
eval.apply(playmulti.core(scalaVersion, playVersion).compile)
assert(unchangedEvalCount == 0)
val expectedClassfiles = Seq[os.RelPath](
os.RelPath("controllers/HomeController.class"),
os.RelPath("controllers/ReverseAssets.class"),
os.RelPath("controllers/ReverseHomeController.class"),
os.RelPath("controllers/routes.class"),
os.RelPath("controllers/routes$javascript.class"),
os.RelPath("controllers/javascript/ReverseHomeController.class"),
os.RelPath("controllers/javascript/ReverseAssets.class"),
if (scalaVersion.startsWith("3.")) os.RelPath("router/Routes$$anon$1.class")
else os.RelPath("router/Routes$$anonfun$routes$1.class"),
os.RelPath("router/Routes.class"),
os.RelPath("router/RoutesPrefix$.class"),
os.RelPath("router/RoutesPrefix.class"),
os.RelPath("views/html/index$.class"),
os.RelPath("views/html/index.class"),
os.RelPath("views/html/main$.class"),
os.RelPath("views/html/main.class")
).map(
eval.outPath / "core" / scalaVersion / playVersion / "compile.dest" / "classes" / _
)
assert(
result.classes.path == eval.outPath / "core" / scalaVersion / playVersion / "compile.dest" / "classes",
outputClassFiles.nonEmpty,
outputClassFiles.forall(expectedClassfiles.contains),
outputClassFiles.size == 15,
evalCount > 0
)

// don't recompile if nothing changed
val Right((_, unchangedEvalCount)) =
eval.apply(playmulti.core(scalaVersion, playVersion).compile)
assert(unchangedEvalCount == 0)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ object PlaySingleApiModuleTests extends TestSuite with PlayTestSuite {

object playsingleapi extends TestUtil.BaseModule with PlayApiModule with SingleModule {
override def playVersion = T { testPlay28 }
def twirlVersion = T { "1.5.1" }
override def scalaVersion = T { "2.13.8" }
override def scalaVersion = T { "2.13.12" }
object test extends PlayTests
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ object PlaySingleModuleTests extends TestSuite with PlayTestSuite {

object playsingle extends TestUtil.BaseModule with PlayModule with SingleModule {
override def playVersion = T { testPlay28 }
override def twirlVersion = T { "1.5.1" }
override def twirlScalaVersion: T[String] =
T { sys.props.getOrElse("MILL_SCALA_2_13_VERSION", ???) }
override def scalaVersion = T { sys.props.getOrElse("MILL_SCALA_2_13_VERSION", ???) }
override def scalaVersion = T { sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) }
object test extends PlayTests
}

Expand Down
Loading

0 comments on commit d7859ca

Please sign in to comment.