Skip to content

Commit

Permalink
Add scala 2.13 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Chantepie authored and cchantep committed Jul 6, 2019
1 parent 5ba6dbb commit fb6acbc
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 102 deletions.
34 changes: 0 additions & 34 deletions .circleci/config.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cache:
- $HOME/.ivy2
- $HOME/.sbt
scala:
# - 2.11.11 (on Circle)
- 2.12.8
- 2.13.0
- 2.11.11
- 2.12.8
- 2.13.0
script: ./.ci_scripts/validate.sh
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ crossScalaVersions in ThisBuild := Seq(
"2.10.7", "2.11.12", (scalaVersion in ThisBuild).value, "2.13.0"
)

resolvers in ThisBuild += Resolver.sonatypeRepo("snapshots")
resolvers in ThisBuild ++= Seq(
Resolver.sonatypeRepo("snapshots"),
"Tatami Snapshots" at "https://raw.github.com/cchantep/tatami/master/snapshots")

//
val scalacPlugin = ScalacPlugin.project
Expand Down
23 changes: 11 additions & 12 deletions jdbc-driver/src/test/scala/acolyte/jdbc/DriverSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.specs2.concurrent.ExecutionEnv

import acolyte.jdbc.test.EmptyConnectionHandler

class DriverSpec(implicit ee: ExecutionEnv)
final class DriverSpec(implicit ee: ExecutionEnv)
extends Specification with DriverUtils with DriverFixtures {

"Acolyte driver" title
Expand Down Expand Up @@ -140,25 +140,24 @@ class DriverSpec(implicit ee: ExecutionEnv)
acolyte.jdbc.Driver.register("id", h)

acolyte.jdbc.Driver.unregister("id").
getStatementHandler aka "handler" mustEqual h
getStatementHandler aka "handler" must_=== h

}

