Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest versions, add Scala 2.13 #5

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ You just add the [jawn support facade](https://github.com/non/jawn#supporting-ex
of your choice and you will can parsed into their respective Json AST.


For Http support, either `import org.mdedetrich.akka.http.JsonSupport._`
or mixin `... with org.mdedetrich.akka.http.JsonSupport`.
For Http support, either `import com.akka.http.JsonSupport._`
or mixin `... with com.qmee.akka.http.JsonSupport`.

Given an implicit jawn facade, this enable you to decode into the respective Json AST
using the Akka HTTP marshalling framework. As jawn is only about parsing and does not abstract
Expand All @@ -84,7 +84,7 @@ Adding support for a specific framework is
These support modules allow you to directly marshall from/unmarshall into your data types
using circes `Decoder` and `Encoder` type classes.

Just mixin or import `org.mdedetrich.akka.http.support.CirceHttpSupport` for Http
Just mixin or import `com.qmee.akka.http.support.CirceHttpSupport` for Http
or pipe your `Source[ByteString, _].via(org.mdedetrich.akka.stream.CirceStreamSupport.decode[A])`
to get a `Source[A, _]`.

Expand Down
54 changes: 37 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name := "akka-streams-json"

val currentScalaVersion = "2.12.7"
val currentScalaVersion = "2.12.8"
val scala211Version = "2.11.12"
val circeVersion = "0.11.1"
val akkaVersion = "2.5.17"
val akkaHttpVersion = "10.1.5"
val jawnVersion = "0.14.1"
val scalaTestVersion = "3.0.5"

scalaVersion in ThisBuild := currentScalaVersion
crossScalaVersions in ThisBuild := Seq(currentScalaVersion, scala211Version)
organization in ThisBuild := "org.mdedetrich"
val scala213Version = "2.13.0"
val circeVersion = "0.12.0-RC4" //"0.11.1"
val akkaVersion = "2.5.25"
val akkaHttpVersion = "10.1.9"
val jawnVersion = "0.14.2"
val scalaTestVersion = "3.0.8"

scalaVersion in ThisBuild := scala213Version
crossScalaVersions in ThisBuild := Seq(currentScalaVersion, scala211Version, scala213Version)
organization in ThisBuild := "com.qmee" //"org.mdedetrich"
publishTo in ThisBuild := Some("Qmee Repo" at "s3://qmee-ivy-repo/")

lazy val streamJson = project.in(file("stream-json")) settings (
name := "akka-stream-json",
Expand Down Expand Up @@ -59,9 +61,9 @@ scalacOptions in ThisBuild ++= Seq(
"-unchecked", // additional warnings where generated code depends on assumptions
"-Xlint", // recommended additional warnings
"-Xcheckinit", // runtime error when a val is not initialized due to trait hierarchies (instead of NPE somewhere else)
"-Ywarn-adapted-args", // Warn if an argument list is modified to match the receiver

"-Ywarn-value-discard", // Warn when non-Unit expression results are unused
"-Ywarn-inaccessible",

"-Ywarn-dead-code",
"-language:postfixOps"
)
Expand All @@ -81,25 +83,28 @@ scmInfo in ThisBuild := Some(

developers in ThisBuild := List(
Developer("knutwalker", "Paul Horn", "", url("https://github.com/knutwalker/")),
Developer("mdedetrich", "Matthew de Detrich", "[email protected]", url("https://github.com/mdedetrich"))
Developer("mdedetrich", "Matthew de Detrich", "[email protected]", url("https://github.com/mdedetrich")),
Developer("jknight", "Jonathan Knight", "", url("https://github.com/JonathanKnight"))
)

licenses in ThisBuild += ("Apache-2.0", url("https://opensource.org/licenses/Apache-2.0"))

publishMavenStyle in ThisBuild := true

/*
publishTo in ThisBuild := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
*/

publishArtifact in Test in ThisBuild := false

pomIncludeRepository in ThisBuild := (_ => false)

//pomIncludeRepository in ThisBuild := (_ => false)
/*
import ReleaseTransformations._
releaseCrossBuild := true
releasePublishArtifactsAction := PgpKeys.publishSigned.value // Use publishSigned in publishArtifacts step
Expand All @@ -118,23 +123,38 @@ releaseProcess := Seq[ReleaseStep](
pushChanges
)

*/

val flagsFor11 = Seq(
"-Xlint:_",
"-Yconst-opt",
"-Ywarn-infer-any",
"-Yclosure-elim",
"-Ydead-code"
"-Ydead-code",
"-Ywarn-adapted-args", // Warn if an argument list is modified to match the receiver
"-Ywarn-inaccessible"
)

val flagsFor12 = Seq(
"-Xlint:_",
"-Ywarn-infer-any",
"-opt-inline-from:<sources>",
"-Ywarn-adapted-args", // Warn if an argument list is modified to match the receiver
"-Ywarn-inaccessible"
)

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


scalacOptions in ThisBuild ++= {
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.mdedetrich.akka.http
package com.qmee.akka.http

import akka.http.scaladsl.model.HttpEntity
import akka.http.scaladsl.model.MediaTypes.`application/json`
import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller}
import akka.http.scaladsl.util.FastFuture
import org.mdedetrich.akka.json.stream.JsonStreamParser
import com.qmee.akka.json.stream.JsonStreamParser
import org.typelevel.jawn.RawFacade

trait JsonSupport {
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.1.4
sbt.version=1.2.8
8 changes: 6 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")
//addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")

addSbtPlugin("com.thoughtworks.sbt-api-mappings" % "sbt-api-mappings" % "2.1.0")

addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.9")
//addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.9")

addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.3.0")

addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.4.0")

addSbtPlugin("com.frugalmechanic" % "fm-sbt-s3-resolver" % "0.18.0")
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.mdedetrich.akka.json.stream
package com.qmee.akka.json.stream

import java.nio.ByteBuffer

import akka.NotUsed
import akka.stream.Attributes.name
import akka.stream._
import akka.stream.scaladsl.{Flow, Keep, Sink}
import akka.stream.stage.{GraphStage, GraphStageLogic, InHandler, OutHandler}
import akka.stream._
import akka.util.ByteString
import org.typelevel.jawn.AsyncParser.ValueStream
import org.typelevel.jawn._
Expand All @@ -13,7 +15,6 @@ import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.Future
import scala.util.Try
import java.nio.ByteBuffer

object JsonStreamParser {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package org.mdedetrich.akka.http.support
package com.qmee.akka.http.support

import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller}
import akka.http.scaladsl.model.MediaTypes.`application/json`
import akka.http.scaladsl.unmarshalling.FromEntityUnmarshaller
import io.circe.jawn.CirceSupportParser._
import com.qmee.akka.http.JsonSupport
import com.qmee.akka.stream.support.{CirceStreamSupport, CirceSupportParser}
import io.circe.{Decoder, Encoder, Json, Printer}

import org.mdedetrich.akka.http.JsonSupport
import org.mdedetrich.akka.stream.support.CirceStreamSupport

trait CirceHttpSupport extends JsonSupport {

implicit def circeJsonUnmarshaller: FromEntityUnmarshaller[Json] =
jsonUnmarshaller[Json]
jsonUnmarshaller[Json](CirceSupportParser.facade)

implicit def circeUnmarshaller[A: Decoder]: FromEntityUnmarshaller[A] =
circeJsonUnmarshaller.map(CirceStreamSupport.decodeJson[A])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
package org.mdedetrich.akka.stream
package support
package com.qmee.akka.stream.support

import akka.NotUsed
import akka.stream.scaladsl.Flow
import akka.util.ByteString
import com.qmee.akka.json.stream.JsonStreamParser
import io.circe.CursorOp.DownField
import io.circe.jawn.CirceSupportParser._
import io.circe._
import org.mdedetrich.akka.json.stream.JsonStreamParser
import org.typelevel.jawn.AsyncParser

trait CirceStreamSupport {

def decode[A: Decoder]: Flow[ByteString, A, NotUsed] =
JsonStreamParser.flow[Json].map(decodeJson[A])
JsonStreamParser.flow[Json](CirceSupportParser.facade).map(decodeJson[A])

def decode[A: Decoder](mode: AsyncParser.Mode): Flow[ByteString, A, NotUsed] =
JsonStreamParser.flow[Json](mode).map(decodeJson[A])
JsonStreamParser.flow[Json](mode)(CirceSupportParser.facade).map(decodeJson[A])

def encode[A](implicit A: Encoder[A], P: Printer = Printer.noSpaces): Flow[A, String, NotUsed] =
Flow[A].map(a => P.pretty(A(a)))

case class JsonParsingException(df: DecodingFailure, cursor: HCursor)
extends Exception(errorMessage(df.history, cursor, df.message), df)

private[mdedetrich] def decodeJson[A](json: Json)(implicit decoder: Decoder[A]): A = {
private[qmee] def decodeJson[A](json: Json)(implicit decoder: Decoder[A]): A = {
val cursor = json.hcursor
decoder(cursor) match {
case Right(e) => e
Expand All @@ -47,4 +45,4 @@ trait CirceStreamSupport {
}
}

object CirceStreamSupport extends CirceStreamSupport
object CirceStreamSupport extends CirceStreamSupport
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.qmee.akka.stream.support

object CirceSupportParser extends io.circe.jawn.CirceSupportParser(None,true)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mdedetrich.akka.http
package com.qmee.akka.http

import akka.actor.ActorSystem
import akka.http.scaladsl.marshalling.Marshal
Expand All @@ -9,10 +9,10 @@ import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Keep, Sink, Source}
import akka.util.ByteString
import com.qmee.akka.http.support.CirceHttpSupport
import com.qmee.akka.stream.support.CirceStreamSupport
import io.circe.generic.semiauto._
import io.circe.{Decoder, Encoder, Printer}
import org.mdedetrich.akka.http.support.CirceHttpSupport
import org.mdedetrich.akka.stream.support.CirceStreamSupport
import org.scalatest._
import org.typelevel.jawn.ParseException

Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.3.0"
version in ThisBuild := "0.3.3"