Skip to content

Commit

Permalink
Scala Core: add Scala 2.12 support (close #276)
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhanunlu committed Nov 20, 2017
1 parent bf51f6f commit 17450bd
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ package com.snowplowanalytics.iglu.core.circe

// Cats
import cats.data._
import cats.std.option._
import cats.instances.option._
import cats.syntax.cartesian._
import cats.syntax.either._

// Circe
import io.circe._
Expand Down Expand Up @@ -61,20 +62,20 @@ object CirceIgluCodecs {
Json.obj("schema" -> Json.fromString(data.schema.toSchemaUri), "data" -> data.data)
}

private[circe] def parseSchemaVer(hCursor: HCursor): Xor[DecodingFailure, SchemaVer] =
private[circe] def parseSchemaVer(hCursor: HCursor): Either[DecodingFailure, SchemaVer] =
for {
jsonString <- hCursor.as[String]
parsed = SchemaVer.parse(jsonString)
schemaVer <- Xor.fromOption(parsed, DecodingFailure("SchemaVer is missing", hCursor.history))
schemaVer <- Either.fromOption(parsed, DecodingFailure("SchemaVer is missing", hCursor.history))
} yield schemaVer

private[circe] def parseSchemaKey(hCursor: HCursor): Xor[DecodingFailure, SchemaKey] =
private[circe] def parseSchemaKey(hCursor: HCursor): Either[DecodingFailure, SchemaKey] =
for {
selfMap <- hCursor.as[JsonObject].map(_.toMap)
schemaKey <- selfMapToSchemaKey(selfMap, hCursor)
} yield schemaKey

private[circe] def selfMapToSchemaKey(selfMap: Map[String, Json], hCursor: HCursor): Xor[DecodingFailure, SchemaKey] = {
private[circe] def selfMapToSchemaKey(selfMap: Map[String, Json], hCursor: HCursor): Either[DecodingFailure, SchemaKey] = {
val self = (
selfMap.get("vendor") |@| selfMap.get("name") |@| selfMap.get("format") |@| selfMap.get("version")).map { (v, n, f, ver) =>
for {
Expand All @@ -85,6 +86,6 @@ object CirceIgluCodecs {
} yield SchemaKey(vendor, name, format, version)
}

Xor.fromOption(self.flatten, DecodingFailure("SchemaKey has incompatible format", hCursor.history))
Either.fromOption(self.flatten, DecodingFailure("SchemaKey has incompatible format", hCursor.history))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package com.snowplowanalytics.iglu.core.circe

import cats.syntax.either._

// Circe
import io.circe._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package com.snowplowanalytics.iglu.core.circe

import cats.syntax.either._

// specs2
import org.specs2.Specification

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ package com.snowplowanalytics.iglu.core.circe
// specs2
import org.specs2.Specification

import cats.syntax.either._

// circe
import io.circe._
import io.circe.parser.parse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ package com.snowplowanalytics.iglu.core.circe
// specs2
import org.specs2.Specification

import cats.syntax.either._

// circe
import io.circe._
import io.circe.parser.parse
Expand Down
4 changes: 2 additions & 2 deletions 0-common/scala-core/project/BuildSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ object BuildSettings {
lazy val commonSettings = Seq[Setting[_]](
organization := "com.snowplowanalytics",
version := "0.2.0",
scalaVersion := "2.11.8",
crossScalaVersions := Seq("2.10.6", "2.11.8"),
scalaVersion := "2.12.4",
crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.4"),
scalacOptions := Seq("-deprecation", "-encoding", "utf8", "-Yrangepos",
"-feature", "-unchecked", "-Xlog-reflective-calls",
"-Xlint"),
Expand Down
24 changes: 21 additions & 3 deletions 0-common/scala-core/project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
import sbt._
import Keys._

object Dependencies {
val resolutionRepos = Seq(
Expand All @@ -20,8 +21,12 @@ object Dependencies {
object V {
// Scala
val json4s = "3.2.11"
val circe = "0.4.1"
val specs2 = "3.3.1"
val circe = "0.8.0"
object specs2 {
val _210 = "3.3.1"
val _211 = "3.3.1"
val _212 = "3.9.5"
}
}

object Libraries {
Expand All @@ -31,6 +36,19 @@ object Dependencies {

// Scala (test only)
val json4sTest = "org.json4s" %% "json4s-jackson" % V.json4s % "test"
val specs2 = "org.specs2" %% "specs2-core" % V.specs2 % "test"
object specs2 {
val _210 = "org.specs2" %% "specs2-core" % V.specs2._210 % "test"
val _211 = "org.specs2" %% "specs2-core" % V.specs2._211 % "test"
val _212 = "org.specs2" %% "specs2-core" % V.specs2._212 % "test"
}
}

def onVersion[A](all: Seq[A] = Seq(), on210: => Seq[A] = Seq(), on211: => Seq[A] = Seq(), on212: => Seq[A] = Seq()) =
scalaVersion(v => all ++ (if (v.contains("2.10.")) {
on210
} else if (v.contains("2.11.")) {
on211
} else {
on212
}))
}
27 changes: 18 additions & 9 deletions 0-common/scala-core/project/IgluCoreBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,43 @@ object IgluCoreBuild extends Build {
lazy val project = Project("iglu-core", file("."))
.settings(buildSettings: _*)
.settings(
libraryDependencies ++= Seq(
libraryDependencies <++= Dependencies.onVersion(
all = Seq(
// Scala (test only)
Libraries.json4sTest,
Libraries.specs2
Libraries.json4sTest),
on210 = Seq(Libraries.specs2._210),
on211 = Seq(Libraries.specs2._211),
on212 = Seq(Libraries.specs2._212)
)
)

lazy val igluCoreJson4s = Project("iglu-core-json4s", file("iglu-core-json4s"))
.settings(json4sBuildSettings: _*)
.settings(
libraryDependencies ++= Seq(
libraryDependencies <++= Dependencies.onVersion(
all = Seq(
// Scala
Libraries.json4s,
Libraries.json4s),
// Scala (test only)
Libraries.specs2
on210 = Seq(Libraries.specs2._210),
on211 = Seq(Libraries.specs2._211),
on212 = Seq(Libraries.specs2._212)
)
)
.dependsOn(project)

lazy val igluCoreCirce = Project("iglu-core-circe", file("iglu-core-circe"))
.settings(circeBuildSettings: _*)
.settings(
libraryDependencies ++= Seq(
libraryDependencies <++= Dependencies.onVersion(
all = Seq(
// Scala
Libraries.circe,
Libraries.circeParser,
Libraries.circeParser),
// Scala (test only)
Libraries.specs2
on210 = Seq(Libraries.specs2._210),
on211 = Seq(Libraries.specs2._211),
on212 = Seq(Libraries.specs2._212)
)
)
.dependsOn(project)
Expand Down

0 comments on commit 17450bd

Please sign in to comment.