"handle multi-threaded access" in {
import scala.concurrent.duration._

val futures =
(1 to 1000).map { _ =>
Future {
val handlerId = UUID.randomUUID().toString
acolyte.jdbc.Driver.register(handlerId, new CompositeHandler())
handlerId
}.map { handlerId =>
acolyte.jdbc.Driver.handlers.get(handlerId) must not(beNull)
}
val futures = (1 to 1000).map { _ =>
Future {
val handlerId = UUID.randomUUID().toString
acolyte.jdbc.Driver.register(handlerId, new CompositeHandler())
handlerId
}.map { handlerId =>
acolyte.jdbc.Driver.handlers.get(handlerId) must not beNull
}
}

Await.result(Future.sequence(futures), 5.seconds)
Future.sequence(futures).map(_.fold(ok)(_ and _)).await(1, 5.seconds)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions play-jdbc/src/main/play-2.4/AcolyteDatabaseCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package acolyte.jdbc.play

private[play] trait AcolyteDatabaseCompat { db: AcolyteDatabase
}
4 changes: 4 additions & 0 deletions play-jdbc/src/main/play-2.5/AcolyteDatabaseCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package acolyte.jdbc.play

private[play] trait AcolyteDatabaseCompat { db: AcolyteDatabase
}
4 changes: 4 additions & 0 deletions play-jdbc/src/main/play-2.6/AcolyteDatabaseCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package acolyte.jdbc.play

private[play] trait AcolyteDatabaseCompat { db: AcolyteDatabase
}
21 changes: 21 additions & 0 deletions play-jdbc/src/main/play-2.7/AcolyteDatabaseCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package acolyte.jdbc.play

import java.sql.Connection

import play.api.db.TransactionIsolationLevel

private[play] trait AcolyteDatabaseCompat { db: AcolyteDatabase
def withTransaction[A](isolationLevel: TransactionIsolationLevel)(block: Connection A): A = {
lazy val con = getConnection(false)

try {
con.setTransactionIsolation(isolationLevel.id)

block(con)
} catch {
case e: Throwable sys.error(s"error: $e")
} finally {
con.close()
}
}
}
2 changes: 1 addition & 1 deletion play-jdbc/src/main/scala/AcolyteDatabase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import acolyte.jdbc.{
final class AcolyteDatabase(
handler: ScalaCompositeHandler,
resourceHandler: ResourceHandler = new ResourceHandler.Default(),
id: String = java.util.UUID.randomUUID().toString) extends Database { self
id: String = java.util.UUID.randomUUID().toString) extends Database with AcolyteDatabaseCompat { self

AcolyteDriver.register(id, new ConnectionHandler.Default(handler, resourceHandler))

Expand Down
20 changes: 10 additions & 10 deletions play-jdbc/src/test/scala/PlayJdbcUseCases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ case object PlayJdbcUseCases {

val useCase1: PlayJdbcContext = PlayJdbcDSL.withPlayDBResult("foo")

def useCase2(onUpdate: Unit): PlayJdbcContext = new PlayJdbcContext(
def useCase2(onUpdate: => Unit): PlayJdbcContext = new PlayJdbcContext(
AcolyteDSL.handleStatement.withUpdateHandler {
case UpdateExecution("insert into foo values (1, 'foo value')", Nil)
case UpdateExecution("insert into foo values (1, 'foo value')", Nil) =>
AcolyteDSL.updateResult(1, RowLists.longList.append(1L))
case UpdateExecution("insert into bar values (1, 'bar value')", Nil)
case UpdateExecution("insert into bar values (1, 'bar value')", Nil) =>
AcolyteDSL.updateResult(2, RowLists.longList.append(1L))
case u throw new SQLException(s"Unexpected update: $u")
case u => throw new SQLException(s"Unexpected update: $u")
},
AcolyteDSL.handleTransaction(whenCommit = { _ onUpdate }))
AcolyteDSL.handleTransaction(whenCommit = { _ => onUpdate }))

def useCase3(onUpdate: Unit): PlayJdbcContext = new PlayJdbcContext(
def useCase3(onUpdate: => Unit): PlayJdbcContext = new PlayJdbcContext(
AcolyteDSL.handleStatement.withUpdateHandler {
case UpdateExecution("insert into foo values (1, 'foo value')", Nil)
case UpdateExecution("insert into foo values (1, 'foo value')", Nil) =>
AcolyteDSL.updateResult(1, RowLists.longList.append(1L))
case UpdateExecution("insert into bar values (1, 'bar value')", Nil)
case UpdateExecution("insert into bar values (1, 'bar value')", Nil) =>
throw new SQLException("Simulating on error.")
case u throw new SQLException(s"Unexpected update: $u")
case u => throw new SQLException(s"Unexpected update: $u")
},
AcolyteDSL.handleTransaction(whenRollback = { _ onUpdate }))
AcolyteDSL.handleTransaction(whenRollback = { _ => onUpdate }))

}
2 changes: 1 addition & 1 deletion project/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Compiler extends AutoPlugin {
"-unchecked",
"-deprecation",
"-feature",
//"-Xfatal-warnings",
"-Xfatal-warnings",
"-Xlint",
"-Ywarn-numeric-widen",
"-Ywarn-dead-code",
Expand Down
3 changes: 1 addition & 2 deletions project/Format.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ object Format {
setPreference(SpaceBeforeColon, false).
setPreference(SpaceInsideBrackets, false).
setPreference(SpacesAroundMultiImports, true).
setPreference(SpacesWithinPatternBinders, true).
setPreference(RewriteArrowSymbols, true)
setPreference(SpacesWithinPatternBinders, true)
)
}
43 changes: 30 additions & 13 deletions project/PlayJdbc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,60 @@ class PlayJdbc(
import Dependencies._
import Format._

val playVersion = settingKey[String]("Playframework version")

lazy val project =
Project(id = "play-jdbc", base = file("play-jdbc")).
settings(formatSettings ++ Seq(
name := "play-jdbc",
scalacOptions in Test ++= {
val v = (version in ThisBuild).value
val sv = (scalaVersion in ThisBuild).value
val sv = (scalaVersion in Test).value
val b = (baseDirectory in (scalacPlugin, Compile)).value
val n = (name in (scalacPlugin, Compile)).value

val msv = {
if (sv startsWith "2.10") "2.10"
else if (sv startsWith "2.11") "2.11"
else if (sv startsWith "2.12") "2.12"
else sv
val msv = CrossVersion.partialVersion(sv) match {
case Some((maj, min)) => s"${maj}.${min}"
case _ => sv
}

val td = b / "target" / s"scala-$msv"
val j = td / s"${n}_${msv}-$v.jar"

Seq("-feature", "-deprecation", s"-Xplugin:${j.getAbsolutePath}")
},
playVersion := {
val scalaVer = scalaVersion.value

if (scalaVer startsWith "2.11.") "2.5.8"
else if (scalaVer startsWith "2.12.") "2.6.7"
else if (scalaVer startsWith "2.13.") "2.7.3"
else "2.4.8"
},
unmanagedSourceDirectories in Compile += {
val base = (sourceDirectory in Compile).value

CrossVersion.partialVersion(playVersion.value) match {
case Some((maj, min)) => base / s"play-${maj}.${min}"
case _ => base / "play"
}
},
compile in Test := (compile in Test).
dependsOn(compile in (scalacPlugin, Test)).value,
// make sure plugin is there
libraryDependencies ++= {
val (playVer, anormVer) = {
if (scalaVersion.value startsWith "2.11") "2.5.8" -> "2.5.2"
else if (scalaVersion.value startsWith "2.12") "2.6.7" -> "2.5.0"
else if (scalaVersion.value startsWith "2.13") "2.7.3" -> "2.5.0"
else "2.4.8" -> "2.5.0"
val anorm = {
if (scalaVersion.value startsWith "2.10.") {
"com.typesafe.play" %% "anorm" % "2.5.0"
} else {
"org.playframework.anorm" %% "anorm" % "2.6.3"
}
}

Seq(
"org.eu.acolyte" % "jdbc-driver" % (version in ThisBuild).value,
"com.typesafe.play" %% "play-jdbc-api" % playVer % "provided",
"com.typesafe.play" %% "anorm" % anormVer % Test,
"com.typesafe.play" %% "play-jdbc-api" % playVersion.value % "provided",
anorm % Test,
"org.specs2" %% "specs2-core" % specsVer.value % Test)
}
)).dependsOn(scalacPlugin, jdbcScala)
Expand Down
68 changes: 47 additions & 21 deletions project/ReactiveMongo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ class ReactiveMongo(scalacPlugin: Project) { self =>
lazy val generatedClassDirectory = settingKey[File](
"Directory where classes get generated")

val reactiveMongoVer = "0.18.0"
val reactiveMongoVer = "0.18.1"

lazy val project =
Project(id = "reactive-mongo", base = file("reactive-mongo")).
settings(formatSettings ++ Set(
name := "reactive-mongo",
fork in Test := true,
javacOptions in Test ++= Seq("-Xlint:unchecked", "-Xlint:deprecation"),
resolvers ++= reactiveResolvers,
libraryDependencies ++= Seq(
"org.reactivemongo" %% "reactivemongo" % reactiveMongoVer % "provided",
"com.jsuereth" %% "scala-arm" % "2.0",
"com.jsuereth" %% "scala-arm" % "2.1-SNAPSHOT",
"org.slf4j" % "slf4j-simple" % "1.7.13" % Provided,
"com.chuusai" %% "shapeless" % "2.3.2",
"com.chuusai" %% "shapeless" % "2.3.3",
"org.specs2" %% "specs2-core" % specsVer.value % Test)
))//.dependsOn(scalacPlugin)

Expand All @@ -35,17 +34,20 @@ class ReactiveMongo(scalacPlugin: Project) { self =>
settings(formatSettings ++ Set(
name := "play-reactive-mongo",
crossScalaVersions ~= { _.filterNot(_ startsWith "2.10") },
javacOptions in Test ++= Seq("-Xlint:unchecked", "-Xlint:deprecation"),
sourceDirectory := {
if (scalaVersion.value startsWith "2.10.") {
new java.io.File("/no/sources")
} else sourceDirectory.value
},
scalacOptions ++= {
val v = version.value
val sv = scalaVersion.value
val b = (baseDirectory in (scalacPlugin, Compile)).value
val n = (name in (scalacPlugin, Compile)).value

val msv = {
if (sv startsWith "2.12") "2.12"
else if (sv startsWith "2.11") "2.11"
else "2.10"
val msv = CrossVersion.partialVersion(sv) match {
case Some((maj, min)) => s"${maj}.${min}"
case _ => sv
}

val td = b / "target" / s"scala-$msv"
Expand All @@ -54,22 +56,46 @@ class ReactiveMongo(scalacPlugin: Project) { self =>
Seq("-feature", "-deprecation", s"-Xplugin:${j.getAbsolutePath}")
},
resolvers ++= reactiveResolvers,
libraryDependencies ++= {
val (playVer, playVar) = if (scalaVersion.value startsWith "2.12") {
"2.6.3" -> "play26"
} else {
"2.5.13" -> "play25"
publish := (Def.taskDyn {
val p = publish.value
val ver = scalaVersion.value

Def.task[Unit] {
if (ver startsWith "2.10.") ({})
else p
}
}).value,
publishTo := (Def.taskDyn {
val p = publishTo.value
val ver = scalaVersion.value

val playRmVer = reactiveMongoVer.span(_ != '-') match {
case (v, m) => s"${v}-${playVar}${m}"
Def.task {
if (ver startsWith "2.10.") None
else p
}
}).value,
libraryDependencies ++= {
val sv = scalaVersion.value

if (sv startsWith "2.10.") {
Seq.empty[ModuleID]
} else {
val (playVer, playVar) = {
if (sv startsWith "2.12.") "2.6.3" -> "play26"
else if (sv startsWith "2.13.") "2.7.3" -> "play27"
else "2.5.13" -> "play25"
}

Seq(
"com.typesafe.play" %% "play" % playVer % Provided,
"org.reactivemongo" %% "play2-reactivemongo" % playRmVer % Provided,
"org.specs2" %% "specs2-core" % specsVer.value % Test
)
val playRmVer = reactiveMongoVer.span(_ != '-') match {
case (v, m) => s"${v}-${playVar}${m}"
}

Seq(
"com.typesafe.play" %% "play" % playVer % Provided,
"org.reactivemongo" %% "play2-reactivemongo" % playRmVer % Provided,
"org.specs2" %% "specs2-core" % specsVer.value % Test
)
}
}
)).dependsOn(scalacPlugin, self.project)

Expand Down
2 changes: 1 addition & 1 deletion project/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if [ "_$JAVA_MODULES" = "_" ]; then
JAVA_MODULES="jdbc-driver"
fi

#EXTRA_JAVA_MODULES="jdbc-java8"
EXTRA_JAVA_MODULES="jdbc-java8"

if [ "_$SCALA_MODULES" = "_" ]; then
SCALA_MODULES="jdbc-scala scalac-plugin reactive-mongo play-jdbc play-reactive-mongo"
Expand Down
Loading

0 comments on commit fb6acbc

Please sign in to comment.