Skip to content

Commit

Permalink
Merge pull request #42 from Powerspace/feat-scala-2.13-cross-version
Browse files Browse the repository at this point in the history
feat: scala 2.13 cross version
  • Loading branch information
rlebran authored Sep 17, 2019
2 parents c2fc32a + 280b954 commit baa4ccd
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 88 deletions.
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ dist: trusty
language: scala

scala:
- 2.12.8
- 2.12.10
- 2.13.0

jdk:
- oraclejdk8

cache:
directories:
- $HOME/.cache
- $HOME/.ivy2/cache
- $HOME/.sbt

script:
- sbt ++$TRAVIS_SCALA_VERSION -Dsbt.log.noformat=true clean test
- sbt ++$TRAVIS_SCALA_VERSION -Dsbt.supershell=false -Dsbt.log.noformat=true clean test
5 changes: 3 additions & 2 deletions akka-http-marshallers/build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
val akkaHttpVersion = "10.1.0"
val akkaHttpJsonVersion = "1.20.0"
val akkaVersion = "2.5.25"
val akkaHttpVersion = "10.1.9"
val akkaHttpJsonVersion = "1.28.0"

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http-core" % akkaHttpVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ object BidSwitchDealSerde extends ConfiguredSerde {
import io.circe._
import io.circe.generic.extras.semiauto._

implicit val dealExtEncoder: Encoder[DealExt] = deriveEncoder[DealExt].cleanRtb
implicit val dealExtEncoder: Encoder[DealExt] = deriveConfiguredEncoder[DealExt].cleanRtb

