From 9b9decbca0046bf3b2dce023e555b90e14725cbf Mon Sep 17 00:00:00 2001 From: Mathieu Pichette Date: Sat, 13 Jun 2020 18:51:52 -0700 Subject: [PATCH] Add support for play 2.8 and scala 2.13 --- .gitignore | 1 + .scalafmt.conf | 4 +- build.sbt | 74 ++++++++++++------- .../sttp/play/PlayWSClientBackend.scala | 24 +++--- common/src/test/resources/logback-test.xml | 10 +++ .../sttp/play/PlayWsClientBackendTest.scala | 9 ++- project/Dependencies.scala | 28 ------- project/build.properties | 2 +- project/plugins.sbt | 2 +- 9 files changed, 81 insertions(+), 73 deletions(-) create mode 100644 common/src/test/resources/logback-test.xml delete mode 100644 project/Dependencies.scala diff --git a/.gitignore b/.gitignore index a932397..545c6d1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ target/ .bloop .metals +.idea diff --git a/.scalafmt.conf b/.scalafmt.conf index 9c689ab..b99a2b6 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,2 +1,2 @@ -version = "2.0.1" -maxColumn = 120 \ No newline at end of file +version = 2.5.3 +maxColumn = 120 diff --git a/build.sbt b/build.sbt index 3638578..65bf321 100644 --- a/build.sbt +++ b/build.sbt @@ -1,18 +1,19 @@ -import Dependencies._ - lazy val root: Project = (project in file(".")) .settings( publishArtifact := false, publishLocal := {}, publish := {} ) - .aggregate(play26Project, play27Project) + .aggregate( + play26Project, + play27Project, + play28Project + ) val commonSettings: Seq[Def.Setting[_]] = inThisBuild( List( organization := "com.ruiandrebatista", - scalaVersion := "2.12.10", - crossScalaVersions := Seq("2.11.12", "2.12.10"), + scalaVersion := "2.12.11", organizationName := "Rui Batista", startYear := Some(2018), licenses += ("Apache-2.0", new URL("https://www.apache.org/licenses/LICENSE-2.0.txt")), @@ -25,31 +26,54 @@ val commonSettings: Seq[Def.Setting[_]] = inThisBuild( url("http://www.ruiandrebatista.com") ) ) - )) ++ Seq( + ) +) ++ Seq( scalaSource in Compile := (LocalProject("root") / baseDirectory).value / "common" / "src" / "main" / "scala", scalaSource in Test := (LocalProject("root") / baseDirectory).value / "common" / "src" / "test" / "scala", - libraryDependencies ++= Seq( - sttpCore, - (sttpCore classifier "tests") % Test, - scalatest % Test, - akkaHttp % Test, - akkaStreams % Test, - akkaHttpCors % Test + unmanagedResourceDirectories in Test ++= Seq( + (LocalProject("root") / baseDirectory).value / "common" / "src" / "test" / "resources" ), - addCompilerPlugin("org.spire-math" % "kind-projector" % kindProjectorVersion cross CrossVersion.binary) + fork in Test := true, + libraryDependencies ++= Seq( + "com.softwaremill.sttp.client" %% "core" % "2.0.0-RC2", + ("com.softwaremill.sttp.client" %% "core" % "2.0.0-RC2" classifier "tests") % Test, + "org.scalatest" %% "scalatest" % "3.0.8" % Test, + "com.typesafe.akka" %% "akka-http" % "10.1.8" % Test, + "com.typesafe.akka" %% "akka-stream" % "2.5.31" % Test, + "ch.megard" %% "akka-http-cors" % "0.4.2" % Test, + "ch.qos.logback" % "logback-classic" % "1.2.3" % Test + ) ) -def sttpPlayWsProject(playVersion: String, sufix: String, id: String) = - Project(id = id, base = file(id)) - .settings(commonSettings: _*) - .settings( - name := s"sttp-play-ws-$sufix", - libraryDependencies ++= playWsDependencies(playVersion) +lazy val play26Project = Project("play26", file("play26")) + .settings(commonSettings) + .settings( + name := "sttp-play-ws-26", + crossScalaVersions := Seq("2.11.12", "2.12.11"), + libraryDependencies ++= Seq( + "com.typesafe.play" %% "play-ws" % "2.6.23", + "com.typesafe.play" %% "play-ahc-ws" % "2.6.23" ) + ) +lazy val play27Project = Project("play27", file("play27")) + .settings(commonSettings) + .settings( + name := "sttp-play-ws-27", + crossScalaVersions := Seq("2.11.12", "2.12.11", "2.13.2"), + libraryDependencies ++= Seq( + "com.typesafe.play" %% "play-ws" % "2.7.5", + "com.typesafe.play" %% "play-ahc-ws" % "2.7.5" + ) + ) -lazy val play26Project = sttpPlayWsProject(play26Version, "26", "play26") -lazy val play27Project = sttpPlayWsProject(play27Version, "27", "play27") - - - +lazy val play28Project = Project("play28", file("play28")) + .settings(commonSettings) + .settings( + name := "sttp-play-ws-28", + crossScalaVersions := Seq("2.12.10", "2.13.2"), + libraryDependencies ++= Seq( + "com.typesafe.play" %% "play-ws" % "2.8.2", + "com.typesafe.play" %% "play-ahc-ws" % "2.8.2" + ) + ) diff --git a/common/src/main/scala/com/ruiandrebatista/sttp/play/PlayWSClientBackend.scala b/common/src/main/scala/com/ruiandrebatista/sttp/play/PlayWSClientBackend.scala index 355625a..dfeba71 100644 --- a/common/src/main/scala/com/ruiandrebatista/sttp/play/PlayWSClientBackend.scala +++ b/common/src/main/scala/com/ruiandrebatista/sttp/play/PlayWSClientBackend.scala @@ -35,13 +35,15 @@ import play.api.libs.ws.ahc.AhcWSClient import scala.concurrent.{ExecutionContext, Future} - -final class PlayWSClientBackend private (wsClient: WSClient, mustCloseClient: Boolean, backendOptions: SttpBackendOptions)( - implicit ec: ExecutionContext, +final class PlayWSClientBackend private ( + wsClient: WSClient, + mustCloseClient: Boolean, + backendOptions: SttpBackendOptions +)(implicit + ec: ExecutionContext, mat: Materializer ) extends SttpBackend[Future, Source[ByteString, Any], NothingT] { - private val maybeProxyServer = backendOptions.proxy.map { sttpProxy => DefaultWSProxyServer(sttpProxy.host, sttpProxy.port, if (sttpProxy.port == 443) Some("https") else None) } @@ -110,9 +112,10 @@ final class PlayWSClientBackend private (wsClient: WSClient, mustCloseClient: Bo MultipartFormData.FilePart(part.name, part.fileName.getOrElse(""), part.contentType orElse ct, source) } - def nameWithFilename = part.fileName.fold(part.name) { fn => - s"""${part.name}"; filename="$fn""" - } + def nameWithFilename = + part.fileName.fold(part.name) { fn => + s"""${part.name}"; filename="$fn""" + } part.body match { case StringBody(s, _, _) => @@ -187,7 +190,6 @@ final class PlayWSClientBackend private (wsClient: WSClient, mustCloseClient: Bo Future(wsClient.close()) else Future.successful(()) - private def saveFile(file: File, response: StandaloneWSResponse) = { if (!file.exists()) { @@ -200,11 +202,9 @@ final class PlayWSClientBackend private (wsClient: WSClient, mustCloseClient: Bo override val responseMonad: MonadError[Future] = new FutureMonad - - override def openWebsocket[T, WS_RESULT]( - request: Request[T,Source[ByteString,Any]], - handler: NothingT[WS_RESULT] + request: Request[T, Source[ByteString, Any]], + handler: NothingT[WS_RESULT] ): Future[WebSocketResponse[WS_RESULT]] = ??? } diff --git a/common/src/test/resources/logback-test.xml b/common/src/test/resources/logback-test.xml new file mode 100644 index 0000000..f8dd5fb --- /dev/null +++ b/common/src/test/resources/logback-test.xml @@ -0,0 +1,10 @@ + + + + %d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n + + + + + + diff --git a/common/src/test/scala/com/ruiandrebatista/sttp/play/PlayWsClientBackendTest.scala b/common/src/test/scala/com/ruiandrebatista/sttp/play/PlayWsClientBackendTest.scala index 46ea780..9245ae5 100644 --- a/common/src/test/scala/com/ruiandrebatista/sttp/play/PlayWsClientBackendTest.scala +++ b/common/src/test/scala/com/ruiandrebatista/sttp/play/PlayWsClientBackendTest.scala @@ -6,9 +6,10 @@ import akka.stream.ActorMaterializer import sttp.client._ import sttp.client.testing._ -import scala.concurrent.Future +import scala.concurrent.duration._ +import scala.concurrent.{Await, Future} -class PlayWsStandaloneClientHttpTest extends HttpTest[Future] { +class PlayWsClientBackendTest extends HttpTest[Future] { implicit private val system = ActorSystem() implicit private val mat = ActorMaterializer() @@ -17,8 +18,8 @@ class PlayWsStandaloneClientHttpTest extends HttpTest[Future] { override implicit val convertToFuture: ConvertToFuture[Future] = ConvertToFuture.future - override def afterAll() = { - system.terminate() + override def afterAll(): Unit = { super.afterAll() + Await.result(system.terminate(), 5.seconds) } } diff --git a/project/Dependencies.scala b/project/Dependencies.scala deleted file mode 100644 index 50a3cb4..0000000 --- a/project/Dependencies.scala +++ /dev/null @@ -1,28 +0,0 @@ -import sbt._ - -object Dependencies { - - lazy val sttpCore = "com.softwaremill.sttp.client" %% "core" % sttpVersion - def playWs(playVersion: String) = "com.typesafe.play" %% "play-ws" % playVersion - def playAhcWs(playVersion: String) = "com.typesafe.play" %% "play-ahc-ws" % playVersion - - def playWsDependencies(playVersion: String) = Seq(playWs(playVersion), playAhcWs(playVersion)) - - lazy val scalatest = "org.scalatest" %% "scalatest" % scalatestVersion - - // Akka hhttp deps - lazy val akkaHttp = "com.typesafe.akka" %% "akka-http" % akkaHttpVersion - lazy val akkaStreams = "com.typesafe.akka" %% "akka-stream" % akkaStreamsVersion - lazy val akkaHttpCors = "ch.megard" %% "akka-http-cors" % akkaHttpCorsVersion - - val sttpVersion = "2.0.0-RC2" - val play26Version = "2.6.23" - val play27Version = "2.7.2" - - val scalatestVersion = "3.0.5" - val akkaHttpCorsVersion = "0.4.0" - val akkaHttpVersion = "10.1.8" - val akkaStreamsVersion = "2.5.19" - val kindProjectorVersion = "0.9.7" - -} diff --git a/project/build.properties b/project/build.properties index c0bab04..a919a9b 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.2.8 +sbt.version=1.3.8 diff --git a/project/plugins.sbt b/project/plugins.sbt index c3a2223..3a4650d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,4 @@ -addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.0") addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.0.0")