From 12354dbd2fbac79adcaf245e34ab4cda47161b71 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 25 Jan 2019 14:49:45 +0100 Subject: [PATCH 1/2] Cleanup imports in Reads.scala --- .../src/main/scala/play/api/libs/json/Reads.scala | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/play-json/shared/src/main/scala/play/api/libs/json/Reads.scala b/play-json/shared/src/main/scala/play/api/libs/json/Reads.scala index b4cf2e1ed..43728d606 100644 --- a/play-json/shared/src/main/scala/play/api/libs/json/Reads.scala +++ b/play-json/shared/src/main/scala/play/api/libs/json/Reads.scala @@ -4,18 +4,15 @@ package play.api.libs.json -import scala.annotation.implicitNotFound - -import scala.util.control +import scala.language.higherKinds +import scala.annotation.implicitNotFound import scala.collection.Seq import scala.collection.compat._ import scala.collection.immutable.Map import scala.collection.mutable.Builder - -import scala.language.higherKinds - -import reflect.ClassTag +import scala.reflect.ClassTag +import scala.util.control /** * A `Reads` object describes how to decode JSON into a value. From a0a085a7b4d519f077996f35086a3f57785ecdbb Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 25 Jan 2019 14:38:05 +0100 Subject: [PATCH 2/2] Replace scala-collection-compat with ScalaCollectionCompat --- build.sbt | 14 ++++++---- .../api/libs/json/ScalaCollectionCompat.scala | 10 +++++++ .../api/libs/json/ScalaCollectionCompat.scala | 28 +++++++++++++++++++ .../main/scala/play/api/libs/json/Reads.scala | 3 +- 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 play-json/shared/src/main/scala-2.13+/play/api/libs/json/ScalaCollectionCompat.scala create mode 100644 play-json/shared/src/main/scala-2.13-/play/api/libs/json/ScalaCollectionCompat.scala diff --git a/build.sbt b/build.sbt index 4ddc0787c..77e2e8d31 100644 --- a/build.sbt +++ b/build.sbt @@ -124,16 +124,20 @@ lazy val `play-json` = crossProject(JVMPlatform, JSPlatform).crossType(CrossType "org.typelevel" %% "macro-compat" % "1.1.1", "org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided" ), - libraryDependencies ++= - (CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 13)) => Seq("org.scala-lang.modules" %%% "scala-collection-compat" % "0.2.0") - case _ => Seq("org.scala-lang.modules" %%% "scala-collection-compat" % "0.1.1") - }), libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, 13)) => Seq() case _ => Seq(compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)) }), + unmanagedSourceDirectories in Compile += { + //val sourceDir = (sourceDirectory in Compile).value + // ^ gives jvm/src/main, for some reason + val sourceDir = baseDirectory.value / "../shared/src/main" + CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, n)) if n >= 13 => sourceDir / "scala-2.13+" + case _ => sourceDir / "scala-2.13-" + } + }, sourceGenerators in Compile += Def.task{ val dir = (sourceManaged in Compile).value diff --git a/play-json/shared/src/main/scala-2.13+/play/api/libs/json/ScalaCollectionCompat.scala b/play-json/shared/src/main/scala-2.13+/play/api/libs/json/ScalaCollectionCompat.scala new file mode 100644 index 000000000..ae37c47c8 --- /dev/null +++ b/play-json/shared/src/main/scala-2.13+/play/api/libs/json/ScalaCollectionCompat.scala @@ -0,0 +1,10 @@ +/* + * Copyright (C) 2009-2019 Lightbend Inc. + */ + +package play.api.libs.json + +/** Copied from scala-collection-compat, because its binary API isn't stable. */ +private[json] object ScalaCollectionCompat { + type Factory[-A, +C] = scala.collection.Factory[A, C] +} diff --git a/play-json/shared/src/main/scala-2.13-/play/api/libs/json/ScalaCollectionCompat.scala b/play-json/shared/src/main/scala-2.13-/play/api/libs/json/ScalaCollectionCompat.scala new file mode 100644 index 000000000..e0355e5a4 --- /dev/null +++ b/play-json/shared/src/main/scala-2.13-/play/api/libs/json/ScalaCollectionCompat.scala @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2009-2019 Lightbend Inc. + */ + +package play.api.libs.json + +import scala.language.implicitConversions +import scala.language.higherKinds + +import scala.collection.generic.CanBuildFrom +import scala.collection.mutable + +/** Copied from scala-collection-compat, because its binary API isn't stable. */ +private[json] object ScalaCollectionCompat { + + /** + * A factory that builds a collection of type `C` with elements of type `A`. + * + * Type param `A` is the type of elements (e.g. `Int`, `Boolean`, etc.). + * Type param `C` is the type of collection (e.g. `List[Int]`, `TreeMap[Int, String]`, etc.). + */ + type Factory[-A, +C] = CanBuildFrom[Nothing, A, C] + + final implicit class FactoryOps[-A, +C](private val factory: Factory[A, C]) { + def newBuilder: mutable.Builder[A, C] = factory() + } + +} diff --git a/play-json/shared/src/main/scala/play/api/libs/json/Reads.scala b/play-json/shared/src/main/scala/play/api/libs/json/Reads.scala index 43728d606..f820ed145 100644 --- a/play-json/shared/src/main/scala/play/api/libs/json/Reads.scala +++ b/play-json/shared/src/main/scala/play/api/libs/json/Reads.scala @@ -8,12 +8,13 @@ import scala.language.higherKinds import scala.annotation.implicitNotFound import scala.collection.Seq -import scala.collection.compat._ import scala.collection.immutable.Map import scala.collection.mutable.Builder import scala.reflect.ClassTag import scala.util.control +import ScalaCollectionCompat._ + /** * A `Reads` object describes how to decode JSON into a value. * `Reads` objects are typically provided as implicit values. When `Reads`