Skip to content

Commit ba80a09

Browse files
authored
Merge pull request #554 from xuwei-k/run-scala-3
Scala 3
2 parents 9115c1e + 3c06b13 commit ba80a09

File tree

12 files changed

+258
-166
lines changed

12 files changed

+258
-166
lines changed

.github/workflows/build-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
uses: playframework/.github/.github/workflows/cmd.yml@v3
3939
with:
4040
java: 17, 11
41-
scala: 2.13.x
41+
scala: 3.x
4242
cmd: |
4343
# Clone generated docs so that we can run some integration tests
4444
git clone -o origin https://github.com/playframework/play-generated-docs.git $PWD/data/generated

app/controllers/Application.scala

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,18 @@ class Application @Inject() (
7474
}
7575
}
7676

77-
def widget(version: Option[String]) = Action { request =>
78-
Ok(views.html.widget(news(version)))
77+
def widget(version: Option[String]) = Action.async { request =>
78+
Future.successful(
79+
Ok(views.html.widget(news(version)))
80+
)
7981
}
8082

8183
// This used to be the download/getting-started page. We are keeping
8284
// the URL for SEO purposes only.
83-
def download = Action { implicit request =>
84-
MovedPermanently(routes.Application.gettingStarted.path)
85+
def download = Action.async { implicit request =>
86+
Future.successful(
87+
MovedPermanently(routes.Application.gettingStarted.path)
88+
)
8589
}
8690

8791
def gettingStarted = Action.async { implicit request =>
@@ -99,9 +103,11 @@ class Application @Inject() (
99103
}
100104
}
101105

102-
def allreleases(platform: Option[String] = None) = Action { implicit request =>
106+
def allreleases(platform: Option[String] = None) = Action.async { implicit request =>
103107
val selectedPlatform = Platform(platform.orElse(request.headers.get("User-Agent")))
104-
Ok(html.allreleases(releases, selectedPlatform))
108+
Future.successful(
109+
Ok(html.allreleases(releases, selectedPlatform))
110+
)
105111
}
106112

107113
def changelog =
@@ -128,7 +134,7 @@ class Application @Inject() (
128134
Redirect("https://github.com/playframework/.github/blob/main/CONTRIBUTING.md")
129135
}
130136

131-
def markdownAction(markdownFile: String, template: RequestHeader => Html => Html) = Action {
137+
def markdownAction(markdownFile: String, template: RequestHeader => Html => Html) = Action.async {
132138
implicit request =>
133139
def readInputStream(is: InputStream): String =
134140
try {
@@ -153,29 +159,41 @@ class Application @Inject() (
153159
page.foreach(cacheApi.set(markdownFile, _))
154160

155161
page match {
156-
case Some(content) => Ok(template(request)(Html(content))).withHeaders(CACHE_CONTROL -> "max-age=10000")
157-
case None => notFound
162+
case Some(content) =>
163+
Future.successful(
164+
Ok(template(request)(Html(content))).withHeaders(CACHE_CONTROL -> "max-age=10000")
165+
)
166+
case None =>
167+
Future.successful(
168+
notFound
169+
)
158170
}
159171
}
160172

161-
def getInvolved = Action { implicit request =>
162-
Ok(html.getInvolved())
173+
def getInvolved = Action.async { implicit request =>
174+
Future.successful(
175+
Ok(html.getInvolved())
176+
)
163177
}
164178

165-
def sponsors = Action { implicit request =>
166-
Ok(html.sponsors())
179+
def sponsors = Action.async { implicit request =>
180+
Future.successful(
181+
Ok(html.sponsors())
182+
)
167183
}
168184

169-
def cookie = Action { implicit request =>
170-
Ok(html.cookie())
185+
def cookie = Action.async { implicit request =>
186+
Future.successful(
187+
Ok(html.cookie())
188+
)
171189
}
172190

173191
// Deprecated links
174192
def movedTo(url: String, originalPath: String) = Action {
175193
MovedPermanently(url)
176194
}
177195

178-
def onHandlerNotFound(route: String) = Action { implicit request =>
196+
def onHandlerNotFound(route: String) = Action.async { implicit request =>
179197
if (
180198
route.startsWith("play-") && route.endsWith("-released") && !route
181199
.contains("-rc") && !route.contains("-m")
@@ -184,11 +202,17 @@ class Application @Inject() (
184202
.replace("play-", "")
185203
.replace("-released", "")
186204
.replace("-", ".")
187-
MovedPermanently(s"https://github.com/playframework/playframework/releases/tag/$version")
205+
Future.successful(
206+
MovedPermanently(s"https://github.com/playframework/playframework/releases/tag/$version")
207+
)
188208
} else if (route.endsWith("/")) {
189-
MovedPermanently("/" + request.path.take(request.path.length - 1).dropWhile(_ == '/'))
209+
Future.successful(
210+
MovedPermanently("/" + request.path.take(request.path.length - 1).dropWhile(_ == '/'))
211+
)
190212
} else {
191-
notFound
213+
Future.successful(
214+
notFound
215+
)
192216
}
193217
}
194218

app/controllers/Blog.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,22 @@ class Blog @Inject() (
2828

2929
val blogName = "Play Framework Blog"
3030

31-
def index() = Action { implicit request =>
32-
Ok(html.blog.index(blogName))
31+
def index() = Action.async { implicit request =>
32+
Future.successful(
33+
Ok(html.blog.index(blogName))
34+
)
3335
}
3436

35-
def graal() = Action { implicit request =>
36-
Ok(html.blog.graal(blogName, "Running Play on GraalVM"))
37+
def graal() = Action.async { implicit request =>
38+
Future.successful(
39+
Ok(html.blog.graal(blogName, "Running Play on GraalVM"))
40+
)
3741
}
3842

39-
def socketio() = Action { implicit request =>
40-
Ok(html.blog.socketio(blogName, "Play socket.io support"))
43+
def socketio() = Action.async { implicit request =>
44+
Future.successful(
45+
Ok(html.blog.socketio(blogName, "Play socket.io support"))
46+
)
4147
}
4248

4349
}

app/controllers/Modules.scala

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import services.modules._
88
import models.modules._
99

1010
import scala.concurrent.ExecutionContext
11+
import scala.concurrent.Future
1112

1213
@Singleton
1314
class Modules @Inject() (modulesLookup: ModulesLookup, moduleDao: ModuleDao, components: ControllerComponents)(
@@ -16,42 +17,63 @@ class Modules @Inject() (modulesLookup: ModulesLookup, moduleDao: ModuleDao, com
1617
reverseRouter: documentation.ReverseRouter,
1718
) extends AbstractController(components) {
1819

19-
def index(keyword: String) = Action { implicit request =>
20-
render {
21-
case Accepts.Html() =>
22-
Ok(views.html.modules.list(moduleDao.findAll(keyword)))
23-
case Accepts.Json() =>
24-
import Module.modulesWrites
25-
Ok(Json.toJson(moduleDao.findEverything()))
26-
}
20+
def index(keyword: String) = Action.async { implicit request =>
21+
Future.successful(
22+
render {
23+
case Accepts.Html() =>
24+
Ok(views.html.modules.list(moduleDao.findAll(keyword)))
25+
case Accepts.Json() =>
26+
import Module.modulesWrites
27+
Ok(Json.toJson(moduleDao.findEverything()))
28+
}
29+
)
2730
}
2831

29-
def download(name: String, version: String) = Action { implicit request =>
32+
def download(name: String, version: String) = Action.async { implicit request =>
3033
modulesLookup.findModule(name, version) match {
31-
case Some(zip) => Ok.sendFile(zip)
32-
case None => PageNotFound
34+
case Some(zip) =>
35+
Future.successful(
36+
Ok.sendFile(zip)
37+
)
38+
case None =>
39+
Future.successful(
40+
PageNotFound
41+
)
3342
}
3443
}
3544

36-
def documentation(name: String, version: String, page: String) = Action { implicit request =>
45+
def documentation(name: String, version: String, page: String) = Action.async { implicit request =>
3746
modulesLookup.loadModuleDocumentation(name, version, page) match {
3847
case Some(content) =>
39-
Ok(views.html.modules.documentation(name, content))
40-
case None => PageNotFound
48+
Future.successful(
49+
Ok(views.html.modules.documentation(name, content))
50+
)
51+
case None =>
52+
Future.successful(
53+
PageNotFound
54+
)
4155
}
4256
}
4357

44-
def show(name: String) = Action { implicit request =>
58+
def show(name: String) = Action.async { implicit request =>
4559
moduleDao.findById(name) match {
46-
case Some((module, releases)) => Ok(views.html.modules.show(module, releases))
47-
case None => PageNotFound
60+
case Some((module, releases)) =>
61+
Future.successful(
62+
Ok(views.html.modules.show(module, releases))
63+
)
64+
case None =>
65+
Future.successful(
66+
PageNotFound
67+
)
4868
}
4969
}
5070

51-
def dependencies(name: String, version: String) = Action { implicit request =>
71+
def dependencies(name: String, version: String) = Action.async { implicit request =>
5272
modulesLookup.findDependencies(name, version) match {
53-
case Some(yml) => Ok(yml)
54-
case None => PageNotFound
73+
case Some(yml) =>
74+
Future.successful(Ok(yml))
75+
case None =>
76+
Future.successful(PageNotFound)
5577
}
5678
}
5779

app/controllers/Outreachy.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import javax.inject.Inject
55
import play.api.mvc.AbstractController
66
import play.api.mvc.ControllerComponents
77

8+
import scala.concurrent.Future
9+
810
/**
911
* The outreachy controller
1012
*/
@@ -14,11 +16,15 @@ class Outreachy @Inject() (components: ControllerComponents)(implicit
1416

1517
//def outreachy = Action(Redirect(routes.Outreachy.round15))
1618

17-
def round10 = Action { implicit req =>
18-
Ok(views.html.outreachy.round10())
19+
def round10 = Action.async { implicit req =>
20+
Future.successful(
21+
Ok(views.html.outreachy.round10())
22+
)
1923
}
2024

21-
def round15 = Action { implicit req =>
22-
Ok(views.html.outreachy.round15())
25+
def round15 = Action.async { implicit req =>
26+
Future.successful(
27+
Ok(views.html.outreachy.round15())
28+
)
2329
}
2430
}

app/controllers/Security.scala

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,51 @@ import play.twirl.api.Html
1010
import utils.Markdown
1111
import org.apache.commons.io.IOUtils
1212
import java.io.File
13+
import scala.concurrent.Future
1314

1415
@Singleton
1516
class Security @Inject() (environment: Environment, val controllerComponents: ControllerComponents)(implicit
1617
val reverseRouter: documentation.ReverseRouter,
1718
) extends BaseController
1819
with Common {
1920

20-
def vulnerability(name: String) = Action { implicit req =>
21+
def vulnerability(name: String) = Action.async { implicit req =>
2122
val path = "public/markdown/vulnerabilities/" + name
2223

2324
// protect against dot dots
2425
if (new File("/" + path).getCanonicalPath != "/" + path) {
25-
notFound
26+
Future.successful(notFound)
2627
} else {
2728
environment
2829
.resourceAsStream(path + ".md")
2930
.map { is =>
3031
val content = IOUtils.toString(is, "utf-8")
3132

3233
try {
33-
Ok(
34-
views.html.security(
35-
"Play Framework Security Advisory",
36-
Html(Markdown.toHtml(content, link => (link, link))),
37-
),
38-
).withHeaders(CACHE_CONTROL -> "max-age=10000")
34+
Future.successful(
35+
Ok(
36+
views.html.security(
37+
"Play Framework Security Advisory",
38+
Html(Markdown.toHtml(content, link => (link, link))),
39+
),
40+
).withHeaders(CACHE_CONTROL -> "max-age=10000")
41+
)
3942
} finally {
4043
is.close()
4144
}
4245
}
43-
.getOrElse(notFound)
46+
.getOrElse(
47+
Future.successful(
48+
notFound
49+
)
50+
)
4451
}
4552
}
4653

47-
def index = Action { implicit req =>
48-
Ok(views.html.vulnerabilities()).withHeaders(CACHE_CONTROL -> "max-age=1000")
54+
def index = Action.async { implicit req =>
55+
Future.successful(
56+
Ok(views.html.vulnerabilities()).withHeaders(CACHE_CONTROL -> "max-age=1000")
57+
)
4958
}
5059

5160
}

app/controllers/documentation/DocumentationController.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class DocumentationController @Inject() (
132132

133133
def v1Page(lang: Option[Lang], v: String, page: String) = VersionAction(v) {
134134
(actor, version) => implicit req =>
135-
actorRequest(actor, page, replyTo => RenderV1Page(lang, version, etag(req), page, replyTo)) {
135+
actorRequest(actor, page, (replyTo: ActorRef[Response[RenderedPage]]) => RenderV1Page(lang, version, etag(req), page, replyTo)) {
136136
case RenderedPage(html, _, _, _, context, cacheId) =>
137137
val result = Ok(views.html.documentation.v1(messages, context, page, html))
138138
cacheable(withLangHeaders(result, page, context), cacheId)
@@ -163,7 +163,7 @@ class DocumentationController @Inject() (
163163
actorRequest(
164164
actor,
165165
category,
166-
replyTo => RenderV1Cheatsheet(lang, version, etag(req), category, replyTo),
166+
(replyTo: ActorRef[Response[V1Cheatsheet]]) => RenderV1Cheatsheet(lang, version, etag(req), category, replyTo),
167167
) { case V1Cheatsheet(sheets, title, otherCategories, context, cacheId) =>
168168
cacheable(
169169
Ok(views.html.documentation.cheatsheet(context, title, otherCategories, sheets)),
@@ -189,7 +189,7 @@ class DocumentationController @Inject() (
189189
def page(lang: Option[Lang], v: String, page: String) = VersionAction(v) { (actor, version) => implicit req =>
190190
val linkFuture = canonicalLinkHeader(page, version)
191191
val resultFuture =
192-
actorRequest(actor, page, replyTo => RenderPage(lang, version, etag(req), page, replyTo)) {
192+
actorRequest(actor, page, (replyTo: ActorRef[Response[RenderedPage]]) => RenderPage(lang, version, etag(req), page, replyTo)) {
193193
case RenderedPage(html, sidebarHtml, breadcrumbsHtml, source, context, cacheId) =>
194194
val pageTitle = HtmlHelpers.friendlyTitle(page)
195195
val result = Ok(
@@ -351,7 +351,7 @@ class DocumentationController @Inject() (
351351
home: String,
352352
) = { (lang: Option[Lang], v: String, page: String) =>
353353
VersionAction(v) { (actor, version) => implicit req =>
354-
actorRequest(actor, page, replyTo => msg(lang, version, etag(req), page, replyTo)) {
354+
actorRequest(actor, page, (replyTo: ActorRef[Response[PageExists]]) => msg(lang, version, etag(req), page, replyTo)) {
355355
case PageExists(true, cacheId) =>
356356
cacheable(TemporaryRedirect(reverseRouter.page(lang, version.name, page)), cacheId)
357357
case PageExists(false, cacheId) =>

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version := "1.0-SNAPSHOT"
33

44
enablePlugins(PlayScala)
55

6-
scalaVersion := "2.13.12"
6+
scalaVersion := "3.3.1"
77
scalacOptions ++= List("-encoding", "utf8", "-deprecation", "-feature", "-unchecked")
88

99
libraryDependencies ++= Seq(

0 commit comments

Comments
 (0)