Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala 3 #554

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: playframework/.github/.github/workflows/cmd.yml@v3
with:
java: 17, 11
scala: 2.13.x
scala: 3.x
cmd: |
# Clone generated docs so that we can run some integration tests
git clone -o origin https://github.com/playframework/play-generated-docs.git $PWD/data/generated
Expand Down
62 changes: 43 additions & 19 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,18 @@ class Application @Inject() (
}
}

def widget(version: Option[String]) = Action { request =>
Ok(views.html.widget(news(version)))
def widget(version: Option[String]) = Action.async { request =>
Future.successful(
Ok(views.html.widget(news(version)))
)
}

// This used to be the download/getting-started page. We are keeping
// the URL for SEO purposes only.
def download = Action { implicit request =>
MovedPermanently(routes.Application.gettingStarted.path)
def download = Action.async { implicit request =>
Future.successful(
MovedPermanently(routes.Application.gettingStarted.path)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... instead of using Action.async { ... Future.successful( ... you could have changed the implicit request to be implicit request: Request[AnyContent]

Is there a reason you choose your approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no strong reason.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok 😉

}

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

def allreleases(platform: Option[String] = None) = Action { implicit request =>
def allreleases(platform: Option[String] = None) = Action.async { implicit request =>
val selectedPlatform = Platform(platform.orElse(request.headers.get("User-Agent")))
Ok(html.allreleases(releases, selectedPlatform))
Future.successful(
Ok(html.allreleases(releases, selectedPlatform))
)
}

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

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

page match {
case Some(content) => Ok(template(request)(Html(content))).withHeaders(CACHE_CONTROL -> "max-age=10000")
case None => notFound
case Some(content) =>
Future.successful(
Ok(template(request)(Html(content))).withHeaders(CACHE_CONTROL -> "max-age=10000")
)
case None =>
Future.successful(
notFound
)
}
}

def getInvolved = Action { implicit request =>
Ok(html.getInvolved())
def getInvolved = Action.async { implicit request =>
Future.successful(
Ok(html.getInvolved())
)
}

def sponsors = Action { implicit request =>
Ok(html.sponsors())
def sponsors = Action.async { implicit request =>
Future.successful(
Ok(html.sponsors())
)
}

def cookie = Action { implicit request =>
Ok(html.cookie())
def cookie = Action.async { implicit request =>
Future.successful(
Ok(html.cookie())
)
}

// Deprecated links
def movedTo(url: String, originalPath: String) = Action {
MovedPermanently(url)
}

def onHandlerNotFound(route: String) = Action { implicit request =>
def onHandlerNotFound(route: String) = Action.async { implicit request =>
if (
route.startsWith("play-") && route.endsWith("-released") && !route
.contains("-rc") && !route.contains("-m")
Expand All @@ -184,11 +202,17 @@ class Application @Inject() (
.replace("play-", "")
.replace("-released", "")
.replace("-", ".")
MovedPermanently(s"https://github.com/playframework/playframework/releases/tag/$version")
Future.successful(
MovedPermanently(s"https://github.com/playframework/playframework/releases/tag/$version")
)
} else if (route.endsWith("/")) {
MovedPermanently("/" + request.path.take(request.path.length - 1).dropWhile(_ == '/'))
Future.successful(
MovedPermanently("/" + request.path.take(request.path.length - 1).dropWhile(_ == '/'))
)
} else {
notFound
Future.successful(
notFound
)
}
}

Expand Down
18 changes: 12 additions & 6 deletions app/controllers/Blog.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,22 @@ class Blog @Inject() (

val blogName = "Play Framework Blog"

def index() = Action { implicit request =>
Ok(html.blog.index(blogName))
def index() = Action.async { implicit request =>
Future.successful(
Ok(html.blog.index(blogName))
)
}

def graal() = Action { implicit request =>
Ok(html.blog.graal(blogName, "Running Play on GraalVM"))
def graal() = Action.async { implicit request =>
Future.successful(
Ok(html.blog.graal(blogName, "Running Play on GraalVM"))
)
}

def socketio() = Action { implicit request =>
Ok(html.blog.socketio(blogName, "Play socket.io support"))
def socketio() = Action.async { implicit request =>
Future.successful(
Ok(html.blog.socketio(blogName, "Play socket.io support"))
)
}

}
62 changes: 42 additions & 20 deletions app/controllers/Modules.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import services.modules._
import models.modules._

import scala.concurrent.ExecutionContext
import scala.concurrent.Future

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

def index(keyword: String) = Action { implicit request =>
render {
case Accepts.Html() =>
Ok(views.html.modules.list(moduleDao.findAll(keyword)))
case Accepts.Json() =>
import Module.modulesWrites
Ok(Json.toJson(moduleDao.findEverything()))
}
def index(keyword: String) = Action.async { implicit request =>
Future.successful(
render {
case Accepts.Html() =>
Ok(views.html.modules.list(moduleDao.findAll(keyword)))
case Accepts.Json() =>
import Module.modulesWrites
Ok(Json.toJson(moduleDao.findEverything()))
}
)
}

def download(name: String, version: String) = Action { implicit request =>
def download(name: String, version: String) = Action.async { implicit request =>
modulesLookup.findModule(name, version) match {
case Some(zip) => Ok.sendFile(zip)
case None => PageNotFound
case Some(zip) =>
Future.successful(
Ok.sendFile(zip)
)
case None =>
Future.successful(
PageNotFound
)
}
}

def documentation(name: String, version: String, page: String) = Action { implicit request =>
def documentation(name: String, version: String, page: String) = Action.async { implicit request =>
modulesLookup.loadModuleDocumentation(name, version, page) match {
case Some(content) =>
Ok(views.html.modules.documentation(name, content))
case None => PageNotFound
Future.successful(
Ok(views.html.modules.documentation(name, content))
)
case None =>
Future.successful(
PageNotFound
)
}
}

def show(name: String) = Action { implicit request =>
def show(name: String) = Action.async { implicit request =>
moduleDao.findById(name) match {
case Some((module, releases)) => Ok(views.html.modules.show(module, releases))
case None => PageNotFound
case Some((module, releases)) =>
Future.successful(
Ok(views.html.modules.show(module, releases))
)
case None =>
Future.successful(
PageNotFound
)
}
}

def dependencies(name: String, version: String) = Action { implicit request =>
def dependencies(name: String, version: String) = Action.async { implicit request =>
modulesLookup.findDependencies(name, version) match {
case Some(yml) => Ok(yml)
case None => PageNotFound
case Some(yml) =>
Future.successful(Ok(yml))
case None =>
Future.successful(PageNotFound)
}
}

Expand Down
14 changes: 10 additions & 4 deletions app/controllers/Outreachy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import javax.inject.Inject
import play.api.mvc.AbstractController
import play.api.mvc.ControllerComponents

import scala.concurrent.Future

/**
* The outreachy controller
*/
Expand All @@ -14,11 +16,15 @@ class Outreachy @Inject() (components: ControllerComponents)(implicit

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

def round10 = Action { implicit req =>
Ok(views.html.outreachy.round10())
def round10 = Action.async { implicit req =>
Future.successful(
Ok(views.html.outreachy.round10())
)
}

def round15 = Action { implicit req =>
Ok(views.html.outreachy.round15())
def round15 = Action.async { implicit req =>
Future.successful(
Ok(views.html.outreachy.round15())
)
}
}
31 changes: 20 additions & 11 deletions app/controllers/Security.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,51 @@ import play.twirl.api.Html
import utils.Markdown
import org.apache.commons.io.IOUtils
import java.io.File
import scala.concurrent.Future

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

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

// protect against dot dots
if (new File("/" + path).getCanonicalPath != "/" + path) {
notFound
Future.successful(notFound)
} else {
environment
.resourceAsStream(path + ".md")
.map { is =>
val content = IOUtils.toString(is, "utf-8")

try {
Ok(
views.html.security(
"Play Framework Security Advisory",
Html(Markdown.toHtml(content, link => (link, link))),
),
).withHeaders(CACHE_CONTROL -> "max-age=10000")
Future.successful(
Ok(
views.html.security(
"Play Framework Security Advisory",
Html(Markdown.toHtml(content, link => (link, link))),
),
).withHeaders(CACHE_CONTROL -> "max-age=10000")
)
} finally {
is.close()
}
}
.getOrElse(notFound)
.getOrElse(
Future.successful(
notFound
)
)
}
}

def index = Action { implicit req =>
Ok(views.html.vulnerabilities()).withHeaders(CACHE_CONTROL -> "max-age=1000")
def index = Action.async { implicit req =>
Future.successful(
Ok(views.html.vulnerabilities()).withHeaders(CACHE_CONTROL -> "max-age=1000")
)
}

}
8 changes: 4 additions & 4 deletions app/controllers/documentation/DocumentationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class DocumentationController @Inject() (

def v1Page(lang: Option[Lang], v: String, page: String) = VersionAction(v) {
(actor, version) => implicit req =>
actorRequest(actor, page, replyTo => RenderV1Page(lang, version, etag(req), page, replyTo)) {
actorRequest(actor, page, (replyTo: ActorRef[Response[RenderedPage]]) => RenderV1Page(lang, version, etag(req), page, replyTo)) {
case RenderedPage(html, _, _, _, context, cacheId) =>
val result = Ok(views.html.documentation.v1(messages, context, page, html))
cacheable(withLangHeaders(result, page, context), cacheId)
Expand Down Expand Up @@ -163,7 +163,7 @@ class DocumentationController @Inject() (
actorRequest(
actor,
category,
replyTo => RenderV1Cheatsheet(lang, version, etag(req), category, replyTo),
(replyTo: ActorRef[Response[V1Cheatsheet]]) => RenderV1Cheatsheet(lang, version, etag(req), category, replyTo),
) { case V1Cheatsheet(sheets, title, otherCategories, context, cacheId) =>
cacheable(
Ok(views.html.documentation.cheatsheet(context, title, otherCategories, sheets)),
Expand All @@ -189,7 +189,7 @@ class DocumentationController @Inject() (
def page(lang: Option[Lang], v: String, page: String) = VersionAction(v) { (actor, version) => implicit req =>
val linkFuture = canonicalLinkHeader(page, version)
val resultFuture =
actorRequest(actor, page, replyTo => RenderPage(lang, version, etag(req), page, replyTo)) {
actorRequest(actor, page, (replyTo: ActorRef[Response[RenderedPage]]) => RenderPage(lang, version, etag(req), page, replyTo)) {
case RenderedPage(html, sidebarHtml, breadcrumbsHtml, source, context, cacheId) =>
val pageTitle = HtmlHelpers.friendlyTitle(page)
val result = Ok(
Expand Down Expand Up @@ -351,7 +351,7 @@ class DocumentationController @Inject() (
home: String,
) = { (lang: Option[Lang], v: String, page: String) =>
VersionAction(v) { (actor, version) => implicit req =>
actorRequest(actor, page, replyTo => msg(lang, version, etag(req), page, replyTo)) {
actorRequest(actor, page, (replyTo: ActorRef[Response[PageExists]]) => msg(lang, version, etag(req), page, replyTo)) {
case PageExists(true, cacheId) =>
cacheable(TemporaryRedirect(reverseRouter.page(lang, version.name, page)), cacheId)
case PageExists(false, cacheId) =>
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version := "1.0-SNAPSHOT"

enablePlugins(PlayScala)

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

libraryDependencies ++= Seq(
Expand Down
Loading
Loading