Skip to content

Commit

Permalink
Migration RowParserImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
cchantep committed Aug 22, 2022
1 parent cd8d7fa commit 514c03c
Show file tree
Hide file tree
Showing 41 changed files with 1,257 additions and 694 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: playframework/.github/.github/workflows/cmd.yml@v2
with:
java: 11, 8
scala: 2.11.12, 2.12.16, 2.13.8, 3.1.3
scala: 2.11.12, 2.12.16, 2.13.8 # TODO: 3.1.3 (other play modules not ok)
cmd: sbt ++$MATRIX_SCALA docs/test

tests:
Expand All @@ -41,7 +41,7 @@ jobs:
with:
java: 11, 8
scala: 2.11.12, 2.12.16, 2.13.8, 3.1.3
cmd: sbt ++$MATRIX_SCALA publishLocal test # scapegoat
cmd: sbt ++$MATRIX_SCALA publishLocal test

finish:
name: Finish
Expand Down
2 changes: 1 addition & 1 deletion .scalafix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OrganizeImports {
"re:javax?\\.",
"scala.language", "scala.util", "scala.collection",
"scala.",
"akka.",
"akka.actor", "akka.stream", "akka.",
"play.",
"resource.",
"acolyte.",
Expand Down
10 changes: 5 additions & 5 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
version = 3.5.8

runner.dialect = Scala213Source3
project.layout = StandardConvention

align.preset = true
assumeStandardLibraryStripMargin = true
Expand All @@ -16,8 +18,6 @@ trailingCommas = preserve
newlines.afterCurlyLambda = preserve
newlines.beforeCurlyLambdaParams = multilineWithCaseOnly

fileOverride {
"glob:**/src/*/scala-3/**/*.scala" {
runner.dialect = scala3
}
}
literals.long=Upper
literals.float=Upper
literals.double=Upper
18 changes: 12 additions & 6 deletions akka/src/test/scala/anorm/AkkaStreamSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@ import scala.collection.immutable.Seq
import scala.concurrent.Future
import scala.concurrent.duration._

import akka.actor.ActorSystem

import akka.stream.Materializer
import akka.stream.scaladsl.{ Keep, Sink, Source }

import acolyte.jdbc.QueryResult
import acolyte.jdbc.AcolyteDSL.withQueryResult
import acolyte.jdbc.Implicits._
import acolyte.jdbc.QueryResult
import acolyte.jdbc.RowLists.stringList

import org.specs2.concurrent.ExecutionEnv

final class AkkaStreamSpec(implicit ee: ExecutionEnv) extends org.specs2.mutable.Specification {

"Akka Stream" title
"Akka Stream".title

implicit lazy val system: ActorSystem = ActorSystem("anorm-tests")

implicit lazy val system = akka.actor.ActorSystem("knox-core-tests")
implicit def materializer = akka.stream.ActorMaterializer.create(system)
implicit def materializer: Materializer =
akka.stream.ActorMaterializer.create(system)

// Akka-Contrib issue with Akka-Stream > 2.5.4
// import akka.stream.contrib.TestKit.assertAllStagesStopped
Expand Down Expand Up @@ -66,8 +71,9 @@ final class AkkaStreamSpec(implicit ee: ExecutionEnv) extends org.specs2.mutable

"on success" in assertAllStagesStopped {
withQueryResult(stringList :+ "A" :+ "B" :+ "C") { implicit con =>
runAsync(Sink.seq[String]) must beLike[ResultSet] { case rs =>
(rs.isClosed must beTrue).and(rs.getStatement.isClosed must beTrue).and(con.isClosed must beFalse)
runAsync(Sink.seq[String]) must beLike[ResultSet] {
case rs =>
(rs.isClosed must beTrue).and(rs.getStatement.isClosed must beTrue).and(con.isClosed must beFalse)
}.await(0, 5.seconds)
}
}
Expand Down
103 changes: 80 additions & 23 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import com.typesafe.tools.mima.plugin.MimaKeys.{ mimaBinaryIssueFilters, mimaPre
// Scalafix
inThisBuild(
List(
//scalaVersion := "2.13.3",
// scalaVersion := "2.13.3",
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
scalafixDependencies ++= Seq(
"com.github.liancheng" %% "organize-imports" % "0.5.0")
scalafixDependencies ++= Seq("com.github.liancheng" %% "organize-imports" % "0.5.0")
)
)

val specs2Test = Seq(
"specs2-core",
"specs2-junit",
"specs2-matcher-extra"
).map("org.specs2" %% _ % "4.10.6" % Test cross(CrossVersion.for3Use2_13))
).map("org.specs2" %% _ % "4.10.6" % Test cross (CrossVersion.for3Use2_13))
.map(_.exclude("org.scala-lang.modules", "*"))

lazy val acolyteVersion = "1.2.1"
lazy val acolyte = "org.eu.acolyte" %% "jdbc-scala" % acolyteVersion % Test
Expand Down Expand Up @@ -50,9 +50,8 @@ lazy val `anorm-tokenizer` = project
// ---

val armShading = Seq(
libraryDependencies += ("com.jsuereth" %% "scala-arm" % "2.1-SNAPSHOT").
cross(CrossVersion.for3Use2_13),
assembly / test := {},
libraryDependencies += ("com.jsuereth" %% "scala-arm" % "2.1-SNAPSHOT").cross(CrossVersion.for3Use2_13),
assembly / test := {},
assembly / assemblyOption ~= {
_.withIncludeScala(false) // java libraries shouldn't include scala
},
Expand Down Expand Up @@ -109,6 +108,14 @@ lazy val coreMimaFilter: ProblemFilter = {
case _ => true
}

lazy val xmlVer = Def.setting[String] {
if (scalaBinaryVersion.value == "2.11") {
"1.3.0"
} else {
"2.1.0"
}
}

lazy val `anorm-core` = project
.in(file("core"))
.settings(
Expand All @@ -117,10 +124,19 @@ lazy val `anorm-core` = project
(Compile / sourceGenerators) += Def.task {
Seq(GFA((Compile / sourceManaged).value / "anorm"))
}.taskValue,
scaladocExtractorSkipToken := {
if (scalaBinaryVersion.value == "3") {
"// skip-doc-5f98a5e"
} else {
scaladocExtractorSkipToken.value
}
},
scalacOptions ++= {
if (scalaBinaryVersion.value == "3") {
Seq.empty
Seq("-Wconf:cat=deprecation&msg=.*(reflectiveSelectableFromLangReflectiveCalls|DeprecatedSqlParser|missing .*ToSql).*:s")
Seq(
"-Wconf:cat=deprecation&msg=.*(reflectiveSelectableFromLangReflectiveCalls|DeprecatedSqlParser|missing .*ToSql).*:s"
)
} else {
Seq(
"-Xlog-free-terms",
Expand Down Expand Up @@ -169,6 +185,7 @@ lazy val `anorm-core` = project
ProblemFilters.exclude[DirectMissingMethodProblem]( // deprecated 2.3.8
"anorm.SqlQuery.statement"
),
incoRet("anorm.ParameterValue.apply"),
// private:
ProblemFilters.exclude[DirectMissingMethodProblem]( // private
"anorm.Sql.asTry"
Expand All @@ -183,27 +200,37 @@ lazy val `anorm-core` = project
"joda-time" % "joda-time" % "2.11.0",
"org.joda" % "joda-convert" % "2.2.2",
"org.scala-lang.modules" %% "scala-parser-combinators" % parserCombinatorsVer.value,
"org.scala-lang.modules" %% "scala-xml" % "2.1.0" % Test,
"com.h2database" % "h2" % "2.1.214" % Test,
"org.scala-lang.modules" %% "scala-xml" % xmlVer.value % Test,
"com.h2database" % "h2" % "2.1.214" % Test,
acolyte
) ++ specs2Test.map(_.exclude("org.scala-lang.modules", "*")),
) ++ specs2Test,
) ++ armShading
)
.dependsOn(`anorm-tokenizer`)

lazy val `anorm-iteratee` = (project in file("iteratee"))
.settings(
sourceDirectory := {
if (scalaBinaryVersion.value == "2.13") new java.io.File("/no/sources")
val v = scalaBinaryVersion.value

if (v == "3" || v == "2.13") new java.io.File("/no/sources")
else sourceDirectory.value
},
mimaPreviousArtifacts := {
if (scalaBinaryVersion.value == "3") Set.empty[ModuleID]
val v = scalaBinaryVersion.value

if (v == "3" || v == "2.13") Set.empty[ModuleID]
else Set(organization.value %% name.value % "2.6.10")
},
publish / skip := { scalaBinaryVersion.value == "2.13" },
publish / skip := {
val v = scalaBinaryVersion.value

v == "3" || v == "2.13"
},
libraryDependencies ++= {
if (scalaBinaryVersion.value == "2.13") Seq.empty[ModuleID]
val v = scalaBinaryVersion.value

if (v == "3" || v == "2.13") Seq.empty[ModuleID]
else
Seq(
"com.typesafe.play" %% "play-iteratees" % "2.6.1",
Expand All @@ -217,7 +244,10 @@ lazy val `anorm-iteratee` = (project in file("iteratee"))

lazy val akkaVer = Def.setting[String] {
sys.env.get("AKKA_VERSION").getOrElse {
if (scalaBinaryVersion.value == "2.11") "2.4.20"
val v = scalaBinaryVersion.value

if (v == "2.11") "2.4.20"
else if (v == "3") "2.6.19"
else "2.5.32"
}
}
Expand All @@ -237,12 +267,20 @@ lazy val `anorm-akka` = (project in file("akka"))
}
},
libraryDependencies ++= Seq("akka-testkit", "akka-stream").map { m =>
"com.typesafe.akka" %% m % akkaVer.value % Provided
("com.typesafe.akka" %% m % akkaVer.value % Provided).exclude("org.scala-lang.modules", "*")
},
libraryDependencies ++= (acolyte +: specs2Test) ++ Seq(
"com.typesafe.akka" %% "akka-stream-contrib" % akkaContribVer.value % Test
("com.typesafe.akka" %% "akka-stream-contrib" % akkaContribVer.value % Test)
.cross(CrossVersion.for3Use2_13)
.exclude("com.typesafe.akka", "*")
),
scalacOptions += "-P:silencer:globalFilters=deprecated",
scalacOptions ++= {
if (scalaBinaryVersion.value == "3") {
Seq("-Wconf:cat=deprecation&msg=.*(onDownstreamFinish|ActorMaterializer).*:s")
} else {
Seq("-P:silencer:globalFilters=deprecated")
}
},
Test / unmanagedSourceDirectories ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n < 13 =>
Expand All @@ -261,16 +299,19 @@ lazy val `anorm-akka` = (project in file("akka"))
lazy val pgVer = sys.env.get("POSTGRES_VERSION").getOrElse("42.4.2")

val playVer = Def.setting[String] {
if (scalaVersion.value.startsWith("2.13")) "2.7.3"
if (scalaBinaryVersion.value == "2.13") "2.7.3"
else "2.6.14"
}

lazy val `anorm-postgres` = (project in file("postgres"))
.settings(
mimaPreviousArtifacts := Set.empty,
libraryDependencies ++= {
val v = scalaBinaryVersion.value

val playJsonVer = {
if (scalaBinaryVersion.value == "2.13") "2.9.2"
if (v == "2.13") "2.9.2"
else if (v == "3") "2.10.0-RC6"
else "2.6.7"
}

Expand All @@ -284,8 +325,23 @@ lazy val `anorm-postgres` = (project in file("postgres"))

lazy val `anorm-enumeratum` = (project in file("enumeratum"))
.settings(
sourceDirectory := {
if (scalaBinaryVersion.value == "3") new java.io.File("/no/sources")
else sourceDirectory.value
},
publish / skip := { scalaBinaryVersion.value == "3" },
mimaPreviousArtifacts := Set.empty,
libraryDependencies ++= Seq("com.beachape" %% "enumeratum" % "1.7.0", acolyte) ++ specs2Test
libraryDependencies ++= {
if (scalaBinaryVersion.value != "3") {
Seq(
"org.scala-lang.modules" %% "scala-xml" % xmlVer.value % Test,
"com.beachape" %% "enumeratum" % "1.7.0",
acolyte
) ++ specs2Test
} else {
Seq.empty
}
}
)
.dependsOn(`anorm-core`)

Expand Down Expand Up @@ -320,7 +376,8 @@ ThisBuild / playBuildRepoName := "anorm"
addCommandAlias(
"validateCode",
List(
"scalafixAll -check",
"scalafmtSbtCheck",
"scalafmtCheckAll",
"+scalafmtCheckAll"
).mkString(";")
)
5 changes: 4 additions & 1 deletion core/src/main/scala-2/anorm/Macro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ object Macro extends MacroOptions {
def psz = params.size

if (names.size < psz) {
c.abort(c.enclosingPosition, s"no column name for parameters: ${show(names)} < $params")
c.abort(
c.enclosingPosition,
s"no column name for parameters: ${names.map(n => show(n)).mkString(", ")} < ${params.map(_.name).mkString(", ")}"
)

} else {
parserImpl[T](c) { (t, _, i) =>
Expand Down
6 changes: 1 addition & 5 deletions core/src/main/scala-2/anorm/macros/SealedRowParserImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ private[anorm] object SealedRowParserImpl {
val caseName = TermName(c.freshName("discriminated"))
val key = q"$discriminate(${subclass.typeSymbol.fullName})"
val caseDecl = q"val $caseName = $key"
val subtype = { // TODO: typeParams is not supported anyway
if (subclass.typeSymbol.asClass.typeParams.isEmpty) subclass
else subclass.erasure
}

(key, caseDecl, cq"`$caseName` => implicitly[anorm.RowParser[$subtype]]")
(key, caseDecl, cq"`$caseName` => implicitly[anorm.RowParser[$subclass]]")
}

lazy val supported = q"List(..${cases.map(_._1)})"
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/scala-2/anorm/macros/ToParameterListImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ private[anorm] object ToParameterListImpl {

c.inferImplicitValue(ptype) match {
case EmptyTree =>
c.abort(
c.enclosingPosition, s"Missing ToParameterList[${subcls}]")
c.abort(c.enclosingPosition, s"Missing ToParameterList[${subcls}]")

case toParams =>
case toParams =>
cq"v: ${subcls} => $toParams(v)"
}
}
Expand Down
Loading

0 comments on commit 514c03c

Please sign in to comment.