Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
Support Scala 2.13.x
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew de Detrich <[email protected]>
  • Loading branch information
mdedetrich committed Nov 3, 2019
1 parent ddea14c commit ab25646
Show file tree
Hide file tree
Showing 23 changed files with 159 additions and 77 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ services:

scala:
- 2.11.12
- 2.12.8
- 2.12.10
- 2.13.1

jdk: oraclejdk8

Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,23 @@ a year, including handling events from Zalando's main website search.

### Installation

Kanadi is currently deployed to OSS Sonatype. For Circe 0.11.x use Kanadi 0.4.x
Kanadi is currently deployed to OSS Sonatype. For Circe 0.12.x use Kanadi 0.5.x (also supports Scala 2.13.x)

```sbt
libraryDependencies ++= Seq(
"org.zalando" %% "kanadi" % "0.4.1"
"org.zalando" %% "kanadi" % "0.5.0"
)
```

Kanadi is currently deployed to OSS Sonatype. For Circe 0.10.x use Kanadi 0.3.x
For Circe 0.11.x use Kanadi 0.4.x

```sbt
libraryDependencies ++= Seq(
"org.zalando" %% "kanadi" % "0.4.2"
)
```

For Circe 0.10.x use Kanadi 0.3.x

```sbt
libraryDependencies ++= Seq(
Expand Down
149 changes: 98 additions & 51 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
name := """kanadi"""

val akkaHttpVersion = "10.1.8"
val akkaStreamsJsonVersion = "0.3.0"
val currentScalaVersion = "2.11.12"
val enumeratumCirceVersion = "1.5.20"
val circeVersion = "0.11.1"
val akkaVersion = "2.5.23"
val akkaHttpVersion = "10.1.9"
val akkaStreamsJsonLatestVersion = "0.4.0"
val akkaStreamsJsonOldVersion = "0.3.0"
val currentScalaVersion = "2.12.10"
val scala213Version = "2.13.1"
val enumeratumCirceLatestVersion = "1.5.22"
val enumeratumCirceOldVersion = "1.5.20"
val circeLatestVersion = "0.12.3" // for Scala 2.12 and 2.13
val circeOldVersion = "0.11.1" // only for scala 2.11
val akkaVersion = "2.5.26"
val specs2OldVersion = "4.3.4"
val specs2LatestVersion = "4.8.0"
val heikoseebergerAkkaHttpCirceOldVersion = "1.25.2"
val heikoseebergerAkkaHttpCirceLatestVersion = "1.29.1"

def circeVersion(scalaVer: String): String =
if (scalaVer.startsWith("2.11")) circeOldVersion else circeLatestVersion

def specs2Version(scalaVer: String): String =
if (scalaVer.startsWith("2.11")) specs2OldVersion else specs2LatestVersion

def enumeratumCirceVersion(scalaVer: String): String =
if (scalaVer.startsWith("2.11")) enumeratumCirceOldVersion else enumeratumCirceLatestVersion

def akkaStreamsJsonVersion(scalaVer: String): String =
if (scalaVer.startsWith("2.11")) akkaStreamsJsonOldVersion else akkaStreamsJsonLatestVersion

def heikoseebergerAkkaHttpCirceVersion(scalaVer: String): String =
if (scalaVer.startsWith("2.11")) heikoseebergerAkkaHttpCirceOldVersion else heikoseebergerAkkaHttpCirceLatestVersion

scalaVersion in ThisBuild := currentScalaVersion

crossScalaVersions in ThisBuild := Seq(currentScalaVersion, "2.12.8")
crossScalaVersions in ThisBuild := Seq("2.11.11", currentScalaVersion, "2.13.1")

organization := "org.zalando"

Expand All @@ -32,32 +55,23 @@ scalacOptions ++= Seq(
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
// "-Xfatal-warnings", // Fail the compilation if there are any warnings.
"-Xfuture", // Turn on future language features.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Xfuture", // Turn on future language features.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
//"-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.
"-Ypartial-unification", // Enable partial unification in type constructor inference
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Ywarn-nullary-unit", // Warn when nullary methods return Unit.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
)

val flagsFor11 = Seq(
Expand All @@ -66,41 +80,74 @@ val flagsFor11 = Seq(
"-Ywarn-infer-any",
"-Yclosure-elim",
"-Ydead-code",
"-Xsource:2.12" // required to build case class construction
"-Ypartial-unification",
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xsource:2.12" // required to build case class construction
)

val flagsFor12 = Seq(
"-Xlint:_",
"-Ywarn-infer-any",
"-Ypartial-unification",
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-opt-inline-from:<sources>"
)

val flagsFor13 = Seq(
"-Xlint:_",
"-opt-inline-from:<sources>"
)

scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n >= 12 =>
case Some((2, n)) if n == 13 =>
flagsFor13
case Some((2, n)) if n == 12 =>
flagsFor12
case Some((2, n)) if n == 11 =>
flagsFor11
}
}

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"org.mdedetrich" %% "censored-raw-header" % "0.2.0",
"org.mdedetrich" %% "webmodels" % "0.5.0",
"com.beachape" %% "enumeratum-circe" % enumeratumCirceVersion,
"io.circe" %% "circe-java8" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"org.mdedetrich" %% "akka-stream-circe" % akkaStreamsJsonVersion,
"org.mdedetrich" %% "akka-http-circe" % akkaStreamsJsonVersion,
"de.heikoseeberger" %% "akka-http-circe" % "1.25.2",
"com.iheart" %% "ficus" % "1.4.3",
"com.typesafe.scala-logging" %% "scala-logging" % "3.8.0",
"ch.qos.logback" % "logback-classic" % "1.1.7",
"org.specs2" %% "specs2-core" % "3.8.9" % Test
)
libraryDependencies ++= {
Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"org.mdedetrich" %% "censored-raw-header" % "0.4.0",
"org.mdedetrich" %% "webmodels" % "0.6.0",
"com.beachape" %% "enumeratum-circe" % enumeratumCirceVersion(scalaVersion.value),
"io.circe" %% "circe-parser" % circeVersion(scalaVersion.value),
"org.mdedetrich" %% "akka-stream-circe" % akkaStreamsJsonVersion(scalaVersion.value),
"org.mdedetrich" %% "akka-http-circe" % akkaStreamsJsonVersion(scalaVersion.value),
"de.heikoseeberger" %% "akka-http-circe" % heikoseebergerAkkaHttpCirceVersion(scalaVersion.value),
"com.iheart" %% "ficus" % "1.4.7",
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.2",
"ch.qos.logback" % "logback-classic" % "1.1.7",
"org.specs2" %% "specs2-core" % specs2Version(scalaVersion.value) % Test
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n == 13 =>
Seq(
"org.scala-lang.modules" %% "scala-parallel-collections" % "0.2.0" % Test
)
case Some((2, n)) if n == 11 =>
Seq(
"io.circe" %% "circe-java8" % circeVersion(scalaVersion.value)
)
case _ =>
Seq.empty
})
}

scalacOptions in Test ++= Seq("-Yrangepos")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.zalando.kanadi.api

private[this] object CrossVersionImports
extends io.circe.java8.time.JavaTimeDecoders
with io.circe.java8.time.JavaTimeEncoders
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.zalando.kanadi.api

private[this] object CrossVersionImports
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.zalando.kanadi.api

private[this] object CrossVersionImports
2 changes: 1 addition & 1 deletion src/main/scala/org/zalando/kanadi/api/EventTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.typesafe.scalalogging.{Logger, LoggerTakingImplicit}
import de.heikoseeberger.akkahttpcirce.ErrorAccumulatingCirceSupport._
import enumeratum._
import io.circe._
import io.circe.java8.time._
import CrossVersionImports._
import io.circe.syntax._
import org.mdedetrich.webmodels.{FlowId, OAuth2TokenProvider}
import org.mdedetrich.webmodels.RequestHeaders.`X-Flow-ID`
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/zalando/kanadi/api/Events.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.typesafe.scalalogging.{Logger, LoggerTakingImplicit}
import de.heikoseeberger.akkahttpcirce.ErrorAccumulatingCirceSupport._
import enumeratum._
import io.circe.Decoder.Result
import io.circe.java8.time._
import CrossVersionImports._
import io.circe.syntax._
import io.circe.{Decoder, Encoder, Json}
import org.mdedetrich.webmodels.{FlowId, OAuth2TokenProvider}
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/org/zalando/kanadi/api/Subscriptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import cats.syntax.either._
import com.typesafe.scalalogging.{Logger, LoggerTakingImplicit}
import de.heikoseeberger.akkahttpcirce.ErrorAccumulatingCirceSupport._
import enumeratum._
import io.circe.java8.time._
import CrossVersionImports._
import io.circe.{Decoder, Encoder, JsonObject}
import io.circe.syntax._
import org.zalando.kanadi.api.defaults._
Expand Down Expand Up @@ -955,7 +955,7 @@ case class Subscriptions(baseUri: URI, oAuth2TokenProvider: Option[OAuth2TokenPr
string
.grouped(kanadiHttpConfig.singleStringChunkLength)
.map(ByteString(_))
.to[List])
.toList)
.via(Framing.delimiter(ByteString("\n"), Int.MaxValue, allowTruncation = true))
.via(combinedJsonParserGraph)
.map {
Expand All @@ -965,7 +965,7 @@ case class Subscriptions(baseUri: URI, oAuth2TokenProvider: Option[OAuth2TokenPr
.limit(kanadiHttpConfig.eventListChunkLength.toLong)
.runWith(Sink.seq)
}
} yield result.to[List]
} yield result.toList
} else {
processNotSuccessful(response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import akka.http.scaladsl.model.headers.RawHeader

final case class CustomHeaders(headers: Map[String, String]) extends AnyVal {
def toRawHeaders: List[RawHeader] =
headers.to[List].map { case (k, v) => RawHeader(k, v) }
headers.toList.map { case (k, v) => RawHeader(k, v) }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package org.zalando.kanadi

import java.util.UUID

import akka.actor.ActorSystem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package org.zalando.kanadi

import java.util.UUID

import akka.actor.ActorSystem
Expand All @@ -10,13 +12,12 @@ import org.specs2.Specification
import org.specs2.concurrent.ExecutionEnv
import org.specs2.matcher.FutureMatchers
import org.specs2.specification.core.SpecStructure
import org.zalando.kanadi.Config
import org.zalando.kanadi.api.Subscriptions.{ConnectionClosedCallback, EventCallback, EventStreamContext}
import org.zalando.kanadi.api._
import org.zalando.kanadi.models._

import scala.concurrent.{Future, Promise}
import scala.concurrent.duration._
import scala.concurrent.{Future, Promise}
import scala.util.Success

final case class SomeBadEvent(firstName: String, lastName: Int, uuid: UUID)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package org.zalando.kanadi

import java.util.UUID

import akka.actor.ActorSystem
Expand All @@ -10,13 +12,12 @@ import org.specs2.Specification
import org.specs2.concurrent.ExecutionEnv
import org.specs2.matcher.FutureMatchers
import org.specs2.specification.core.SpecStructure
import org.zalando.kanadi.Config
import org.zalando.kanadi.api.Subscriptions.defaultEventStreamSupervisionDecider
import org.zalando.kanadi.api._
import org.zalando.kanadi.models._

import scala.concurrent.duration._
import scala.concurrent.Promise
import scala.concurrent.duration._
import scala.util.Success

class BasicSourceSpec(implicit ec: ExecutionEnv) extends Specification with FutureMatchers with Config {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package org.zalando.kanadi

import java.util.UUID
import java.util.concurrent.atomic.{AtomicBoolean, AtomicInteger}

Expand All @@ -10,7 +12,6 @@ import org.specs2.Specification
import org.specs2.concurrent.ExecutionEnv
import org.specs2.matcher.FutureMatchers
import org.specs2.specification.core.SpecStructure
import org.zalando.kanadi.Config
import org.zalando.kanadi.api.Subscriptions.{
ConnectionClosedCallback,
EventCallback,
Expand All @@ -19,8 +20,8 @@ import org.zalando.kanadi.api.Subscriptions.{
import org.zalando.kanadi.api._
import org.zalando.kanadi.models._

import scala.concurrent.{Future, Promise}
import scala.concurrent.duration._
import scala.concurrent.{Future, Promise}
import scala.util.Success

class BasicSpec(implicit ec: ExecutionEnv) extends Specification with FutureMatchers with Config {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package org.zalando.kanadi

import java.util.UUID

import akka.actor.ActorSystem
Expand All @@ -11,7 +13,6 @@ import org.specs2.Specification
import org.specs2.concurrent.ExecutionEnv
import org.specs2.matcher.FutureMatchers
import org.specs2.specification.core.SpecStructure
import org.zalando.kanadi.Config
import org.zalando.kanadi.api._
import org.zalando.kanadi.models.{EventTypeName, SubscriptionId}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package org.zalando.kanadi

import java.util.UUID

import akka.actor.ActorSystem
Expand All @@ -11,7 +13,6 @@ import org.specs2.Specification
import org.specs2.concurrent.ExecutionEnv
import org.specs2.matcher.FutureMatchers
import org.specs2.specification.core.SpecStructure
import org.zalando.kanadi.Config
import org.zalando.kanadi.api._
import org.zalando.kanadi.models.{EventTypeName, SubscriptionId}

Expand Down
Loading

0 comments on commit ab25646

Please sign in to comment.