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

Cross-compile for Scala 3 #227

Merged
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ jobs:
strategy:
matrix:
scala:
- 2.13.8
- 2.12.17
- 2.13.13
- 2.12.19
- 3.3.3

steps:
- uses: actions/checkout@v3
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ project/plugins/project/
*.ipr

# Mac
.DS_Store
.DS_Store

# Metals/Bloop/Vscode specific
.metals
metals.sbt
.bloop
.vscode
106 changes: 67 additions & 39 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,56 +1,84 @@
import Dependencies._

def crossSettings[T](scalaVersion: String, if3: List[T], if2: List[T]) =
CrossVersion.partialVersion(scalaVersion) match {
case Some((3, _)) => if3
case Some((2, 12 | 13)) => if2
case _ => Nil
}

lazy val commonSettings = Seq(
organization := "com.evolutiongaming",
homepage := Some(new URL("http://github.com/evolution-gaming/scassandra")),
startYear := Some(2018),
organizationName := "Evolution",
organizationHomepage := Some(url("http://evolution.com")),
scalaVersion := crossScalaVersions.value.head,
crossScalaVersions := Seq("2.13.8", "2.12.17"),
crossScalaVersions := Seq("2.13.13", "3.3.3", "2.12.19"),
Compile / doc / scalacOptions ++= Seq("-groups", "-implicits", "-no-link-warnings"),
publishTo := Some(Resolver.evolutionReleases),
licenses := Seq(("MIT", url("https://opensource.org/licenses/MIT"))),
releaseCrossBuild := true,
scalacOptsFailOnWarn := Some(false))
scalacOptsFailOnWarn := Some(false),
scalacOptions ++= crossSettings(
scalaVersion.value,
if3 = List("-Ykind-projector", "-language:implicitConversions", "-explain", "-deprecation"),
if2 = List("-Xsource:3"),
))

lazy val root = (project in file(".")
settings (name := "scassandra")
settings commonSettings
settings (
lazy val root = (project in file("."))
.settings(name := "scassandra")
.settings(commonSettings)
.settings(
publish / skip := true,
skip / publishArtifact := true)
aggregate(scassandra, tests))
skip / publishArtifact := true
)
.aggregate(scassandra, tests)

lazy val scassandra = (project in file("scassandra")
settings (name := "scassandra")
settings commonSettings
settings (libraryDependencies ++= Seq(
Cats.core,
Cats.effect,
`config-tools`,
`cats-helper`,
sstream,
scalatest % Test,
nel,
`cassandra-driver`,
`executor-tools`,
Pureconfig.pureconfig,
Pureconfig.cats)))
lazy val scassandra = (project in file("scassandra"))
.settings(name := "scassandra")
.settings(commonSettings)
.settings(
libraryDependencies ++= Seq(
Cats.core,
Cats.effect,
`config-tools`,
`cats-helper`,
sstream,
scalatest % Test,
nel,
`cassandra-driver`,
`executor-tools`,
Pureconfig.cats
)
)
.settings(
libraryDependencies ++= crossSettings(
scalaVersion.value,
if3 = List(Pureconfig.core),
if2 = List(Pureconfig.pureconfig),
)
)

lazy val tests = (project in file("tests")
settings (name := "tests")
settings commonSettings
settings Seq(
publish / skip := true,
skip / publishArtifact := true,
Test / fork := true,
Test / parallelExecution := false)
dependsOn scassandra % "test->test;compile->compile"
settings (libraryDependencies ++= Seq(
`cassandra-launcher` % Test,
Slf4j.api % Test,
Slf4j.`log4j-over-slf4j` % Test,
Logback.core % Test,
Logback.classic % Test,
scalatest % Test)))
lazy val tests = (project in file("tests"))
.settings(name := "tests")
.settings(commonSettings)
.settings(
Seq(
publish / skip := true,
skip / publishArtifact := true,
Test / fork := true,
Test / parallelExecution := false
)
)
.dependsOn(scassandra % "test->test;compile->compile")
.settings(
libraryDependencies ++= Seq(
`testcontainers-cassandra` % Test,
Slf4j.api % Test,
Slf4j.`log4j-over-slf4j` % Test,
Logback.core % Test,
Logback.classic % Test,
scalatest % Test
)
)
26 changes: 14 additions & 12 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@ import sbt._

