Skip to content

Commit

Permalink
Merge pull request #11740 from mkurz/activate_Scala3
Browse files Browse the repository at this point in the history
Activate Scala 3 on CI
  • Loading branch information
mkurz committed Apr 3, 2023
2 parents b58df09 + acf6af8 commit b85cd5d
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 32 deletions.
38 changes: 12 additions & 26 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
uses: playframework/.github/.github/workflows/cmd.yml@v3
with:
java: 17, 11
scala: 2.13.x
scala: 2.13.x, 3.x
add-dimensions: >-
{
"sbt_test_task": [ "test", "Play-Integration-Test/It/test", "Play-Microbenchmark/jmh:run -i 1 -wi 0 -f 1 -t 1 -foe=true" ]
Expand All @@ -116,7 +116,10 @@ jobs:
if [ "$MATRIX_JAVA" = 17 ]; then
export JAVA_TOOL_OPTIONS="$JAVA_TOOL_OPTIONS --add-exports=java.base/sun.security.x509=ALL-UNNAMED --add-opens=java.base/sun.security.ssl=ALL-UNNAMED";
fi;
sbt "${{needs.extra-vars.outputs.akka_version_opts}}" "${{needs.extra-vars.outputs.akka_http_version_opts}}" ++$MATRIX_SCALA "$MATRIX_SBT_TEST_TASK"
if [ "$MATRIX_SCALA" = "3.x" ]; then
export PLAY_SCALA3_TESTS="-Dscala3Tests=true"
fi;
sbt "${{needs.extra-vars.outputs.akka_version_opts}}" "${{needs.extra-vars.outputs.akka_http_version_opts}}" $PLAY_SCALA3_TESTS ++$MATRIX_SCALA "$MATRIX_SBT_TEST_TASK"
docs-tests:
name: Docs Tests
Expand All @@ -128,12 +131,16 @@ jobs:
uses: playframework/.github/.github/workflows/cmd.yml@v3
with:
java: 17, 11
scala: 2.13.x
scala: 2.13.x, 3.x
exclude: >-
[
{ "java": "${{ github.event_name == 'schedule' || '17' }}" }
]
cmd: cd documentation && sbt "${{needs.extra-vars.outputs.akka_version_opts}}" "${{needs.extra-vars.outputs.akka_http_version_opts}}" ++$MATRIX_SCALA test
cmd: >-
if [ "$MATRIX_SCALA" = "3.x" ]; then
export PLAY_SCALA3_TESTS="-Dscala3Tests=true"
fi;
cd documentation && sbt "${{needs.extra-vars.outputs.akka_version_opts}}" "${{needs.extra-vars.outputs.akka_http_version_opts}}" $PLAY_SCALA3_TESTS ++$MATRIX_SCALA test
scripted-tests:
name: Scripted Tests
Expand All @@ -143,7 +150,7 @@ jobs:
uses: playframework/.github/.github/workflows/cmd.yml@v3
with:
java: 17, 11
scala: 2.13.x
scala: 2.13.x, 3.x
add-dimensions: >-
{
"sbt": [ "1.8.2" ],
Expand All @@ -170,27 +177,6 @@ jobs:
cache-path: ~/.ivy2/local/com.typesafe.play
cache-key: play-published-local-jdk{0}-${{ github.sha }}-${{ github.event_name != 'schedule' || github.run_id }}

scala3-compilation:
name: Build with Scala3
uses: playframework/.github/.github/workflows/cmd.yml@v3
with:
java: 11
scala: 3.x
# as we progress we should add here the modules that are ready for compilation
# with Scala 3
# sbt "-Dscala.version=$SCALA_VERSION
# Play / compile
# Play / Test / compile
# "
cmd: >-
sbt -Dscala.version=$MATRIX_SCALA scalaVersion "
Play / scalafmtCheckAll;
Play / test;
Play-Streams / scalafmtCheckAll;
Sbt-Routes-Compiler / test;
Play-Streams / test;
"
finish:
name: Finish
if: github.event_name == 'pull_request'
Expand Down
10 changes: 7 additions & 3 deletions core/play/src/main/scala/play/core/parsers/Multipart.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,19 @@ object Multipart {
case FileInfo(partName, filename, contentType, dispositionType) =>
val tempFile = temporaryFileCreator.create("multipartBody", "asTemporaryFile")
Accumulator(FileIO.toPath(tempFile.path)).mapFuture {
case IOResult(_, Failure(error)) => Future.failed(error)
case IOResult(count, _) =>
// Can't use unapply in Scala 3 here as long as we use the .cross(CrossVersion.for3Use2_13) workaround for akka-http
// That's because Scala 3 changed the unapply signature/behaviour and here we try to call unapply of a Scala 2 artifacts
// from a Scala 3 artifact, which results in:
// [error] java.lang.NoSuchMethodError: 'akka.stream.IOResult akka.stream.IOResult$.unapply(akka.stream.IOResult)'
case r: IOResult if r.status.isFailure => Future.failed(r.status.failed.get)
case r: IOResult if r.status.isSuccess =>
Future.successful(
FilePart(
partName,
filename,
contentType,
tempFile,
count,
r.count,
dispositionType,
tf => Some(ByteString.fromArray(java.nio.file.Files.readAllBytes(tf.path)))
)
Expand Down
8 changes: 6 additions & 2 deletions documentation/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ lazy val main = Project("Play-Documentation", file("."))
.enablePlugins(PlayDocsPlugin, SbtTwirl)
.settings(
// Avoid the use of deprecated APIs in the docs
scalacOptions ++= Seq("-deprecation"),
scalacOptions ++= Seq("-deprecation") ++
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("-Xsource:3")
case _ => Seq.empty
}),
javacOptions ++= Seq(
"-encoding",
"UTF-8",
Expand Down Expand Up @@ -75,7 +79,7 @@ lazy val main = Project("Play-Documentation", file("."))
Test / unmanagedResourceDirectories ++= (baseDirectory.value / "manual" / "detailedTopics" ** "code").get,
// Don't include sbt files in the resources
Test / unmanagedResources / excludeFilter := (Test / unmanagedResources / excludeFilter).value || "*.sbt",
crossScalaVersions := Seq("2.13.10"),
crossScalaVersions := Seq("2.13.10", "3.3.0-RC3"),
scalaVersion := "2.13.10",
Test / fork := true,
Test / javaOptions ++= Seq("-Xmx512m", "-Xms128m"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ class JavaErrorHandling extends PlaySpecification with WsTestClient {
"java error handling" should {
"allow providing a custom error handler" in new WithServer(fakeApp[javaguide.application.root.ErrorHandler]) {
override def running() = {
import play.api.libs.ws.DefaultBodyReadables.readableAsString
await(wsUrl("/error").get()).body must startWith("A server error occurred: ")
}
}

"allow providing a custom error handler" in new WithServer(fakeApp[ErrorHandler]) {
override def running() = {
import play.api.libs.ws.DefaultBodyReadables.readableAsString
(await(wsUrl("/error").get()).body must not).startWith("A server error occurred: ")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class ScalaAkkaEmbeddingPlay extends Specification with WsTestClient {
}

def testRequest(port: Int) = {
import play.api.libs.ws.DefaultBodyReadables.readableAsString
withClient { client => Await.result(client.url("/hello/world").get(), Duration.Inf).body must_== "Hello world" }(
new play.api.http.Port(port)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class ScalaNettyEmbeddingPlay extends Specification with WsTestClient {
}

def testRequest(port: Int) = {
import play.api.libs.ws.DefaultBodyReadables.readableAsString
withClient { client => Await.result(client.url("/hello/world").get(), Duration.Inf).body must_== "Hello world" }(
new play.api.http.Port(port)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ScalaErrorHandling extends PlaySpecification with WsTestClient {
"scala error handling" should {
"allow providing a custom error handler" in new WithServer(fakeApp[root.ErrorHandler]) {
override def running() = {
import play.api.libs.ws.DefaultBodyReadables.readableAsString
await(wsUrl("/error").get()).body must_== "A server error occurred: foo"
}
}
Expand Down
31 changes: 31 additions & 0 deletions project/BuildSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,37 @@ object BuildSettings {
ProblemFilters.exclude[ReversedMissingMethodProblem](
"play.api.routing.sird.QueryStringParameterExtractor.unapplySeq"
),
// Needed for 2.13 because of the -Xsource:3 scalac option; not sure why MiMa complains here, the methods still
// are available, maybe bytecode is slightly different, but source compatibility should be the same
ProblemFilters.exclude[DirectMissingMethodProblem]("controllers.AssetsModule.bindings"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.db.evolutions.SimpleEvolutionsReader.evolutions"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.http.HttpEntity#Chunked.as"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.http.HttpEntity#Chunked.asJava"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.http.HttpEntity#Chunked.contentLength"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.http.HttpEntity#Streamed.as"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.http.HttpEntity#Streamed.asJava"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.http.HttpEntity#Strict.as"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.http.HttpEntity#Strict.asJava"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.http.HttpEntity#Strict.contentLength"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.i18n.I18nModule.bindings"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.inject.guice.FakeRoutes.withPrefix"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.inject.SimpleModule.bindings"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.test.HttpsServerEndpointRecipe.withDescription"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.api.test.HttpsServerEndpointRecipe.withServerProvider"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.core.j.JavaRouterAdapter.withPrefix"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"play.core.server.common.ServerResultUtils#DefaultClose.header"
),
ProblemFilters.exclude[DirectMissingMethodProblem](
"play.core.server.common.ServerResultUtils#DefaultKeepAlive.header"
),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.core.server.common.ServerResultUtils#SendClose.header"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"play.core.server.common.ServerResultUtils#SendKeepAlive.header"
),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.core.server.NettyServerProvider.createServer"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.filters.cors.CORSFilter.logger"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.filters.csrf.CSRFModule.bindings"),
),
(Compile / unmanagedSourceDirectories) += {
val suffix = CrossVersion.partialVersion(scalaVersion.value) match {
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ val webjarsLocatorCore = "0.52"
val sbtHeader = "5.8.0"
val scalafmt = "2.4.6"
val sbtTwirl: String = sys.props.getOrElse("twirl.version", "1.6.0-RC2") // sync with documentation/project/plugins.sbt
val interplay: String = sys.props.getOrElse("interplay.version", "3.1.0-RC8")
val interplay: String = sys.props.getOrElse("interplay.version", "3.1.0-RC10")

buildInfoKeys := Seq[BuildInfoKey](
"sbtNativePackagerVersion" -> sbtNativePackager,
Expand Down

0 comments on commit b85cd5d

Please sign in to comment.