Skip to content

Commit 6580fe7

Browse files
committed
+ Move CodecImplicits.scala from scala-implicits to new scala-macro module
+ Also remove never used makeDeserializer, makeSerializer methods from `private[scala] object CodecImplicits` + Remove jsoniter-scala-macros dependency from scala-implicits & scala-client + Remove scala-java8-compat dependency from scala-client when publishing + scala-client now depend scala-implicits in pom.xml I don't found any benefit to shade scala-implicits into scala-client But shading cause some trouble, ex: scala/bug#11247 + Publish scala-macro & scala-implicits + Users of scala-client now need add `"com.couchbase.client" %% "scala-macro" % Provided` Change-Id: I0ad6a74b2b4b168f84d24321e0333de67ef3e742
1 parent a4813c5 commit 6580fe7

File tree

4 files changed

+48
-82
lines changed

4 files changed

+48
-82
lines changed

build.sbt

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ lazy val javaModuleSettings = commonSettings ++ Seq(
3535
crossPaths := false // drop off Scala suffix from artifact names and publish path
3636
)
3737

38-
val defaultScala = scalaVersion := "2.13.1"
3938
lazy val scalaModuleSettings = commonSettings ++ Seq(
40-
defaultScala,
41-
crossScalaVersions := Seq("2.13.1", "2.12.10", "2.11.12"),
39+
version := "1.1.0-SNAPSHOT",
40+
scalaVersion := V.scala,
41+
crossScalaVersions := V.crossScala,
4242
scalacOptions ++= Seq("-encoding", "UTF-8", "-target:jvm-1.8", "-deprecation", "-feature"),
4343
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
4444
// Required for Scala 2.11 build, this enables support for Java SAM.
@@ -203,7 +203,7 @@ lazy val `tracing-opentelemetry` = project
203203
opentelemetry("exporters-inmemory") % Test
204204
),
205205
// tracing-opentelemetry need scala only when test
206-
defaultScala,
206+
scalaVersion := V.scala,
207207
scalacOptions ++= Seq("-encoding", "UTF-8", "-target:jvm-1.8", "-deprecation", "-feature"),
208208
Test / unmanagedSourceDirectories := Seq((Test / javaSource).value, (Test / scalaSource).value)
209209
)
@@ -215,13 +215,18 @@ lazy val `scala-implicits` = project
215215
.settings(scalaModuleSettings: _*)
216216
.settings(
217217
description := "The official Couchbase Scala SDK (Implicits)",
218-
version := "1.1.0-SNAPSHOT",
219-
libraryDependencies ++= scalaImplicitsDeps.value,
220-
exportJars := true,
221-
publish / skip := true
218+
libraryDependencies ++= scalaImplicitsDeps.value
222219
)
223220
.dependsOn(`core-io`, `test-utils` % Test)
224221