val dealExtDecoder: Decoder[DealExt] = deriveDecoder[DealExt]
val dealExtDecoder: Decoder[DealExt] = deriveConfiguredDecoder[DealExt]

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ object BidSwitchImpressionSerde extends ConfiguredSerde {
import io.circe.generic.extras.semiauto._

private implicit val googleImpressionEncoder: Encoder[com.powerspace.bidswitch.ImpressionExt.Google] =
deriveEncoder[com.powerspace.bidswitch.ImpressionExt.Google].cleanRtb
deriveConfiguredEncoder[com.powerspace.bidswitch.ImpressionExt.Google].cleanRtb
private implicit val yieldoneImpressionEncoder: Encoder[com.powerspace.bidswitch.ImpressionExt.Yieldone] =
deriveEncoder[com.powerspace.bidswitch.ImpressionExt.Yieldone].cleanRtb
deriveConfiguredEncoder[com.powerspace.bidswitch.ImpressionExt.Yieldone].cleanRtb

val impressionExtEncoder: Encoder[ImpressionExt] = deriveEncoder[ImpressionExt].cleanRtb
val impressionExtEncoder: Encoder[ImpressionExt] = deriveConfiguredEncoder[ImpressionExt].cleanRtb

private implicit val googleImpressionDecoder: Decoder[com.powerspace.bidswitch.ImpressionExt.Google] =
deriveDecoder[com.powerspace.bidswitch.ImpressionExt.Google]
deriveConfiguredDecoder[com.powerspace.bidswitch.ImpressionExt.Google]
private implicit val yieldoneImpressionDecoder: Decoder[com.powerspace.bidswitch.ImpressionExt.Yieldone] =
deriveDecoder[com.powerspace.bidswitch.ImpressionExt.Yieldone]
deriveConfiguredDecoder[com.powerspace.bidswitch.ImpressionExt.Yieldone]

val impressionExtDecoder: Decoder[ImpressionExt] = deriveDecoder[ImpressionExt]
val impressionExtDecoder: Decoder[ImpressionExt] = deriveConfiguredDecoder[ImpressionExt]

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class BidSwitchSerdeTest extends FunSuite with GivenWhenThen {
test("BidSwitch BidResponse deserialization") {
Given("A BidSwitch BidResponse in JSON format")
val stream: URL = getClass.getResource("/bidswitch-bidresponse.json")
val json: String = scala.io.Source.fromFile(stream.toURI).mkString
val source = scala.io.Source.fromFile(stream.toURI)
val json: String = source.mkString
source.close()

When("I deserialize it")
val decoded = decode[BidResponse](json)
Expand Down Expand Up @@ -57,7 +59,9 @@ class BidSwitchSerdeTest extends FunSuite with GivenWhenThen {
test("BidSwitch bid response serialization with no-bid") {
Given("An BidSwitch bid response in JSON format with no bid")
val stream: URL = getClass.getResource("/bidswitch-bidresponse-no-bid.json")
val json: String = scala.io.Source.fromFile(stream.toURI).mkString
val source = scala.io.Source.fromFile(stream.toURI)
val json: String = source.mkString
source.close()

When("I deserialize it")
val decoded = decode[BidResponse](json)
Expand Down
19 changes: 10 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name := "scala-openrtb"

version in ThisBuild := "1.2.0"
version in ThisBuild := "1.3.0"

scalaVersion in ThisBuild := "2.12.8"
organization in ThisBuild := "com.powerspace.openrtb"
organizationName in ThisBuild := "Powerspace"
organizationHomepage := Some(url("https://powerspace.com/"))
scalaVersion in ThisBuild := "2.13.0"
crossScalaVersions in ThisBuild := Seq("2.12.10", "2.13.0")
organization in ThisBuild := "com.powerspace.openrtb"
organizationName in ThisBuild := "Powerspace"
organizationHomepage := Some(url("https://powerspace.com/"))

scalacOptions in ThisBuild := Seq(
"-unchecked",
Expand All @@ -18,7 +19,6 @@ scalacOptions in ThisBuild := Seq(
"-unchecked",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-unused-import",
"-language:postfixOps",
"-language:implicitConversions",
"-language:existentials",
Expand All @@ -29,9 +29,9 @@ publishArtifact in root := false

val testSettings = Seq(
libraryDependencies ++= Seq(
"org.scalactic" %% "scalactic" % "3.0.1" % "test",
"org.scalatest" %% "scalatest" % "3.0.1" % "test",
"org.scalamock" %% "scalamock-scalatest-support" % "3.5.0" % "test")
"org.scalactic" %% "scalactic" % "3.0.8" % "test",
"org.scalatest" %% "scalatest" % "3.0.8" % "test",
"org.scalamock" %% "scalamock" % "4.4.0" % "test")
)

// OpenRTB Scala model
Expand Down Expand Up @@ -74,6 +74,7 @@ lazy val root = (project in file("."))
openRtbJson,
bidswitchModel,
bidswitchJson,
akkaHttpMarshaller,
examples,
benchmarks
)
8 changes: 4 additions & 4 deletions examples/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
val http4sVersion = "0.20.0-M6"
val akkaHttpVersion = "10.1.0"
val akkaHttpJsonVersion = "1.20.0"
val monixVersion = "3.0.0-RC2"
val http4sVersion = "0.21.0-M4"
val akkaHttpVersion = "10.1.9"
val akkaHttpJsonVersion = "1.28.0"
val monixVersion = "3.0.0"

PB.targets in Compile := Seq(
scalapb.gen(flatPackage = true) -> (sourceManaged in Compile).value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Bidder[F[_]: Applicative] extends OpenrtbBidder[F] {
* Provide a list of [[com.google.openrtb.BidResponse.SeatBid.Bid]] given a list
* of [[com.google.openrtb.BidRequest.Imp]]
*/
private def bidOnImps(imps: Traversable[Imp]): F[Traversable[Bid]] = {
private def bidOnImps(imps: Iterable[Imp]): F[Iterable[Bid]] = {
imps
.flatMap(bidOnImp)
.pure[F]
Expand Down
8 changes: 4 additions & 4 deletions openrtb-json/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
val circeVersion = "0.11.0"
val circeVersion = "0.12.1"

libraryDependencies ++= Seq(
"io.circe" %% "circe-core",
Expand All @@ -7,6 +7,6 @@ libraryDependencies ++= Seq(
"io.circe" %% "circe-generic-extras"
).map(_ % circeVersion)

libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.5" % "test"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test"
libraryDependencies += "org.gnieh" %% "diffson-circe" % "3.0.0" % "test"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.8" % "test"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test"
libraryDependencies += "org.gnieh" %% "diffson-circe" % "4.0.0-M5" % "test"
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.circe.JsonObject.fromIterable
import io.circe._
import io.circe.generic.extras.Configuration
import io.circe.generic.extras.decoding.ConfiguredDecoder
import io.circe.generic.extras.encoding.ConfiguredObjectEncoder
import io.circe.generic.extras.encoding.ConfiguredAsObjectEncoder
import scalapb.{ExtendableMessage, GeneratedExtension, GeneratedMessage}
import shapeless.Lazy

Expand Down Expand Up @@ -91,7 +91,7 @@ object OpenRtbExtensions {

def registerExtension[Extendable <: ExtendableMessage[Extendable], Extension <: scalapb.GeneratedMessage](
extension: OpenRtbExtension[Extendable, Extension])(
implicit encoder: Lazy[ConfiguredObjectEncoder[Extension]],
implicit encoder: Lazy[ConfiguredAsObjectEncoder[Extension]],
decoder: Lazy[ConfiguredDecoder[Extension]],
extendableTag: ClassTag[Extendable],
extensionTag: ClassTag[Extension]): ExtensionRegistry = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class OpenRtbImpressionSerde(implicit extensionRegistry: ExtensionRegistry) exte

import EncodingUtils._

implicit val metricEncoder: Encoder[Imp.Metric] = deriveEncoder[Imp.Metric].cleanRtb
implicit val metricEncoder: Encoder[Imp.Metric] = deriveConfiguredEncoder[Imp.Metric].cleanRtb

def encoder(
implicit bannerEncoder: Encoder[Imp.Banner],
Expand All @@ -50,7 +50,7 @@ class OpenRtbImpressionSerde(implicit extensionRegistry: ExtensionRegistry) exte
nativeEncode: Encoder[Imp.Native]): Encoder[Imp] =
extendedEncoder[Imp]

implicit val metricDecoder: Decoder[Imp.Metric] = deriveDecoder[Imp.Metric]
implicit val metricDecoder: Decoder[Imp.Metric] = deriveConfiguredDecoder[Imp.Metric]

def decoder(
implicit bannerDecoder: Decoder[Imp.Banner],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class OpenRtbSeatBidSerde(bidSerde: OpenRtbBidSerde)(implicit er: ExtensionRegis
private implicit val bidEncoder: Encoder[SeatBid.Bid] = bidSerde.encoder

implicit def encoder: Encoder[BidResponse.SeatBid] =
deriveEncoder[BidResponse.SeatBid].cleanRtb
deriveConfiguredEncoder[BidResponse.SeatBid].cleanRtb

implicit def decoder(implicit bidDecoder: Decoder[BidResponse.SeatBid.Bid]): Decoder[BidResponse.SeatBid] =
cursor =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.powerspace.openrtb.json.util

import com.powerspace.openrtb.json.OpenRtbExtensions.ExtensionRegistry
import io.circe._
import io.circe.generic.extras.encoding.ConfiguredObjectEncoder
import io.circe.generic.extras.Configuration
import io.circe.generic.extras.decoding.ConfiguredDecoder
import io.circe.generic.extras.encoding.ConfiguredAsObjectEncoder
import scalapb.{ExtendableMessage, GeneratedEnumCompanion, UnknownFieldSet}
import shapeless.Lazy

Expand All @@ -13,28 +13,30 @@ import scala.util.Try

object EncodingUtils {

import PrimitivesUtils._
import io.circe.generic.extras.semiauto._

import scala.reflect.runtime.universe.TypeTag
import scala.reflect.runtime.{currentMirror => cm}
import PrimitivesUtils._

private implicit val customConfig: Configuration = Configuration.default.withSnakeCaseMemberNames.withDefaults

def extendedEncoder[Ext <: ExtendableMessage[Ext]](
implicit encoder: Lazy[ConfiguredObjectEncoder[Ext]],
implicit encoder: Lazy[ConfiguredAsObjectEncoder[Ext]],
er: ExtensionRegistry,
tag: ClassTag[Ext]): Encoder[Ext] =
er.encoderWithExtensions[Ext](baseEncoder = openRtbEncoder)

def openRtbEncoder[A](implicit encoder: Lazy[ConfiguredAsObjectEncoder[A]]): Encoder[A] =
deriveConfiguredEncoder[A](encoder).cleanRtb

def extendedDecoder[Ext <: ExtendableMessage[Ext]](
implicit encoder: Lazy[ConfiguredDecoder[Ext]],
er: ExtensionRegistry,
tag: ClassTag[Ext]): Decoder[Ext] =
er.decoderWithExtensions[Ext](baseDecoder = openRtbDecoder)

def openRtbEncoder[A](implicit encoder: Lazy[ConfiguredObjectEncoder[A]]): Encoder[A] =
deriveEncoder[A](encoder).cleanRtb
def openRtbDecoder[A](implicit decoder: Lazy[ConfiguredDecoder[A]]): Decoder[A] = deriveDecoder[A](decoder)
def openRtbDecoder[A](implicit decoder: Lazy[ConfiguredDecoder[A]]): Decoder[A] = deriveConfiguredDecoder[A](decoder)

/**
* Unknown fields Encoder
Expand All @@ -44,18 +46,7 @@ object EncodingUtils {

implicit class EncoderEnhancement[T](encoder: Encoder[T]) {

/**
* Clean up the JSON file from empty fields/arrays unless present within the given list
*/
def clean(toKeep: Seq[String] = Seq()): Encoder[T] = {
encoder.mapJson(jsonObject =>
jsonObject.mapObject(obj =>
obj.filter {
case (_, Json.Null) => false
case (id, json) if json.isArray && json.asArray.exists(_.isEmpty) && !toKeep.contains(id) => false
case _ => true
}))
}
def cleanRtb: Encoder[T] = renameOneof.clean.transformBooleans

/**
* Transform boolean fields into the related integers
Expand All @@ -69,26 +60,37 @@ object EncodingUtils {
})
}

def cleanRtb: Encoder[T] = renameOneof.clean.transformBooleans

def rename(renames: Map[String, String]): Encoder[T] =
def renameOneof: Encoder[T] =
encoder.mapJson({
_.mapObject(obj =>
JsonObject.fromIterable(obj.toIterable.map {
case (key, json) => (renames.getOrElse(key, key), json)
case (key, json) => (key.stripSuffix("_oneof"), json)
}))
})

def renameOneof: Encoder[T] =
def clean: Encoder[T] = clean(Seq())

/**
* Clean up the JSON file from empty fields/arrays unless present within the given list
*/
def clean(toKeep: Seq[String] = Seq()): Encoder[T] = {
encoder.mapJson(jsonObject =>
jsonObject.mapObject(obj =>
obj.filter {
case (_, Json.Null) => false
case (id, json) if json.isArray && json.asArray.exists(_.isEmpty) && !toKeep.contains(id) => false
case _ => true
}))
}

def rename(renames: Map[String, String]): Encoder[T] =
encoder.mapJson({
_.mapObject(obj =>
JsonObject.fromIterable(obj.toIterable.map {
case (key, json) => (key.stripSuffix("_oneof"), json)
case (key, json) => (renames.getOrElse(key, key), json)
}))
})

def clean: Encoder[T] = clean(Seq())

}

/**
Expand Down
Loading

0 comments on commit baa4ccd

Please sign in to comment.