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

Add support for play 2.8 and scala 2.13 #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
target/
.bloop
.metals
.idea
4 changes: 2 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "2.0.1"
maxColumn = 120
version = 2.5.3
maxColumn = 120
74 changes: 49 additions & 25 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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")),
Expand All @@ -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"
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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, _, _) =>
Expand Down Expand Up @@ -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()) {
Expand All @@ -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]] = ???

}
Expand Down
10 changes: 10 additions & 0 deletions common/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
}
}
28 changes: 0 additions & 28 deletions project/Dependencies.scala

This file was deleted.

2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.2.8
sbt.version=1.3.8
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")

Expand Down