Skip to content

Commit 7d93888

Browse files
authored
Merge pull request #561 from hughsimpson/scala_3
2 parents 2566e8b + 873776a commit 7d93888

File tree

51 files changed

+683
-510
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+683
-510
lines changed

.github/workflows/ci.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
strategy:
2828
matrix:
2929
os: [ubuntu-latest]
30-
scala: [2.13.6, 2.12.14]
30+
scala: [2.13.6, 2.12.14, 3.0.1]
3131
3232
runs-on: ${{ matrix.os }}
3333
steps:
@@ -133,6 +133,16 @@ jobs:
133133
tar xf targets.tar
134134
rm targets.tar
135135
136+
- name: Download target directories (3.0.1)
137+
uses: actions/download-artifact@v2
138+
with:
139+
name: target-${{ matrix.os }}-3.0.1-${{ matrix.java }}
140+
141+
- name: Inflate target directories (3.0.1)
142+
run: |
143+
tar xf targets.tar
144+
rm targets.tar
145+
136146
- uses: olafurpg/setup-gpg@v3
137147

138148
- run: sbt ++${{ matrix.scala }} ci-release

.scalafmt.conf

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
align = more
1+
align.preset = "more"
22
maxColumn = 120
3-
version = 2.3.2
3+
version = "3.0.2"
4+
fileOverride {
5+
"glob:**/src/main/scala-3/**" {
6+
runner.dialect = scala3
7+
}
8+
}

build.sbt

+41-37
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
inThisBuild(
22
List(
33
organization := "com.github.cb372",
4-
homepage := Some(url("https://github.com/cb372/scalacache")),
5-
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
4+
homepage := Some(url("https://github.com/cb372/scalacache")),
5+
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
66
developers := List(
77
Developer(
88
"cb372",
@@ -14,6 +14,8 @@ inThisBuild(
1414
)
1515
)
1616

17+
val CatsEffectVersion = "3.2.7"
18+
1719
scalafmtOnCompile in ThisBuild := true
1820

1921
lazy val root: Project = Project(id = "scalacache", base = file("."))
@@ -36,13 +38,13 @@ lazy val core =
3638
.settings(
3739
moduleName := "scalacache-core",
3840
libraryDependencies ++= Seq(
39-
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
40-
"org.slf4j" % "slf4j-api" % "1.7.30",
41-
"org.typelevel" %% "cats-effect" % "3.0.2",
41+
"org.slf4j" % "slf4j-api" % "1.7.30",
42+
"org.typelevel" %% "cats-effect" % CatsEffectVersion,
4243
scalatest,
4344
scalacheck
44-
),
45-
coverageMinimum := 60,
45+
) ++ (if (scalaVersion.value.startsWith("2.")) Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value)
46+
else Nil),
47+
coverageMinimum := 60,
4648
coverageFailOnMinimum := true
4749
)
4850

@@ -67,31 +69,31 @@ lazy val redis = createModule("redis")
6769
libraryDependencies ++= Seq(
6870
"redis.clients" % "jedis" % "2.10.2"
6971
),
70-
coverageMinimum := 56,
72+
coverageMinimum := 56,
7173
coverageFailOnMinimum := true
7274
)
7375

7476
lazy val caffeine = createModule("caffeine")
7577
.settings(
7678
libraryDependencies ++= Seq(
77-
"com.github.ben-manes.caffeine" % "caffeine" % "2.9.0",
78-
"org.typelevel" %% "cats-effect-testkit" % "3.0.2" % Test,
79-
"com.google.code.findbugs" % "jsr305" % "3.0.2" % Provided
79+
"com.github.ben-manes.caffeine" % "caffeine" % "2.9.0",
80+
"org.typelevel" %% "cats-effect-testkit" % CatsEffectVersion % Test,
81+
"com.google.code.findbugs" % "jsr305" % "3.0.2" % Provided
8082
),
81-
coverageMinimum := 80,
83+
coverageMinimum := 80,
8284
coverageFailOnMinimum := true
8385
)
8486

8587
lazy val circe = createModule("circe")
8688
.settings(
8789
libraryDependencies ++= Seq(
88-
"io.circe" %% "circe-core" % "0.13.0",
89-
"io.circe" %% "circe-parser" % "0.13.0",
90-
"io.circe" %% "circe-generic" % "0.13.0" % Test,
90+
"io.circe" %% "circe-core" % "0.14.1",
91+
"io.circe" %% "circe-parser" % "0.14.1",
92+
"io.circe" %% "circe-generic" % "0.14.1" % Test,
9193
scalacheck,
9294
scalatestplus
9395
),
94-
coverageMinimum := 80,
96+
coverageMinimum := 80,
9597
coverageFailOnMinimum := true
9698
)
9799

