Skip to content

Commit

Permalink
* trying to get rid of Java 11 dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
benedeki committed Nov 4, 2024
1 parent b9bacef commit bbb1e7f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 74 deletions.
16 changes: 2 additions & 14 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ object Dependencies {
// Armeria Zio backend
lazy val sttpArmeririaZioBackend = sttpClient3Org %% "armeria-backend-zio" % Versions.sttpClient % Optional
// HttpClient Zio backend
lazy val sttpHttpClientZioBackend = sttpClient3Org %% "zio" % Versions.sttpClient % Optional
// lazy val sttpHttpClientZioBackend = sttpClient3Org %% "zio" % Versions.sttpClient % Optional TODO #298 needs Java 11 cross-build

// testing
lazy val zioTest = zioOrg %% "zio-test" % Versions.zio % Test
Expand All @@ -270,26 +270,14 @@ object Dependencies {
sttpArmeririaCatsBackend,
catsEffect,
sttpArmeririaZioBackend,
sttpHttpClientZioBackend,
// sttpHttpClientZioBackend, TODO #298 needs Java 11 cross-build
zioTest,
zioTestSbt,
zioTestJunit,
sbtJunitInterface
) ++
testDependencies ++
jsonSerdeDependencies
// "com.softwaremill.sttp.client3" %% "core" % "3.9.7",
// "com.softwaremill.sttp.client3" %% "async-http-client-backend-future" % "3.9.6",
// "com.softwaremill.sttp.client3" %% "armeria-backend-cats" % "3.9.8",
// "com.softwaremill.sttp.client3" %% "armeria-backend" % "3.9.8",
// "com.softwaremill.sttp.client3" %% "zio" % "3.9.8",
// "com.softwaremill.sttp.client3" %% "armeria-backend-zio" % "3.9.8",
// "org.typelevel" %% "cats-effect" % "3.3.14",
// "dev.zio" %% "zio" % "2.1.4",
// "dev.zio" %% "zio-interop-cats" % "23.1.0.1",
// "dev.zio" %% "zio-macros" % "2.1.4",
// "com.softwaremill.sttp.client3" %% "circe" % Versions.sttpCirceJson

}

def databaseDependencies: Seq[ModuleID] = {
Expand Down
5 changes: 5 additions & 0 deletions project/VersionAxes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ object VersionAxes {
override val idSuffix: String = directorySuffix.replaceAll("""\W+""", "_")
}

case class JavaVersionAxis(javaVersion: String) extends sbt.VirtualAxis.WeakAxis {
override val directorySuffix = s"-jdk$javaVersion"
override val idSuffix: String = directorySuffix.replaceAll("""\W+""", "_")
}

private def camelCaseToLowerDashCase(origName: String): String = {
origName
.replaceAll("([A-Z])", "-$1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,39 @@

package za.co.absa.atum.reader.server.future

import com.typesafe.config.{Config, ConfigFactory}
import scala.concurrent.{ExecutionContext, Future}
import sttp.client3.{HttpClientFutureBackend, SttpBackend}

import za.co.absa.atum.reader.server.GenericServerConnection


class HttpClientServerConnection private(serverUrl: String, closeable: Boolean)(implicit executor: ExecutionContext)
extends FutureServerConnection(serverUrl, closeable) {

def this(serverUrl: String)(implicit executor: ExecutionContext) = {
this(serverUrl, true)(executor)
}

def this(config: Config = ConfigFactory.load())(implicit executor: ExecutionContext) = {
this(GenericServerConnection.atumServerUrl(config))(executor)
}

override protected val backend: SttpBackend[Future, Any] = HttpClientFutureBackend()

}

object HttpClientServerConnection {
lazy implicit val serverConnection: FutureServerConnection = new HttpClientServerConnection()(ExecutionContext.Implicits.global)

def use[R](serverUrl: String)(fnc: HttpClientServerConnection => Future[R])
(implicit executor: ExecutionContext): Future[R] = {
val serverConnection = new HttpClientServerConnection(serverUrl)
try {
fnc(serverConnection)
} finally {
serverConnection.close()
}
}
}
// TODO #298 needs Java 11 cross-build
//import com.typesafe.config.{Config, ConfigFactory}
//import scala.concurrent.{ExecutionContext, Future}
//import sttp.client3.{HttpClientFutureBackend, SttpBackend}
//
//import za.co.absa.atum.reader.server.GenericServerConnection
//
//
//class HttpClientServerConnection private(serverUrl: String, closeable: Boolean)(implicit executor: ExecutionContext)
// extends FutureServerConnection(serverUrl, closeable) {
//
// def this(serverUrl: String)(implicit executor: ExecutionContext) = {
// this(serverUrl, true)(executor)
// }
//
// def this(config: Config = ConfigFactory.load())(implicit executor: ExecutionContext) = {
// this(GenericServerConnection.atumServerUrl(config))(executor)
// }
//
// override protected val backend: SttpBackend[Future, Any] = HttpClientFutureBackend()
//
//}
//
//object HttpClientServerConnection {
// lazy implicit val serverConnection: FutureServerConnection = new HttpClientServerConnection()(ExecutionContext.Implicits.global)
//
// def use[R](serverUrl: String)(fnc: HttpClientServerConnection => Future[R])
// (implicit executor: ExecutionContext): Future[R] = {
// val serverConnection = new HttpClientServerConnection(serverUrl)
// try {
// fnc(serverConnection)
// } finally {
// serverConnection.close()
// }
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,29 @@

package za.co.absa.atum.reader.server.zio

import com.typesafe.config.{Config, ConfigFactory}
import sttp.client3.{Identity, RequestT, Response}
import sttp.client3.httpclient.zio.HttpClientZioBackend
import za.co.absa.atum.reader.server.GenericServerConnection
import za.co.absa.atum.reader.server.GenericServerConnection.RequestResult
import zio.Task


class HttpClientServerConnection(serverUrl: String) extends ZioServerConnection(serverUrl) {

def this(config: Config = ConfigFactory.load()) = {
this(GenericServerConnection.atumServerUrl(config ))
}

override protected def executeRequest[R](request: RequestT[Identity, RequestResult[R], Any]): Task[Response[RequestResult[R]]] = {
HttpClientZioBackend().flatMap { backend =>
backend.send(request)
}
}

}

object HttpClientServerConnection {
lazy implicit val serverConnection: HttpClientServerConnection = new HttpClientServerConnection()
}
//TODO #298 needs Java 11 cross-build
//import com.typesafe.config.{Config, ConfigFactory}
//import sttp.client3.{Identity, RequestT, Response}
//import sttp.client3.httpclient.zio.HttpClientZioBackend
//import za.co.absa.atum.reader.server.GenericServerConnection
//import za.co.absa.atum.reader.server.GenericServerConnection.RequestResult
//import zio.Task
//
//
//class HttpClientServerConnection(serverUrl: String) extends ZioServerConnection(serverUrl) {
//
// def this(config: Config = ConfigFactory.load()) = {
// this(GenericServerConnection.atumServerUrl(config ))
// }
//
// override protected def executeRequest[R](request: RequestT[Identity, RequestResult[R], Any]): Task[Response[RequestResult[R]]] = {
// HttpClientZioBackend().flatMap { backend =>
// backend.send(request)
// }
// }
//
//}
//
//object HttpClientServerConnection {
// lazy implicit val serverConnection: HttpClientServerConnection = new HttpClientServerConnection()
//}

0 comments on commit bbb1e7f

Please sign in to comment.