object Dependencies {

val `cassandra-driver` = "com.datastax.cassandra" % "cassandra-driver-core" % "3.11.3"
val scalatest = "org.scalatest" %% "scalatest" % "3.2.17"
val `executor-tools` = "com.evolutiongaming" %% "executor-tools" % "1.0.3"
val `config-tools` = "com.evolutiongaming" %% "config-tools" % "1.0.4"
val nel = "com.evolutiongaming" %% "nel" % "1.3.4"
val `cassandra-launcher` = "com.evolutiongaming" %% "cassandra-launcher" % "0.0.4"
val `cats-helper` = "com.evolutiongaming" %% "cats-helper" % "3.2.0"
val sstream = "com.evolutiongaming" %% "sstream" % "1.0.1"
val `cassandra-driver` = "com.datastax.cassandra" % "cassandra-driver-core" % "3.11.3"
val scalatest = "org.scalatest" %% "scalatest" % "3.2.17"
val `executor-tools` = "com.evolutiongaming" %% "executor-tools" % "1.0.4"
val `config-tools` = "com.evolutiongaming" %% "config-tools" % "1.0.5"
val nel = "com.evolutiongaming" %% "nel" % "1.3.5"
val `testcontainers-cassandra` = "com.dimafeng" %% "testcontainers-scala-cassandra" % "0.40.17"
val `cats-helper` = "com.evolutiongaming" %% "cats-helper" % "3.9.0"
val sstream = "com.evolutiongaming" %% "sstream" % "1.0.2"

object Logback {
private val version = "1.4.3"
private val version = "1.4.11"
val core = "ch.qos.logback" % "logback-core" % version
val classic = "ch.qos.logback" % "logback-classic" % version
}

object Slf4j {
private val version = "1.7.36"
private val version = "2.0.9"
val api = "org.slf4j" % "slf4j-api" % version
val `log4j-over-slf4j` = "org.slf4j" % "log4j-over-slf4j" % version
}

object Cats {
val core = "org.typelevel" %% "cats-core" % "2.8.0"
val core = "org.typelevel" %% "cats-core" % "2.10.0"
val effect = "org.typelevel" %% "cats-effect" % "3.4.8"
}

object Pureconfig {
private val version = "0.17.3"
private val version = "0.17.6"

val core = "com.github.pureconfig" %% "pureconfig-core" % version
val pureconfig = "com.github.pureconfig" %% "pureconfig" % version
val cats = "com.github.pureconfig" %% "pureconfig-cats" % version
}
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11")

addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.11")

Expand Down
15 changes: 15 additions & 0 deletions scassandra/src/main/scala-3/com/evolutiongaming/util/ToJava.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.evolutiongaming.util

import scala.jdk.CollectionConverters._

object ToJava {

def from[T](collection: List[T]): java.util.Collection[T] =
collection.asJavaCollection

def from[T](set: Set[T]): java.util.Set[T] =
set.asJava

def from[A, B](map: Map[A, B]): java.util.Map[A, B] =
map.asJava
}
13 changes: 13 additions & 0 deletions scassandra/src/main/scala-3/com/evolutiongaming/util/ToScala.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.evolutiongaming.util

import scala.collection.mutable
import scala.jdk.CollectionConverters._

object ToScala {

def from[T](collection: java.util.Collection[T]): Iterable[T] =
collection.asScala

def from[A, B](map: java.util.Map[A, B]): mutable.Map[A, B] =
map.asScala
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.evolutiongaming.scassandra

import com.typesafe.config.Config
import pureconfig.{ConfigReader, ConfigSource}
import pureconfig.generic.semiauto.deriveReader
import pureconfig.ConfigSource

/**
* See [[https://docs.datastax.com/en/developer/java-driver/3.5/manual/auth/]]
*/
final case class AuthenticationConfig(username: String, password: Masked[String])

object AuthenticationConfig {

implicit val configReaderAuthenticationConfig: ConfigReader[AuthenticationConfig] = deriveReader
object AuthenticationConfig extends AuthenticationConfigImplicits {

def apply(username: String, password: String): AuthenticationConfig = {
AuthenticationConfig(username, Masked(password))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.evolutiongaming.scassandra

import com.evolutiongaming.scassandra.util.PureconfigSyntax._
import pureconfig.ConfigReader

trait AuthenticationConfigImplicits {
implicit val configReaderAuthenticationConfig: ConfigReader[AuthenticationConfig] =
ConfigReader.fromCursor[AuthenticationConfig] { cursor =>
for {
objCur <- cursor.asObjectCursor
username <- objCur.getAt[String]("username")
password <- objCur.getAt[String]("password")
} yield AuthenticationConfig(
username = username,
password = password
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object CassandraConfig {
implicit val configReaderProtocolVersion: ConfigReader[ProtocolVersion] = ConfigReaderFromEnum(ProtocolVersion.values())

implicit val configReaderCassandraConfig: ConfigReader[CassandraConfig] = {
cursor: ConfigCursor => {
(cursor: ConfigCursor) => {
for {
cursor <- cursor.asObjectCursor
} yield {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object EncodeByIdx {
}

implicit val localDateJEncodeByIdx: EncodeByIdx[LocalDateJ] = {
EncodeByIdx[LocalDate].contramap { a: LocalDateJ =>
EncodeByIdx[LocalDate].contramap { (a: LocalDateJ) =>
LocalDate.fromDaysSinceEpoch(a.toEpochDay.toInt)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ object EncodeByName {
}

implicit val localDateJEncodeByName: EncodeByName[LocalDateJ] = {
EncodeByName[LocalDate].contramap { a: LocalDateJ =>
EncodeByName[LocalDate].contramap { (a: LocalDateJ) =>
LocalDate.fromDaysSinceEpoch(a.toEpochDay.toInt)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package com.evolutiongaming.scassandra

import com.datastax.driver.core.policies.{DCAwareRoundRobinPolicy, LoadBalancingPolicy, TokenAwarePolicy}
import com.typesafe.config.Config
import pureconfig.{ConfigReader, ConfigSource}
import pureconfig.generic.semiauto.deriveReader
import pureconfig.ConfigSource

/**
* See [[https://docs.datastax.com/en/developer/java-driver/3.5/manual/load_balancing/]]
Expand All @@ -25,13 +24,10 @@ final case class LoadBalancingConfig(
}
}

object LoadBalancingConfig {
object LoadBalancingConfig extends LoadBalancingConfigImplicits {

val Default: LoadBalancingConfig = LoadBalancingConfig()

implicit val configReaderLoadBalancingConfig: ConfigReader[LoadBalancingConfig] = deriveReader


@deprecated("use ConfigReader instead", "1.1.5")
def apply(config: Config): LoadBalancingConfig = apply(config, Default)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.evolutiongaming.scassandra

import com.evolutiongaming.scassandra.util.PureconfigSyntax._
import pureconfig.ConfigReader

trait LoadBalancingConfigImplicits {
implicit val configReaderLoadBalancingConfig: ConfigReader[LoadBalancingConfig] = ConfigReader.fromCursor[LoadBalancingConfig] { cursor =>
val defaultConfig = LoadBalancingConfig()

for {
objCur <- cursor.asObjectCursor
localDc <- objCur.getAtOpt[String]("local-dc").map(_.getOrElse(defaultConfig.localDc))
allowRemoteDcsForLocalConsistencyLevel <- objCur.getAtOpt[Boolean]("allow-remote-dcs-for-local-consistency-level").map(_.getOrElse(defaultConfig.allowRemoteDcsForLocalConsistencyLevel))
} yield LoadBalancingConfig(
localDc = localDc,
allowRemoteDcsForLocalConsistencyLevel = allowRemoteDcsForLocalConsistencyLevel
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object PoolingConfig {
val Default: PoolingConfig = PoolingConfig()

implicit val configReaderPoolingConfig: ConfigReader[PoolingConfig] = {
cursor: ConfigCursor => {
(cursor: ConfigCursor) => {
for {
cursor <- cursor.asObjectCursor
} yield {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.evolutiongaming.scassandra

import com.datastax.driver.core.{ConsistencyLevel, QueryOptions}
import com.evolutiongaming.scassandra.util.ConfigReaderFromEnum
import com.typesafe.config.Config
import pureconfig.generic.semiauto.deriveReader
import pureconfig.{ConfigReader, ConfigSource}
import pureconfig.ConfigSource

import scala.concurrent.duration._

Expand Down Expand Up @@ -44,14 +42,10 @@ final case class QueryConfig(
}
}

object QueryConfig {
object QueryConfig extends QueryConfigImplicits {

val Default: QueryConfig = QueryConfig()

implicit val configReaderConsistencyLevel: ConfigReader[ConsistencyLevel] = ConfigReaderFromEnum(ConsistencyLevel.values())

implicit val configReaderQueryConfig: ConfigReader[QueryConfig] = deriveReader

@deprecated("use ConfigReader instead", "1.1.5")
def apply(config: Config): QueryConfig = apply(config, Default)

Expand Down
Loading
Loading