222+
lazy val `scala-macro` = project
223+
.disablePlugins(AssemblyPlugin, CheckstylePlugin)
224+
.settings(scalaModuleSettings: _*)
225+
.settings(
226+
libraryDependencies += jsoniterScala("macros")
227+
)
228+
.dependsOn(`scala-implicits`)
229+
225230
val scalaClientAssemblySettings = commonAssemblySettings ++ inTask(assembly)(
226231
Seq(
227232
assemblyShadeRules := Seq(
@@ -230,16 +235,14 @@ val scalaClientAssemblySettings = commonAssemblySettings ++ inTask(assembly)(
230235
).map { p =>
231236
ShadeRule.rename(s"$p.**" -> s"${organization.value}.scala.deps.@0").inAll
232237
},
233-
// shade scala-java8-compat, scala-implicits and selfJar (scala-client)
238+
// shade scala-java8-compat, and selfJar (scala-client)
234239
assemblyExcludedJars := {
235-
val cp = fullClasspath.value
236-
val depJar = (`scala-implicits` / Compile / packageBin / artifactPath).value
237-
val selfJar = (Compile / packageBin / artifactPath).value
238-
val includedJars = Set(depJar, selfJar)
239-
val sv = scalaBinaryVersion.value
240+
val cp = fullClasspath.value
241+
val selfJar = (Compile / packageBin / artifactPath).value
242+
val sv = scalaBinaryVersion.value
240243
cp.filterNot { entry =>
241244
entry.isModule(scalaJava8Compat, sv) ||
242-
includedJars.contains(entry.data)
245+
entry.data == selfJar
243246
}
244247
},
245248
shadeResourceTransformers += Discard(
@@ -253,7 +256,6 @@ lazy val `scala-client` = project
253256
.enableAssemblyPublish()
254257
.settings(
255258
description := "The official Couchbase Scala SDK",
256-
version := "1.1.0-SNAPSHOT",
257259
libraryDependencies ++= scalaClientDeps.value,
258260
// https://docs.scala-lang.org/overviews/core/collections-migration-213.html#how-do-i-cross-build-my-project-against-scala-212-and-scala-213
259261
unmanagedSourceDirectories in Compile += {
@@ -265,15 +267,14 @@ lazy val `scala-client` = project
265267
}
266268
)
267269
.itConfig()
268-
.dependsOn(`core-io`, `scala-implicits`, `test-utils` % Test)
269-
.removePomDependsOn(`scala-implicits`)
270+
.dependsOn(`core-io`, `scala-implicits`, `scala-macro` % Provided, `test-utils` % Test)
271+
.removePomDependsOn(scalaJava8Compat)
270272

271273
lazy val `scala-examples` = project
272274
.disablePlugins(AssemblyPlugin, CheckstylePlugin)
273275
.settings(scalaModuleSettings: _*)
274276
.settings(
275277
description := "Examples for the Couchbase Scala SDK",
276-
version := "1.1.0-SNAPSHOT",
277278
// resolvers += "oss.sonatype.org-snapshot" at "https://oss.jfrog.org/artifactory/oss-snapshot-local",
278279
libraryDependencies ++= Seq(
279280
opentelemetry("sdk"),
@@ -302,6 +303,7 @@ lazy val aggregated = Seq[ProjectReference](
302303
`java-client`,
303304
`java-examples`,
304305
`scala-implicits`,
306+
`scala-macro`,
305307
`scala-client`,
306308
`scala-examples`,
307309
`test-utils`,

project/Dependencies.scala

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import sbt._
1+
import sbt.{Def, _}
22
import Keys._
33

44
object Dependencies {
55
object V {
6-
val crossScalaVersions = Seq("2.13.1", "2.12.10", "2.11.12")
7-
val scalaVersion = "2.13.1"
8-
val reactor = "3.3.1.RELEASE"
9-
val slf4j = "1.7.30"
10-
val netty = "4.1.45.Final"
11-
val nettyBoringssl = "2.0.28.Final"
12-
val jctools = "2.1.2" // 3.0.0
13-
val jackson = "2.10.1" // 2.10.2
14-
val snappy = "0.4"
15-
val latencyutils = "2.0.3"
16-
val log4jSlf4j = "2.13.0"
6+
val crossScala = Seq("2.13.1", "2.12.10", "2.11.12")
7+
val scala = "2.13.1"
8+
val reactor = "3.3.1.RELEASE"
9+
val slf4j = "1.7.30"
10+
val netty = "4.1.45.Final"
11+
val nettyBoringssl = "2.0.28.Final"
12+
val jctools = "2.1.2" // 3.0.0
13+
val jackson = "2.10.1" // 2.10.2
14+
val snappy = "0.4"
15+
val latencyutils = "2.0.3"
16+
val log4jSlf4j = "2.13.0"
1717
// jupiter-interface's version should be same as sbt-jupiter-interface's version in project/plugins.sbt
1818
val jupiterInterface = "0.8.3"
1919
val junit = "5.5.2"
@@ -25,7 +25,7 @@ object Dependencies {
2525
val opentracing = "0.33.0"
2626
val opentelemetry = "0.2.0"
2727
val scalaCollCompat = "2.1.3"
28-
val jsoniter = "0.9.23"
28+
// val jsoniter = "0.9.23"
2929
val jsoniterScala = "2.1.6"
3030
val json4s = "3.6.7"
3131
val jawnAst = "0.14.3"
@@ -156,16 +156,14 @@ object Dependencies {
156156
Seq(
157157
scalaCollCompat,
158158
jsoniterScala("core"),
159-
jsoniterScala("macros") % Provided,
160-
upickle.value % Optional
159+
upickle.value % Optional
161160
) ++ scalaModuleOptionalDeps.value
162161
}
163162

164163
def scalaClientDeps = Def.setting {
165164
Seq(
166165
reactorScala,
167166
jsoniterScala("core"),
168-
jsoniterScala("macros"), // FIXME should be `% Provided`
169167
scalaJava8Compat,
170168
scalaCollCompat,
171169
scalacheck % Test,

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resolvers += Resolver.jcenterRepo
22

33
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
4-
addSbtPlugin("com.sandinh" % "sbt-shade" % "0.1.2")
4+
addSbtPlugin("com.sandinh" % "sbt-shade" % "0.1.3")
55
addSbtPlugin("net.aichler" % "sbt-jupiter-interface" % "0.8.3")
66

77
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1")

scala-implicits/src/main/scala/com/couchbase/client/scala/implicits/CodecImplicits.scala renamed to scala-macro/src/main/scala/com/couchbase/client/scala/implicits/CodecImplicits.scala

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -62,67 +62,33 @@ private[scala] object CodecImplicits {
6262
// SCBC-158: Note on withSetMaxInsertNumber(100000) below. The default number of items allowed in Sets and Maps is a
6363
// conservative 1,024. Adjusting this to an arbitrary 100k.
6464

65-
// Implementation detail: the excellent JSON library Jsoniter, with the extensions from com.github.plokhotnyuk.jsoniter_scala,
65+
// Implementation detail: the excellent JSON library com.github.plokhotnyuk.jsoniter_scala
6666
// is currently used to encode and decode case classes. This is purely an implementation detail and should not be
6767
// relied upon.
68-
def makeDeserializer[T](
69-
c: scala.reflect.macros.blackbox.Context
70-
)(implicit e: c.WeakTypeTag[T]): c.universe.Tree = {
71-
import c.universe._
72-
q"""
73-
new JsonDeserializer[${e}] {
74-
import com.github.plokhotnyuk.jsoniter_scala.core._
75-
import com.github.plokhotnyuk.jsoniter_scala.macros._
76-
77-
implicit val jsonIterDecodeCodec: JsonValueCodec[$e] =
78-
JsonCodecMaker.make[$e](CodecMakerConfig.withSetMaxInsertNumber(100000).withMapMaxInsertNumber(100000))
79-
80-
override def deserialize(bytes: Array[Byte]): scala.util.Try[$e] = {
81-
scala.util.Try(readFromArray(bytes))
82-
}
83-
}
84-
"""
85-
}
86-
87-
def makeSerializer[T](
88-
c: scala.reflect.macros.blackbox.Context
89-
)(implicit e: c.WeakTypeTag[T]): c.universe.Tree = {
90-
import c.universe._
91-
q"""
92-
new JsonSerializer[$e] {
93-
import com.github.plokhotnyuk.jsoniter_scala.core._
94-
import com.github.plokhotnyuk.jsoniter_scala.macros._
95-
96-
implicit val jsonIterEncodeCodec: JsonValueCodec[$e] =
97-
JsonCodecMaker.make[$e](CodecMakerConfig.withSetMaxInsertNumber(100000).withMapMaxInsertNumber(100000))
98-
99-
override def serialize(content: $e): scala.util.Try[Array[Byte]] = {
100-
scala.util.Try(writeToArray(content))
101-
}
102-
}
103-
"""
104-
}
105-
10668
def makeCodec[T](
10769
c: scala.reflect.macros.blackbox.Context
10870
)(implicit e: c.WeakTypeTag[T]): c.universe.Tree = {
10971
import c.universe._
11072
q"""
11173
new Codec[$e] {
112-
import com.github.plokhotnyuk.jsoniter_scala.core._
113-
import com.github.plokhotnyuk.jsoniter_scala.macros._
114-
import scala.reflect.runtime.universe._
115-
import scala.util.{Failure, Success, Try}
74+
import com.github.plokhotnyuk.jsoniter_scala.core.{JsonValueCodec, readFromArray, writeToArray}
75+
import com.github.plokhotnyuk.jsoniter_scala.macros.{CodecMakerConfig, JsonCodecMaker}
76+
77+
import scala.util.Try
11678

11779
val jsonIterCodec: JsonValueCodec[$e] =
118-
JsonCodecMaker.make[$e](CodecMakerConfig.withSetMaxInsertNumber(100000).withMapMaxInsertNumber(100000))
80+
JsonCodecMaker.make[$e](
81+
CodecMakerConfig
82+
.withSetMaxInsertNumber(100000)
83+
.withMapMaxInsertNumber(100000)
84+
)
11985

12086
override def serialize(input: $e): Try[Array[Byte]] = {
121-
scala.util.Try(writeToArray(input)(jsonIterCodec))
87+
Try(writeToArray(input)(jsonIterCodec))
12288
}
12389

12490
override def deserialize(input: Array[Byte]): Try[$e] = {
125-
scala.util.Try(readFromArray(input)(jsonIterCodec))
91+
Try(readFromArray(input)(jsonIterCodec))
12692
}
12793
}
12894
"""

0 commit comments

Comments
 (0)