@@ -102,19 +104,19 @@ lazy val tests = createModule("tests")
102104
lazy val docs = createModule("docs")
103105
.enablePlugins(MicrositesPlugin)
104106
.settings(
105-
publishArtifact := false,
106-
micrositeName := "ScalaCache",
107-
micrositeAuthor := "Chris Birchall",
107+
publishArtifact := false,
108+
micrositeName := "ScalaCache",
109+
micrositeAuthor := "Chris Birchall",
108110
micrositeDescription := "A facade for the most popular cache implementations, with a simple, idiomatic Scala API.",
109-
micrositeBaseUrl := "/scalacache",
111+
micrositeBaseUrl := "/scalacache",
110112
micrositeDocumentationUrl := "/scalacache/docs",
111-
micrositeHomepage := "https://github.com/cb372/scalacache",
112-
micrositeGithubOwner := "cb372",
113-
micrositeGithubRepo := "scalacache",
114-
micrositeGitterChannel := true,
115-
micrositeTwitterCreator := "@cbirchall",
116-
micrositeShareOnSocial := true,
117-
mdocIn := (sourceDirectory in Compile).value / "mdoc"
113+
micrositeHomepage := "https://github.com/cb372/scalacache",
114+
micrositeGithubOwner := "cb372",
115+
micrositeGithubRepo := "scalacache",
116+
micrositeGitterChannel := true,
117+
micrositeTwitterCreator := "@cbirchall",
118+
micrositeShareOnSocial := true,
119+
mdocIn := (sourceDirectory in Compile).value / "mdoc"
118120
)
119121
.dependsOn(
120122
core,
@@ -127,7 +129,7 @@ lazy val docs = createModule("docs")
127129
lazy val benchmarks = createModule("benchmarks")
128130
.enablePlugins(JmhPlugin)
129131
.settings(
130-
publishArtifact := false,
132+
publishArtifact := false,
131133
fork in (Compile, run) := true,
132134
javaOptions in Jmh ++= Seq("-server", "-Xms2G", "-Xmx2G", "-XX:+UseG1GC", "-XX:-UseBiasedLocking"),
133135
javaOptions in (Test, run) ++= Seq(
@@ -143,11 +145,11 @@ lazy val benchmarks = createModule("benchmarks")
143145
)
144146
.dependsOn(caffeine)
145147

146-
lazy val scalatest = "org.scalatest" %% "scalatest" % "3.2.8" % Test
148+
lazy val scalatest = "org.scalatest" %% "scalatest" % "3.2.9" % Test
147149

148150
lazy val scalacheck = "org.scalacheck" %% "scalacheck" % "1.15.3" % Test
149151

150-
lazy val scalatestplus = "org.scalatestplus" %% "scalacheck-1-15" % "3.2.5.0" % Test
152+
lazy val scalatestplus = "org.scalatestplus" %% "scalacheck-1-15" % "3.2.9.0" % Test
151153

152154
lazy val commonSettings =
153155
mavenSettings ++
@@ -164,12 +166,13 @@ lazy val mavenSettings = Seq(
164166
}
165167
)
166168

169+
val Scala30 = "3.0.1"
167170
val Scala213 = "2.13.6"
168171
val Scala212 = "2.12.14"
169-
val Jdk11 = "[email protected]"
172+
val Jdk11 = "[email protected]"
170173

171-
ThisBuild / scalaVersion := Scala213
172-
ThisBuild / crossScalaVersions := Seq(Scala213, Scala212)
174+
ThisBuild / scalaVersion := Scala213
175+
ThisBuild / crossScalaVersions := Seq(Scala213, Scala212, Scala30)
173176
ThisBuild / githubWorkflowJavaVersions := Seq(Jdk11)
174177
ThisBuild / githubWorkflowBuild := Seq(
175178
WorkflowStep.Sbt(List("scalafmtCheckAll"), name = Some("Check Formatting")),
@@ -181,8 +184,9 @@ ThisBuild / githubWorkflowBuild := Seq(
181184
//sbt-ci-release settings
182185
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
183186
ThisBuild / githubWorkflowPublishTargetBranches := Seq(RefPredicate.StartsWith(Ref.Tag("v")))
184-
ThisBuild / githubWorkflowPublishPreamble := Seq(WorkflowStep.Use(UseRef.Public("olafurpg", "setup-gpg", "v3")))
185-
ThisBuild / githubWorkflowPublish := Seq(WorkflowStep.Sbt(List("ci-release")))
186-
ThisBuild / githubWorkflowEnv ++= List("PGP_PASSPHRASE", "PGP_SECRET", "SONATYPE_PASSWORD", "SONATYPE_USERNAME").map { envKey =>
187-
envKey -> s"$${{ secrets.$envKey }}"
187+
ThisBuild / githubWorkflowPublishPreamble := Seq(WorkflowStep.Use(UseRef.Public("olafurpg", "setup-gpg", "v3")))
188+
ThisBuild / githubWorkflowPublish := Seq(WorkflowStep.Sbt(List("ci-release")))
189+
ThisBuild / githubWorkflowEnv ++= List("PGP_PASSPHRASE", "PGP_SECRET", "SONATYPE_PASSWORD", "SONATYPE_USERNAME").map {
190+
envKey =>
191+
envKey -> s"$${{ secrets.$envKey }}"
188192
}.toMap

modules/benchmarks/src/main/scala/scalacache/benchmark/CaffeineBenchmark.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import cats.effect.Clock
1515
@State(Scope.Thread)
1616
class CaffeineBenchmark {
1717

18-
implicit val clockSyncIO = Clock[SyncIO]
18+
implicit val clockSyncIO: Clock[SyncIO] = Clock[SyncIO]
1919

2020
val underlyingCache = Caffeine.newBuilder().build[String, Entry[String]]()
2121
implicit val cache: Cache[SyncIO, String] = CaffeineCache[SyncIO, String](underlyingCache)

modules/benchmarks/src/test/scala/scalacache/benchmark/ProfilingMemoize.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import scalacache.memoization._
88
import cats.effect.SyncIO
99
import cats.effect.Clock
1010

11-
/**
12-
* Just runs forever, endlessly calling memoize, so Java Flight Recorder can output sampling data.
11+
/** Just runs forever, endlessly calling memoize, so Java Flight Recorder can output sampling data.
1312
*/
1413
object ProfilingMemoize extends App {
1514

modules/caffeine/src/main/scala/scalacache/caffeine/CaffeineCache.scala

+9-11
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import cats.MonadError
1919
*
2020
* This cache implementation is synchronous.
2121
*/
22-
class CaffeineCache[F[_]: Sync, V](val underlying: CCache[String, Entry[V]])(
23-
implicit val config: CacheConfig,
22+
class CaffeineCache[F[_]: Sync, V](val underlying: CCache[String, Entry[V]])(implicit
23+
val config: CacheConfig,
2424
clock: Clock[F]
2525
) extends AbstractCache[F, V] {
2626
protected val F: Sync[F] = Sync[F]
@@ -29,9 +29,8 @@ class CaffeineCache[F[_]: Sync, V](val underlying: CCache[String, Entry[V]])(
2929

3030
def doGet(key: String): F[Option[V]] = {
3131
F.delay {
32-
Option(underlying.getIfPresent(key))
33-
}
34-
.flatMap(_.filterA(Entry.isExpired[F, V]))
32+
Option(underlying.getIfPresent(key))
33+
}.flatMap(_.filterA(Entry.isExpired[F, V]))
3534
.map(_.map(_.value))
3635
.flatTap { result =>
3736
logCacheHitOrMiss(key, result)
@@ -49,7 +48,7 @@ class CaffeineCache[F[_]: Sync, V](val underlying: CCache[String, Entry[V]])(
4948
override def doRemove(key: String): F[Unit] =
5049
F.delay(underlying.invalidate(key))
5150

52-
override def doRemoveAll(): F[Unit] =
51+
override def doRemoveAll: F[Unit] =
5352
F.delay(underlying.invalidateAll())
5453

5554
override def close: F[Unit] = {
@@ -64,16 +63,15 @@ class CaffeineCache[F[_]: Sync, V](val underlying: CCache[String, Entry[V]])(
6463

6564
object CaffeineCache {
6665

67-
/**
68-
* Create a new Caffeine cache.
66+
/** Create a new Caffeine cache.
6967
*/
7068
def apply[F[_]: Sync: Clock, V](implicit config: CacheConfig): F[CaffeineCache[F, V]] =
7169
Sync[F].delay(Caffeine.newBuilder().build[String, Entry[V]]()).map(apply(_))
7270

73-
/**
74-
* Create a new cache utilizing the given underlying Caffeine cache.
71+
/** Create a new cache utilizing the given underlying Caffeine cache.
7572
*
76-
* @param underlying a Caffeine cache
73+
* @param underlying
74+
* a Caffeine cache
7775
*/
7876
def apply[F[_]: Sync: Clock, V](
7977
underlying: CCache[String, Entry[V]]

modules/circe/src/test/scala/scalacache/serialization/CirceCodecSpec.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CirceCodecSpec extends AnyFlatSpec with Matchers with ScalaCheckDrivenProp
1616
import scalacache.serialization.circe._
1717

1818
private def serdesCheck[A: Arbitrary](expectedJson: A => String)(implicit codec: Codec[A]): Unit = {
19-
forAll(minSuccessful(10000)) { a: A =>
19+
forAll(minSuccessful(10000)) { (a: A) =>
2020
val serialised = codec.encode(a)
2121
new String(serialised, "utf-8") shouldBe expectedJson(a)
2222
val deserialised = codec.decode(serialised)

modules/core/src/main/scala/scalacache/memoization/Macros.scala modules/core/src/main/scala-2/scalacache/memoization/Macros.scala

+19-17
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@ class Macros(val c: blackbox.Context) {
1212
def memoizeImpl[F[_], V: c.WeakTypeTag](
1313
ttl: c.Expr[Option[Duration]]
1414
)(f: c.Tree)(cache: c.Expr[Cache[F, V]], flags: c.Expr[Flags]): c.Tree = {
15-
commonMacroImpl(cache, { keyName =>
16-
q"""$cache.cachingForMemoize($keyName)($ttl)($f)($flags)"""
17-
})
15+
commonMacroImpl(
16+
cache,
17+
{ keyName =>
18+
q"""$cache.cachingForMemoize($keyName)($ttl)($f)($flags)"""
19+
}
20+
)
1821
}
1922

2023
def memoizeFImpl[F[_], V: c.WeakTypeTag](
2124
ttl: c.Expr[Option[Duration]]
2225
)(f: c.Tree)(cache: c.Expr[Cache[F, V]], flags: c.Expr[Flags]): c.Tree = {
23-
commonMacroImpl(cache, { keyName =>
24-
q"""$cache.cachingForMemoizeF($keyName)($ttl)($f)($flags)"""
25-
})
26+
commonMacroImpl(
27+
cache,
28+
{ keyName =>
29+
q"""$cache.cachingForMemoizeF($keyName)($ttl)($f)($flags)"""
30+
}
31+
)
2632
}
2733

2834
private def commonMacroImpl[F[_], V: c.WeakTypeTag](
@@ -45,7 +51,7 @@ class Macros(val c: blackbox.Context) {
4551

4652
val keyName = createKeyName()
4753
val cachingCall = keyNameToCachingCall(keyName)
48-
val tree = q"""
54+
val tree = q"""
4955
val $keyName = $cache.config.memoization.toStringConverter.toString($classNameTree, $classParamssTree, $methodNameTree, $methodParamssTree)
5056
$cachingCall
5157
"""
@@ -54,9 +60,7 @@ class Macros(val c: blackbox.Context) {
5460
tree
5561
}
5662

57-
/**
58-
* Get the symbol of the method that encloses the macro,
59-
* or abort the compilation if we can't find one.
63+
/** Get the symbol of the method that encloses the macro, or abort the compilation if we can't find one.
6064
*/
6165
private def getMethodSymbol(): c.Symbol = {
6266

@@ -76,8 +80,7 @@ class Macros(val c: blackbox.Context) {
7680
getMethodSymbolRecursively(c.internal.enclosingOwner)
7781
}
7882

79-
/**
80-
* Convert the given method symbol to a tree representing the method name.
83+
/** Convert the given method symbol to a tree representing the method name.
8184
*/
8285
private def getMethodName(methodSymbol: c.Symbol): c.Tree = {
8386
val methodName = methodSymbol.asMethod.name.toString
@@ -98,10 +101,10 @@ class Macros(val c: blackbox.Context) {
98101
getClassSymbolRecursively(c.internal.enclosingOwner)
99102
}
100103

101-
/**
102-
* Convert the given class symbol to a tree representing the fully qualified class name.
104+
/** Convert the given class symbol to a tree representing the fully qualified class name.
103105
*
104-
* @param classSymbol should be either a ClassSymbol or a ModuleSymbol
106+
* @param classSymbol
107+
* should be either a ClassSymbol or a ModuleSymbol
105108
*/
106109
private def getFullClassName(classSymbol: c.Symbol): c.Tree = {
107110
val className = classSymbol.fullName
@@ -135,8 +138,7 @@ class Macros(val c: blackbox.Context) {
135138
listToTree(identss.map(is => listToTree(is)))
136139
}
137140

138-
/**
139-
* Convert a List[Tree] to a Tree representing `Vector`
141+
/** Convert a List[Tree] to a Tree representing `Vector`
140142
*/
141143
private def listToTree(ts: List[c.Tree]): c.Tree = {
142144
q"_root_.scala.collection.immutable.Vector(..$ts)"

0 commit comments

Comments
 (0)