From 3fe3040f8cef3ff9700608a5631a72472a4db9f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Chantepie?= Date: Sat, 9 Sep 2023 17:25:21 +0200 Subject: [PATCH] Fix build --- akka/src/test/scala-2.12+/StreamTestKit.scala | 13 ++++ akka/src/test/scala-2.12-/StreamTestKit.scala | 10 +++ .../src/test/scala/anorm/AkkaStreamSpec.scala | 3 +- build.sbt | 73 +++++++++++++++---- project/Common.scala | 2 +- 5 files changed, 83 insertions(+), 18 deletions(-) create mode 100644 akka/src/test/scala-2.12+/StreamTestKit.scala create mode 100644 akka/src/test/scala-2.12-/StreamTestKit.scala diff --git a/akka/src/test/scala-2.12+/StreamTestKit.scala b/akka/src/test/scala-2.12+/StreamTestKit.scala new file mode 100644 index 00000000..1b2ac5da --- /dev/null +++ b/akka/src/test/scala-2.12+/StreamTestKit.scala @@ -0,0 +1,13 @@ +/* + * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. + */ + +package anorm + +import akka.stream.Materializer +import akka.stream.testkit.scaladsl.{ StreamTestKit => AkkaTestKit } + +private[anorm] object StreamTestKit { + def assertAllStagesStopped[T](f: => T)(implicit mat: Materializer): T = + AkkaTestKit.assertAllStagesStopped(f) +} diff --git a/akka/src/test/scala-2.12-/StreamTestKit.scala b/akka/src/test/scala-2.12-/StreamTestKit.scala new file mode 100644 index 00000000..1c811191 --- /dev/null +++ b/akka/src/test/scala-2.12-/StreamTestKit.scala @@ -0,0 +1,10 @@ +/* + * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. + */ + +package anorm + +/* No valid testkit for 2.11 */ +private[anorm] object StreamTestKit { + def assertAllStagesStopped[T](f: => T): T = f +} diff --git a/akka/src/test/scala/anorm/AkkaStreamSpec.scala b/akka/src/test/scala/anorm/AkkaStreamSpec.scala index 9d410b7f..d9791c20 100644 --- a/akka/src/test/scala/anorm/AkkaStreamSpec.scala +++ b/akka/src/test/scala/anorm/AkkaStreamSpec.scala @@ -15,7 +15,6 @@ import akka.actor.ActorSystem import akka.stream.Materializer import akka.stream.scaladsl.{ Keep, Sink, Source } -import akka.stream.testkit.scaladsl.StreamTestKit.assertAllStagesStopped import acolyte.jdbc.AcolyteDSL.withQueryResult import acolyte.jdbc.Implicits._ @@ -33,6 +32,8 @@ final class AkkaStreamSpec(implicit ee: ExecutionEnv) extends org.specs2.mutable implicit def materializer: Materializer = akka.stream.ActorMaterializer.create(system) + import StreamTestKit.assertAllStagesStopped + "Akka Stream" should { "expose the query result as source" in assertAllStagesStopped { withQueryResult(stringList :+ "A" :+ "B" :+ "C") { implicit con => diff --git a/build.sbt b/build.sbt index 269a5f33..4e95e712 100644 --- a/build.sbt +++ b/build.sbt @@ -261,8 +261,6 @@ lazy val akkaVer = Def.setting[String] { } } -lazy val pekkoVer = Def.setting[String]("1.0.1") - lazy val `anorm-akka` = (project in file("akka")) .settings( mimaPreviousArtifacts := { @@ -278,7 +276,7 @@ lazy val `anorm-akka` = (project in file("akka")) libraryDependencies ++= Seq( acolyte, "org.scala-lang.modules" %% "scala-xml" % xmlVer.value % Test, - "com.typesafe.akka" %% "akka-stream-testkit" % akkaVer.value % Test + ("com.typesafe.akka" %% "akka-stream-testkit" % akkaVer.value % Test).exclude("org.scala-lang.modules", "*") ) ++ specs2Test, scalacOptions ++= { if (scalaBinaryVersion.value == "3") { @@ -287,30 +285,75 @@ lazy val `anorm-akka` = (project in file("akka")) Seq("-P:silencer:globalFilters=deprecated") } }, - Test / unmanagedSourceDirectories ++= { + Test / unmanagedSourceDirectories += { CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, n)) if n < 13 => - Seq((Test / sourceDirectory).value / "scala-2.13-") + (Test / sourceDirectory).value / "scala-2.13-" case _ => - Seq((Test / sourceDirectory).value / "scala-2.13+") + (Test / sourceDirectory).value / "scala-2.13+" + + } + }, + Test / unmanagedSourceDirectories += { + CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, 11)) => + (Test / sourceDirectory).value / "scala-2.12-" + + case _ => + (Test / sourceDirectory).value / "scala-2.12+" } } ) .dependsOn(`anorm-core`) +lazy val pekkoVer = Def.setting[String]("1.0.1") + +lazy val pekkoEnabled = Def.setting[Boolean] { + val v = scalaBinaryVersion.value + + v != "2.11" && v != "2.12" +} + lazy val `anorm-pekko` = (project in file("pekko")) .settings( mimaPreviousArtifacts := Set.empty, - libraryDependencies ++= Seq("pekko-testkit", "pekko-stream").map { m => - ("org.apache.pekko" %% m % pekkoVer.value % Provided).exclude("org.scala-lang.modules", "*") + sourceDirectory := { + if (!pekkoEnabled.value) new java.io.File("/no/sources") + else sourceDirectory.value + }, + publishArtifact := pekkoEnabled.value, + publish := Def.taskDyn { + val ver = scalaBinaryVersion.value + val go = publish.value + + Def.task { + if (pekkoEnabled.value) { + go + } + } + }.value, + libraryDependencies ++= { + if (pekkoEnabled.value) { + Seq("pekko-testkit", "pekko-stream").map { m => + ("org.apache.pekko" %% m % pekkoVer.value % Provided).exclude("org.scala-lang.modules", "*") + } + } else { + Seq.empty + } + }, + libraryDependencies ++= { + if (pekkoEnabled.value) { + Seq( + acolyte, + "org.scala-lang.modules" %% "scala-xml" % xmlVer.value % Test, + "org.apache.pekko" %% "pekko-stream-testkit" % pekkoVer.value % Test + ) ++ specs2Test + } else { + Seq.empty + } }, - libraryDependencies ++= Seq( - acolyte, - "org.scala-lang.modules" %% "scala-xml" % xmlVer.value % Test, - "org.apache.pekko" %% "pekko-stream-testkit" % pekkoVer.value % Test - ) ++ specs2Test, scalacOptions ++= { if (scalaBinaryVersion.value == "3") { Seq("-Wconf:cat=deprecation&msg=.*(onDownstreamFinish|ActorMaterializer).*:s") @@ -327,9 +370,7 @@ lazy val `anorm-pekko` = (project in file("pekko")) Seq((Test / sourceDirectory).value / "scala-2.13+") } - }, - crossScalaVersions --= Seq("2.11.12", "2.12.18"), - mimaFailOnNoPrevious := false + } ) .dependsOn(`anorm-core`) diff --git a/project/Common.scala b/project/Common.scala index c1f4eff9..426e1a28 100644 --- a/project/Common.scala +++ b/project/Common.scala @@ -23,7 +23,7 @@ object Common extends AutoPlugin { organization := "org.playframework.anorm", sonatypeProfileName := "org.playframework", scalaVersion := "2.12.18", - crossScalaVersions := Seq("2.11.12", scalaVersion.value, "2.13.11", "3.3.0"), + crossScalaVersions := Seq("2.11.12", scalaVersion.value, "2.13.11", "3.3.1"), (Compile / unmanagedSourceDirectories) ++= { val sv = scalaVersion.value