From 1046ae7d9742030f58271f89521782193fa59d42 Mon Sep 17 00:00:00 2001 From: Heiko Seeberger Date: Fri, 26 Mar 2021 16:41:20 +0100 Subject: [PATCH] Refactor build (#562) * Fix build * Refactor build --- .github/workflows/release.yml | 14 +-- .github/workflows/test.yml | 3 +- .scalafmt.conf | 1 + .../akkahttpargonaut/ArgonautSupport.scala | 2 - .../ArgonautSupportSpec.scala | 5 +- .../akkahttpavro4s/AvroSupport.scala | 18 ++-- .../akkahttpavro4s/AvroSupportSpec.scala | 9 +- .../akkahttpavro4s/ExampleApp.scala | 1 - .../akkahttpcirce/CirceSupport.scala | 4 +- .../akkahttpcirce/CirceSupportSpec.scala | 5 +- .../akkahttpcirce/ExampleApp.scala | 3 +- .../akkahttpjackson/JacksonSupport.scala | 12 +-- .../akkahttpjackson/ExampleApp.scala | 1 - .../akkahttpjackson/JacksonSupportSpec.scala | 9 +- .../akkahttpjson4s/Json4sSupport.scala | 4 +- .../akkahttpjson4s/ExampleApp.scala | 1 - .../akkahttpjson4s/Json4sSupportSpec.scala | 9 +- .../JsoniterScalaSupport.scala | 1 - .../akkahttpjsoniterscala/ExampleApp.scala | 1 - .../JsoniterScalaSupportSpec.scala | 9 +- .../akkahttpninny/NinnySupport.scala | 6 +- .../akkahttpninny/NinnySupportSpec.scala | 10 +- .../akkahttpplayjson/PlayJsonSupport.scala | 1 - .../akkahttpplayjson/ExampleApp.scala | 1 - .../PlayJsonSupportSpec.scala | 9 +- .../UpickleCustomizationSupport.scala | 3 +- .../UpickleCustomizationSupportSpec.scala | 10 +- .../akkahttpziojson/ZioJsonSupport.scala | 10 +- .../akkahttpziojson/ExampleApp.scala | 5 +- .../akkahttpziojson/ZioJsonSupportSpec.scala | 16 +-- build.sbt | 97 ++++++++++--------- 31 files changed, 124 insertions(+), 156 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 12ed8797..7d9c6620 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,15 +6,17 @@ on: jobs: publish: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v1 - - uses: olafurpg/setup-scala@v2 - - uses: olafurpg/setup-gpg@v2 + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: olafurpg/setup-scala@v10 + - uses: olafurpg/setup-gpg@v3 - name: Publish ${{ github.ref }} run: sbt ci-release env: - PGP_SECRET: ${{ secrets.PGP_SECRET }} PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} - SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + PGP_SECRET: ${{ secrets.PGP_SECRET }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 95b5571a..3a24cf11 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,10 +5,11 @@ on: branches: [ master ] pull_request: branches: [ master ] + workflow_dispatch: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Set up JDK 11 diff --git a/.scalafmt.conf b/.scalafmt.conf index 4f53d398..a5a4ad81 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -8,3 +8,4 @@ unindentTopLevelOperators = true spaces.inImportCurlyBraces = true rewrite.rules = ["AsciiSortImports", "RedundantBraces", "RedundantParens"] docstrings.blankFirstLine = true +trailingCommas = preserve diff --git a/akka-http-argonaut/src/main/scala/de/heikoseeberger/akkahttpargonaut/ArgonautSupport.scala b/akka-http-argonaut/src/main/scala/de/heikoseeberger/akkahttpargonaut/ArgonautSupport.scala index 6f07d92b..2055265a 100644 --- a/akka-http-argonaut/src/main/scala/de/heikoseeberger/akkahttpargonaut/ArgonautSupport.scala +++ b/akka-http-argonaut/src/main/scala/de/heikoseeberger/akkahttpargonaut/ArgonautSupport.scala @@ -26,10 +26,8 @@ import akka.http.scaladsl.util.FastFuture import akka.stream.scaladsl.{ Flow, Source } import akka.util.ByteString import argonaut.{ DecodeJson, EncodeJson, Json, Parse, PrettyParams } - import scala.collection.immutable.Seq import scala.concurrent.Future -import scala.util.Try import scala.util.control.NonFatal /** diff --git a/akka-http-argonaut/src/test/scala/de/heikoseeberger/akkahttpargonaut/ArgonautSupportSpec.scala b/akka-http-argonaut/src/test/scala/de/heikoseeberger/akkahttpargonaut/ArgonautSupportSpec.scala index d5a0f1cc..0b108023 100644 --- a/akka-http-argonaut/src/test/scala/de/heikoseeberger/akkahttpargonaut/ArgonautSupportSpec.scala +++ b/akka-http-argonaut/src/test/scala/de/heikoseeberger/akkahttpargonaut/ArgonautSupportSpec.scala @@ -25,11 +25,10 @@ import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeExcep import akka.stream.scaladsl.{ Sink, Source } import argonaut.Argonaut._ import org.scalatest.BeforeAndAfterAll - -import scala.concurrent.Await -import scala.concurrent.duration.DurationInt import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AsyncWordSpec +import scala.concurrent.Await +import scala.concurrent.duration.DurationInt object ArgonautSupportSpec { diff --git a/akka-http-avro4s/src/main/scala/de/heikoseeberger/akkahttpavro4s/AvroSupport.scala b/akka-http-avro4s/src/main/scala/de/heikoseeberger/akkahttpavro4s/AvroSupport.scala index 40e9575b..256b9ba4 100644 --- a/akka-http-avro4s/src/main/scala/de/heikoseeberger/akkahttpavro4s/AvroSupport.scala +++ b/akka-http-avro4s/src/main/scala/de/heikoseeberger/akkahttpavro4s/AvroSupport.scala @@ -16,19 +16,24 @@ package de.heikoseeberger.akkahttpavro4s -import java.io.ByteArrayOutputStream - import akka.http.javadsl.common.JsonEntityStreamingSupport import akka.http.scaladsl.common.EntityStreamingSupport import akka.http.scaladsl.marshalling.{ Marshaller, Marshalling, ToEntityMarshaller } -import akka.http.scaladsl.model.MediaTypes.`application/json` import akka.http.scaladsl.model._ +import akka.http.scaladsl.model.MediaTypes.`application/json` import akka.http.scaladsl.unmarshalling.{ FromEntityUnmarshaller, Unmarshal, Unmarshaller } import akka.http.scaladsl.util.FastFuture import akka.stream.scaladsl.{ Flow, Source } import akka.util.ByteString -import com.sksamuel.avro4s._ - +import com.sksamuel.avro4s.{ + AvroInputStream, + AvroOutputStream, + AvroSchema, + Decoder, + Encoder, + SchemaFor +} +import java.io.ByteArrayOutputStream import scala.collection.immutable.Seq import scala.concurrent.Future import scala.util.Try @@ -70,7 +75,7 @@ trait AvroSupport { private def jsonSource[A: SchemaFor: Encoder](entitySource: SourceOf[A])(implicit support: JsonEntityStreamingSupport - ): SourceOf[ByteString] = { + ): SourceOf[ByteString] = entitySource .map { obj => val baos = new ByteArrayOutputStream() @@ -81,7 +86,6 @@ trait AvroSupport { } .map(ByteString(_)) .via(support.framingRenderer) - } def unmarshallerContentTypes: Seq[ContentTypeRange] = defaultContentTypes diff --git a/akka-http-avro4s/src/test/scala/de/heikoseeberger/akkahttpavro4s/AvroSupportSpec.scala b/akka-http-avro4s/src/test/scala/de/heikoseeberger/akkahttpavro4s/AvroSupportSpec.scala index 6e5f231d..ade5100a 100644 --- a/akka-http-avro4s/src/test/scala/de/heikoseeberger/akkahttpavro4s/AvroSupportSpec.scala +++ b/akka-http-avro4s/src/test/scala/de/heikoseeberger/akkahttpavro4s/AvroSupportSpec.scala @@ -18,18 +18,17 @@ package de.heikoseeberger.akkahttpavro4s import akka.actor.ActorSystem import akka.http.scaladsl.marshalling.Marshal -import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.model._ -import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException +import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller } +import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException import akka.stream.scaladsl.{ Sink, Source } import com.sksamuel.avro4s.{ Decoder, Encoder, SchemaFor } import org.scalatest.BeforeAndAfterAll - -import scala.concurrent.Await -import scala.concurrent.duration.DurationInt import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AsyncWordSpec +import scala.concurrent.Await +import scala.concurrent.duration.DurationInt object AvroSupportSpec { diff --git a/akka-http-avro4s/src/test/scala/de/heikoseeberger/akkahttpavro4s/ExampleApp.scala b/akka-http-avro4s/src/test/scala/de/heikoseeberger/akkahttpavro4s/ExampleApp.scala index 26d3f395..b6772eed 100644 --- a/akka-http-avro4s/src/test/scala/de/heikoseeberger/akkahttpavro4s/ExampleApp.scala +++ b/akka-http-avro4s/src/test/scala/de/heikoseeberger/akkahttpavro4s/ExampleApp.scala @@ -24,7 +24,6 @@ import akka.http.scaladsl.server.Directives import akka.http.scaladsl.unmarshalling.Unmarshal import akka.stream.scaladsl.Source import com.sksamuel.avro4s.{ FromRecord, SchemaFor, ToRecord } - import scala.concurrent.Await import scala.concurrent.duration._ import scala.io.StdIn diff --git a/akka-http-circe/src/main/scala/de/heikoseeberger/akkahttpcirce/CirceSupport.scala b/akka-http-circe/src/main/scala/de/heikoseeberger/akkahttpcirce/CirceSupport.scala index f60d515f..3f58b2fe 100644 --- a/akka-http-circe/src/main/scala/de/heikoseeberger/akkahttpcirce/CirceSupport.scala +++ b/akka-http-circe/src/main/scala/de/heikoseeberger/akkahttpcirce/CirceSupport.scala @@ -32,14 +32,12 @@ import akka.http.scaladsl.util.FastFuture import akka.stream.scaladsl.{ Flow, Source } import akka.util.ByteString import cats.data.{ NonEmptyList, ValidatedNel } -import cats.syntax.show.toShow import cats.syntax.either.catsSyntaxEither +import cats.syntax.show.toShow import io.circe.{ Decoder, DecodingFailure, Encoder, Json, Printer, jawn } import io.circe.parser.parse - import scala.collection.immutable.Seq import scala.concurrent.Future -import scala.util.Try import scala.util.control.NonFatal /** diff --git a/akka-http-circe/src/test/scala/de/heikoseeberger/akkahttpcirce/CirceSupportSpec.scala b/akka-http-circe/src/test/scala/de/heikoseeberger/akkahttpcirce/CirceSupportSpec.scala index 955d8f2f..c70cce7f 100644 --- a/akka-http-circe/src/test/scala/de/heikoseeberger/akkahttpcirce/CirceSupportSpec.scala +++ b/akka-http-circe/src/test/scala/de/heikoseeberger/akkahttpcirce/CirceSupportSpec.scala @@ -35,11 +35,10 @@ import io.circe.{ DecodingFailure, Encoder, ParsingFailure, Printer } import io.circe.CursorOp.DownField import org.scalatest.{ BeforeAndAfterAll, EitherValues } import org.scalatest.concurrent.ScalaFutures - -import scala.concurrent.Await -import scala.concurrent.duration.DurationInt import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AsyncWordSpec +import scala.concurrent.Await +import scala.concurrent.duration.DurationInt object CirceSupportSpec { diff --git a/akka-http-circe/src/test/scala/de/heikoseeberger/akkahttpcirce/ExampleApp.scala b/akka-http-circe/src/test/scala/de/heikoseeberger/akkahttpcirce/ExampleApp.scala index 40529c8d..2045d8d0 100644 --- a/akka-http-circe/src/test/scala/de/heikoseeberger/akkahttpcirce/ExampleApp.scala +++ b/akka-http-circe/src/test/scala/de/heikoseeberger/akkahttpcirce/ExampleApp.scala @@ -23,9 +23,8 @@ import akka.http.scaladsl.model.{ HttpRequest, RequestEntity } import akka.http.scaladsl.server.Directives import akka.http.scaladsl.unmarshalling.Unmarshal import akka.stream.scaladsl.Source - -import scala.io.StdIn import scala.concurrent.duration._ +import scala.io.StdIn object ExampleApp { diff --git a/akka-http-jackson/src/main/scala/de/heikoseeberger/akkahttpjackson/JacksonSupport.scala b/akka-http-jackson/src/main/scala/de/heikoseeberger/akkahttpjackson/JacksonSupport.scala index b7f98db3..910c0269 100644 --- a/akka-http-jackson/src/main/scala/de/heikoseeberger/akkahttpjackson/JacksonSupport.scala +++ b/akka-http-jackson/src/main/scala/de/heikoseeberger/akkahttpjackson/JacksonSupport.scala @@ -16,8 +16,6 @@ package de.heikoseeberger.akkahttpjackson -import java.lang.reflect.{ ParameterizedType, Type => JType } - import akka.http.javadsl.common.JsonEntityStreamingSupport import akka.http.javadsl.marshallers.jackson.Jackson import akka.http.scaladsl.common.EntityStreamingSupport @@ -31,7 +29,7 @@ import akka.util.ByteString import com.fasterxml.jackson.core.`type`.TypeReference import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.scala.DefaultScalaModule - +import java.lang.reflect.{ ParameterizedType, Type => JType } import scala.collection.immutable.Seq import scala.concurrent.Future import scala.reflect.runtime.universe._ @@ -77,11 +75,9 @@ trait JacksonSupport { mirror.runtimeClass(t) else new ParameterizedType { - def getRawType = mirror.runtimeClass(t) - - def getActualTypeArguments = t.typeArgs.map(mapType).toArray - - def getOwnerType = null + def getRawType() = mirror.runtimeClass(t) + def getActualTypeArguments() = t.typeArgs.map(mapType).toArray + def getOwnerType() = null } new TypeReference[T] { diff --git a/akka-http-jackson/src/test/scala/de/heikoseeberger/akkahttpjackson/ExampleApp.scala b/akka-http-jackson/src/test/scala/de/heikoseeberger/akkahttpjackson/ExampleApp.scala index bd0df821..692fae15 100644 --- a/akka-http-jackson/src/test/scala/de/heikoseeberger/akkahttpjackson/ExampleApp.scala +++ b/akka-http-jackson/src/test/scala/de/heikoseeberger/akkahttpjackson/ExampleApp.scala @@ -22,7 +22,6 @@ import akka.http.scaladsl.model.HttpRequest import akka.http.scaladsl.server.Directives import akka.http.scaladsl.unmarshalling.Unmarshal import akka.stream.scaladsl.Source - import scala.concurrent.Await import scala.concurrent.duration._ import scala.io.StdIn diff --git a/akka-http-jackson/src/test/scala/de/heikoseeberger/akkahttpjackson/JacksonSupportSpec.scala b/akka-http-jackson/src/test/scala/de/heikoseeberger/akkahttpjackson/JacksonSupportSpec.scala index 571911d1..84c3ddc4 100644 --- a/akka-http-jackson/src/test/scala/de/heikoseeberger/akkahttpjackson/JacksonSupportSpec.scala +++ b/akka-http-jackson/src/test/scala/de/heikoseeberger/akkahttpjackson/JacksonSupportSpec.scala @@ -18,17 +18,16 @@ package de.heikoseeberger.akkahttpjackson import akka.actor.ActorSystem import akka.http.scaladsl.marshalling.Marshal -import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.model._ -import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException +import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller } +import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException import akka.stream.scaladsl.{ Sink, Source } import org.scalatest.BeforeAndAfterAll - -import scala.concurrent.Await -import scala.concurrent.duration.DurationInt import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AsyncWordSpec +import scala.concurrent.Await +import scala.concurrent.duration.DurationInt object JacksonSupportSpec { diff --git a/akka-http-json4s/src/main/scala/de/heikoseeberger/akkahttpjson4s/Json4sSupport.scala b/akka-http-json4s/src/main/scala/de/heikoseeberger/akkahttpjson4s/Json4sSupport.scala index b35816e7..7edb50f3 100644 --- a/akka-http-json4s/src/main/scala/de/heikoseeberger/akkahttpjson4s/Json4sSupport.scala +++ b/akka-http-json4s/src/main/scala/de/heikoseeberger/akkahttpjson4s/Json4sSupport.scala @@ -16,8 +16,6 @@ package de.heikoseeberger.akkahttpjson4s -import java.lang.reflect.InvocationTargetException - import akka.http.javadsl.common.JsonEntityStreamingSupport import akka.http.scaladsl.common.EntityStreamingSupport import akka.http.scaladsl.marshalling.{ Marshaller, Marshalling, ToEntityMarshaller } @@ -29,8 +27,8 @@ import akka.stream.Materializer import akka.stream.scaladsl.{ Flow, Source } import akka.util.ByteString import de.heikoseeberger.akkahttpjson4s.Json4sSupport.ShouldWritePretty.False +import java.lang.reflect.InvocationTargetException import org.json4s.{ Formats, MappingException, Serialization } - import scala.collection.immutable.Seq import scala.concurrent.{ ExecutionContext, Future } import scala.util.Try diff --git a/akka-http-json4s/src/test/scala/de/heikoseeberger/akkahttpjson4s/ExampleApp.scala b/akka-http-json4s/src/test/scala/de/heikoseeberger/akkahttpjson4s/ExampleApp.scala index dd35d403..464e67be 100644 --- a/akka-http-json4s/src/test/scala/de/heikoseeberger/akkahttpjson4s/ExampleApp.scala +++ b/akka-http-json4s/src/test/scala/de/heikoseeberger/akkahttpjson4s/ExampleApp.scala @@ -23,7 +23,6 @@ import akka.http.scaladsl.server.Directives import akka.http.scaladsl.unmarshalling.Unmarshal import akka.stream.scaladsl.Source import org.json4s.{ DefaultFormats, jackson } - import scala.concurrent.Await import scala.concurrent.duration._ import scala.io.StdIn diff --git a/akka-http-json4s/src/test/scala/de/heikoseeberger/akkahttpjson4s/Json4sSupportSpec.scala b/akka-http-json4s/src/test/scala/de/heikoseeberger/akkahttpjson4s/Json4sSupportSpec.scala index f4428481..da999084 100644 --- a/akka-http-json4s/src/test/scala/de/heikoseeberger/akkahttpjson4s/Json4sSupportSpec.scala +++ b/akka-http-json4s/src/test/scala/de/heikoseeberger/akkahttpjson4s/Json4sSupportSpec.scala @@ -18,18 +18,17 @@ package de.heikoseeberger.akkahttpjson4s import akka.actor.ActorSystem import akka.http.scaladsl.marshalling.Marshal -import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.model._ -import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException +import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller } +import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException import akka.stream.scaladsl.{ Sink, Source } import org.json4s.{ DefaultFormats, jackson, native } import org.scalatest.BeforeAndAfterAll - -import scala.concurrent.Await -import scala.concurrent.duration.DurationInt import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AsyncWordSpec +import scala.concurrent.Await +import scala.concurrent.duration.DurationInt object Json4sSupportSpec { diff --git a/akka-http-jsoniter-scala/src/main/scala/de/heikoseeberger/akkahttpjsoniterscala/JsoniterScalaSupport.scala b/akka-http-jsoniter-scala/src/main/scala/de/heikoseeberger/akkahttpjsoniterscala/JsoniterScalaSupport.scala index dd063528..52c46f7e 100644 --- a/akka-http-jsoniter-scala/src/main/scala/de/heikoseeberger/akkahttpjsoniterscala/JsoniterScalaSupport.scala +++ b/akka-http-jsoniter-scala/src/main/scala/de/heikoseeberger/akkahttpjsoniterscala/JsoniterScalaSupport.scala @@ -32,7 +32,6 @@ import akka.http.scaladsl.util.FastFuture import akka.stream.scaladsl.{ Flow, Source } import akka.util.ByteString import com.github.plokhotnyuk.jsoniter_scala.core._ - import scala.collection.immutable.Seq import scala.concurrent.Future import scala.util.Try diff --git a/akka-http-jsoniter-scala/src/test/scala/de/heikoseeberger/akkahttpjsoniterscala/ExampleApp.scala b/akka-http-jsoniter-scala/src/test/scala/de/heikoseeberger/akkahttpjsoniterscala/ExampleApp.scala index 4d8f88cc..ae3d3bba 100644 --- a/akka-http-jsoniter-scala/src/test/scala/de/heikoseeberger/akkahttpjsoniterscala/ExampleApp.scala +++ b/akka-http-jsoniter-scala/src/test/scala/de/heikoseeberger/akkahttpjsoniterscala/ExampleApp.scala @@ -22,7 +22,6 @@ import akka.http.scaladsl.model.HttpRequest import akka.http.scaladsl.server.{ Directives, Route } import akka.http.scaladsl.unmarshalling.Unmarshal import akka.stream.scaladsl.Source - import scala.concurrent.Await import scala.concurrent.duration._ import scala.io.StdIn diff --git a/akka-http-jsoniter-scala/src/test/scala/de/heikoseeberger/akkahttpjsoniterscala/JsoniterScalaSupportSpec.scala b/akka-http-jsoniter-scala/src/test/scala/de/heikoseeberger/akkahttpjsoniterscala/JsoniterScalaSupportSpec.scala index ee83a93d..f7b82cea 100644 --- a/akka-http-jsoniter-scala/src/test/scala/de/heikoseeberger/akkahttpjsoniterscala/JsoniterScalaSupportSpec.scala +++ b/akka-http-jsoniter-scala/src/test/scala/de/heikoseeberger/akkahttpjsoniterscala/JsoniterScalaSupportSpec.scala @@ -18,19 +18,18 @@ package de.heikoseeberger.akkahttpjsoniterscala import akka.actor.ActorSystem import akka.http.scaladsl.marshalling.Marshal -import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.model._ -import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException +import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller } +import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException import akka.stream.scaladsl.{ Sink, Source } import com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec import com.github.plokhotnyuk.jsoniter_scala.macros._ import org.scalatest.BeforeAndAfterAll - -import scala.concurrent.Await -import scala.concurrent.duration.DurationInt import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AsyncWordSpec +import scala.concurrent.Await +import scala.concurrent.duration.DurationInt object JsoniterScalaSupportSpec { diff --git a/akka-http-ninny/src/main/scala/de/heikoseeberger/akkahttpninny/NinnySupport.scala b/akka-http-ninny/src/main/scala/de/heikoseeberger/akkahttpninny/NinnySupport.scala index 641179c9..3d14feda 100644 --- a/akka-http-ninny/src/main/scala/de/heikoseeberger/akkahttpninny/NinnySupport.scala +++ b/akka-http-ninny/src/main/scala/de/heikoseeberger/akkahttpninny/NinnySupport.scala @@ -16,19 +16,17 @@ package de.heikoseeberger.akkahttpninny -import java.nio.charset.StandardCharsets - import akka.http.javadsl.common.JsonEntityStreamingSupport import akka.http.scaladsl.common.EntityStreamingSupport import akka.http.scaladsl.marshalling.{ Marshaller, Marshalling, ToEntityMarshaller } -import akka.http.scaladsl.model.MediaTypes.`application/json` import akka.http.scaladsl.model.{ ContentTypeRange, HttpEntity, MediaType, MessageEntity } +import akka.http.scaladsl.model.MediaTypes.`application/json` import akka.http.scaladsl.unmarshalling.{ FromEntityUnmarshaller, Unmarshal, Unmarshaller } import akka.http.scaladsl.util.FastFuture import akka.stream.scaladsl.{ Flow, Source } import akka.util.ByteString import io.github.kag0.ninny._ - +import java.nio.charset.StandardCharsets import scala.collection.immutable.Seq import scala.concurrent.Future import scala.util.control.NonFatal diff --git a/akka-http-ninny/src/test/scala/de/heikoseeberger/akkahttpninny/NinnySupportSpec.scala b/akka-http-ninny/src/test/scala/de/heikoseeberger/akkahttpninny/NinnySupportSpec.scala index fe1cdf5f..f137c85a 100644 --- a/akka-http-ninny/src/test/scala/de/heikoseeberger/akkahttpninny/NinnySupportSpec.scala +++ b/akka-http-ninny/src/test/scala/de/heikoseeberger/akkahttpninny/NinnySupportSpec.scala @@ -18,19 +18,17 @@ package de.heikoseeberger.akkahttpninny import akka.actor.ActorSystem import akka.http.scaladsl.marshalling.Marshal -import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.model._ -import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException +import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller } +import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException import akka.stream.scaladsl.{ Sink, Source } import io.github.kag0.ninny.JsonException import org.scalatest.BeforeAndAfterAll - -import scala.collection.immutable.Seq -import scala.concurrent.Await -import scala.concurrent.duration.DurationInt import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AsyncWordSpec +import scala.concurrent.Await +import scala.concurrent.duration.DurationInt object NinnySupportSpec { diff --git a/akka-http-play-json/src/main/scala/de/heikoseeberger/akkahttpplayjson/PlayJsonSupport.scala b/akka-http-play-json/src/main/scala/de/heikoseeberger/akkahttpplayjson/PlayJsonSupport.scala index ce7ede7c..81acd9fe 100644 --- a/akka-http-play-json/src/main/scala/de/heikoseeberger/akkahttpplayjson/PlayJsonSupport.scala +++ b/akka-http-play-json/src/main/scala/de/heikoseeberger/akkahttpplayjson/PlayJsonSupport.scala @@ -26,7 +26,6 @@ import akka.http.scaladsl.util.FastFuture import akka.stream.scaladsl.{ Flow, Source } import akka.util.ByteString import play.api.libs.json.{ JsError, JsResultException, JsValue, Json, Reads, Writes } - import scala.collection.immutable.Seq import scala.concurrent.Future import scala.util.Try diff --git a/akka-http-play-json/src/test/scala/de/heikoseeberger/akkahttpplayjson/ExampleApp.scala b/akka-http-play-json/src/test/scala/de/heikoseeberger/akkahttpplayjson/ExampleApp.scala index 46eb3be7..cba8c324 100644 --- a/akka-http-play-json/src/test/scala/de/heikoseeberger/akkahttpplayjson/ExampleApp.scala +++ b/akka-http-play-json/src/test/scala/de/heikoseeberger/akkahttpplayjson/ExampleApp.scala @@ -23,7 +23,6 @@ import akka.http.scaladsl.server.Directives import akka.http.scaladsl.unmarshalling.Unmarshal import akka.stream.scaladsl.Source import play.api.libs.json.{ Format, JsValue, Json } - import scala.concurrent.Await import scala.concurrent.duration._ import scala.io.StdIn diff --git a/akka-http-play-json/src/test/scala/de/heikoseeberger/akkahttpplayjson/PlayJsonSupportSpec.scala b/akka-http-play-json/src/test/scala/de/heikoseeberger/akkahttpplayjson/PlayJsonSupportSpec.scala index dfbd21ac..d3dc2486 100644 --- a/akka-http-play-json/src/test/scala/de/heikoseeberger/akkahttpplayjson/PlayJsonSupportSpec.scala +++ b/akka-http-play-json/src/test/scala/de/heikoseeberger/akkahttpplayjson/PlayJsonSupportSpec.scala @@ -18,19 +18,18 @@ package de.heikoseeberger.akkahttpplayjson import akka.actor.ActorSystem import akka.http.scaladsl.marshalling.Marshal -import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.model._ -import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException +import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller } +import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException import akka.stream.scaladsl.{ Sink, Source } import org.scalatest.BeforeAndAfterAll +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AsyncWordSpec import play.api.libs.json.{ Format, Json } - import scala.collection.immutable.Seq import scala.concurrent.Await import scala.concurrent.duration.DurationInt -import org.scalatest.matchers.should.Matchers -import org.scalatest.wordspec.AsyncWordSpec object PlayJsonSupportSpec { diff --git a/akka-http-upickle/src/main/scala/de/heikoseeberger/akkahttpupickle/UpickleCustomizationSupport.scala b/akka-http-upickle/src/main/scala/de/heikoseeberger/akkahttpupickle/UpickleCustomizationSupport.scala index c21e30df..4e4defb9 100644 --- a/akka-http-upickle/src/main/scala/de/heikoseeberger/akkahttpupickle/UpickleCustomizationSupport.scala +++ b/akka-http-upickle/src/main/scala/de/heikoseeberger/akkahttpupickle/UpickleCustomizationSupport.scala @@ -25,8 +25,7 @@ import akka.http.scaladsl.unmarshalling.{ FromEntityUnmarshaller, Unmarshal, Unm import akka.http.scaladsl.util.FastFuture import akka.stream.scaladsl.{ Flow, Source } import akka.util.ByteString -import UpickleCustomizationSupport._ - +import de.heikoseeberger.akkahttpupickle.UpickleCustomizationSupport._ import scala.collection.immutable.Seq import scala.concurrent.Future import scala.util.Try diff --git a/akka-http-upickle/src/test/scala/de/heikoseeberger/akkahttpupickle/UpickleCustomizationSupportSpec.scala b/akka-http-upickle/src/test/scala/de/heikoseeberger/akkahttpupickle/UpickleCustomizationSupportSpec.scala index d8249e92..6c24e1b3 100644 --- a/akka-http-upickle/src/test/scala/de/heikoseeberger/akkahttpupickle/UpickleCustomizationSupportSpec.scala +++ b/akka-http-upickle/src/test/scala/de/heikoseeberger/akkahttpupickle/UpickleCustomizationSupportSpec.scala @@ -18,19 +18,15 @@ package de.heikoseeberger.akkahttpupickle import akka.actor.ActorSystem import akka.http.scaladsl.marshalling.Marshal -import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.model._ -import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException -import akka.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller } -import akka.stream.scaladsl.{ Sink, Source } +import akka.http.scaladsl.unmarshalling.Unmarshal import org.scalatest.BeforeAndAfterAll import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AsyncWordSpec -import upickle.AttributeTagged -import upickle.core.Visitor - import scala.concurrent.Await import scala.concurrent.duration.DurationInt +import upickle.AttributeTagged +import upickle.core.Visitor final class UpickleCustomizationSupportSpec extends AsyncWordSpec diff --git a/akka-http-zio-json/src/main/scala/de/heikoseeberger/akkahttpziojson/ZioJsonSupport.scala b/akka-http-zio-json/src/main/scala/de/heikoseeberger/akkahttpziojson/ZioJsonSupport.scala index 34063d97..47c5bda1 100644 --- a/akka-http-zio-json/src/main/scala/de/heikoseeberger/akkahttpziojson/ZioJsonSupport.scala +++ b/akka-http-zio-json/src/main/scala/de/heikoseeberger/akkahttpziojson/ZioJsonSupport.scala @@ -31,14 +31,10 @@ import akka.http.scaladsl.unmarshalling.{ FromEntityUnmarshaller, Unmarshal, Unm import akka.http.scaladsl.util.FastFuture import akka.stream.scaladsl.{ Flow, Source } import akka.util.ByteString - import scala.collection.immutable.Seq import scala.concurrent.Future -import scala.util.Try import scala.util.control.NonFatal import zio.json._ -import scala.util.Failure -import scala.util.Success import zio.stream.ZStream object ZioJsonSupport extends ZioJsonSupport @@ -49,7 +45,7 @@ object ZioJsonSupport extends ZioJsonSupport * The marshaller writes `A` to JSON `HTTPEntity`. * * The unmarshaller follows zio-json's early exit strategy, attempting to reading JSON to an `A`. - * + * * A safe unmarshaller is provided to attempt reading JSON to an `Either[String, A]` instead. * * No intermediate JSON representation as per zio-json's design. @@ -127,8 +123,8 @@ trait ZioJsonSupport { implicit final def unmarshaller[A: JsonDecoder]: FromEntityUnmarshaller[A] = Unmarshaller.byteStringUnmarshaller .forContentTypes(unmarshallerContentTypes: _*) - .flatMap { implicit ec => implicit m => a => - a match { + .flatMap { implicit ec => implicit m => + { case ByteString.empty => throw Unmarshaller.NoContentException case data => val marshaller = fromByteStringUnmarshaller diff --git a/akka-http-zio-json/src/test/scala/de/heikoseeberger/akkahttpziojson/ExampleApp.scala b/akka-http-zio-json/src/test/scala/de/heikoseeberger/akkahttpziojson/ExampleApp.scala index 103b224f..567436fc 100644 --- a/akka-http-zio-json/src/test/scala/de/heikoseeberger/akkahttpziojson/ExampleApp.scala +++ b/akka-http-zio-json/src/test/scala/de/heikoseeberger/akkahttpziojson/ExampleApp.scala @@ -23,10 +23,9 @@ import akka.http.scaladsl.model.{ HttpRequest, RequestEntity } import akka.http.scaladsl.server.Directives import akka.http.scaladsl.unmarshalling.Unmarshal import akka.stream.scaladsl.Source -import zio.json._ - -import scala.io.StdIn import scala.concurrent.duration._ +import scala.io.StdIn +import zio.json._ object ExampleApp { private final case class Foo(bar: String) diff --git a/akka-http-zio-json/src/test/scala/de/heikoseeberger/akkahttpziojson/ZioJsonSupportSpec.scala b/akka-http-zio-json/src/test/scala/de/heikoseeberger/akkahttpziojson/ZioJsonSupportSpec.scala index b6270ccf..b6183a73 100644 --- a/akka-http-zio-json/src/test/scala/de/heikoseeberger/akkahttpziojson/ZioJsonSupportSpec.scala +++ b/akka-http-zio-json/src/test/scala/de/heikoseeberger/akkahttpziojson/ZioJsonSupportSpec.scala @@ -18,26 +18,18 @@ package de.heikoseeberger.akkahttpziojson import akka.actor.ActorSystem import akka.http.scaladsl.marshalling.Marshal -import akka.http.scaladsl.model.{ - ContentTypeRange, - HttpCharsets, - HttpEntity, - MediaType, - RequestEntity, - ResponseEntity -} +import akka.http.scaladsl.model.{ HttpEntity, RequestEntity, ResponseEntity } import akka.http.scaladsl.model.ContentTypes.{ `application/json`, `text/plain(UTF-8)` } import akka.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller } import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException import akka.stream.scaladsl.{ Sink, Source } import org.scalatest.{ BeforeAndAfterAll, EitherValues } import org.scalatest.concurrent.ScalaFutures -import zio.json._ - -import scala.concurrent.Await -import scala.concurrent.duration.DurationInt import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AsyncWordSpec +import scala.concurrent.Await +import scala.concurrent.duration.DurationInt +import zio.json._ object ZioJsonSupportSpec { diff --git a/build.sbt b/build.sbt index c6e1e31e..7de470ab 100644 --- a/build.sbt +++ b/build.sbt @@ -1,8 +1,14 @@ +// ***************************************************************************** +// Build settings +// ***************************************************************************** + inThisBuild( Seq( organization := "de.heikoseeberger", + organizationName := "Heiko Seeberger", + startYear := Some(2015), + licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0")), homepage := Some(url("https://github.com/hseeberger/akka-http-json")), - licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")), scmInfo := Some( ScmInfo( url("https://github.com/hseeberger/akka-http-json"), @@ -17,6 +23,19 @@ inThisBuild( url("https://github.com/hseeberger") ) ), + scalaVersion := "2.13.5", + crossScalaVersions := Seq(scalaVersion.value, "2.12.13"), + scalacOptions ++= Seq( + "-unchecked", + "-deprecation", + "-language:_", + "-encoding", + "UTF-8", + "-Ywarn-unused:imports", + "-target:jvm-1.8" + ), + scalafmtOnCompile := true, + dynverSeparator := "_" // the default `+` is not compatible with docker tags, ) ) @@ -38,7 +57,7 @@ lazy val `akka-http-json` = `akka-http-ninny`, `akka-http-play-json`, `akka-http-upickle`, - `akka-http-zio-json` + `akka-http-zio-json`, ) .settings(commonSettings) .settings( @@ -57,7 +76,7 @@ lazy val `akka-http-argonaut` = library.argonaut, library.akkaStream % Provided, library.scalaTest % Test, - ), + ) ) lazy val `akka-http-circe` = @@ -72,7 +91,7 @@ lazy val `akka-http-circe` = library.akkaStream % Provided, library.circeGeneric % Test, library.scalaTest % Test, - ), + ) ) lazy val `akka-http-jackson` = @@ -84,10 +103,10 @@ lazy val `akka-http-jackson` = library.akkaHttp, library.akkaHttpJacksonJava, library.jacksonModuleScala, - library.scalaReflect % scalaVersion.value, - library.akkaStream % Provided, - library.scalaTest % Test, - ), + "org.scala-lang" % "scala-reflect" % scalaVersion.value, + library.akkaStream % Provided, + library.scalaTest % Test, + ) ) lazy val `akka-http-json4s` = @@ -102,7 +121,7 @@ lazy val `akka-http-json4s` = library.json4sJackson % Test, library.json4sNative % Test, library.scalaTest % Test, - ), + ) ) lazy val `akka-http-jsoniter-scala` = @@ -116,7 +135,7 @@ lazy val `akka-http-jsoniter-scala` = library.akkaStream % Provided, library.jsoniterScalaMacros % Test, library.scalaTest % Test, - ), + ) ) lazy val `akka-http-ninny` = @@ -129,7 +148,7 @@ lazy val `akka-http-ninny` = library.ninny, library.akkaStream % Provided, library.scalaTest % Test, - ), + ) ) lazy val `akka-http-play-json` = @@ -142,7 +161,7 @@ lazy val `akka-http-play-json` = library.playJson, library.akkaStream % Provided, library.scalaTest % Test, - ), + ) ) lazy val `akka-http-upickle` = @@ -155,7 +174,7 @@ lazy val `akka-http-upickle` = library.upickle, library.akkaStream % Provided, library.scalaTest % Test, - ), + ) ) lazy val `akka-http-avro4s` = @@ -168,7 +187,7 @@ lazy val `akka-http-avro4s` = library.avro4sJson, library.akkaStream % Provided, library.scalaTest % Test, - ), + ) ) lazy val `akka-http-zio-json` = @@ -180,10 +199,23 @@ lazy val `akka-http-zio-json` = library.akkaHttp, library.zioJson, library.akkaStream % Provided, - library.scalaTest % Test, + library.scalaTest % Test ) ) +// ***************************************************************************** +// Project settings +// ***************************************************************************** + +lazy val commonSettings = + Seq( + // Also (automatically) format build definition together with sources + Compile / scalafmt := { + val _ = (Compile / scalafmtSbt).value + (Compile / scalafmt).value + } + ) + // ***************************************************************************** // Library dependencies // ***************************************************************************** @@ -203,52 +235,27 @@ lazy val library = val play = "2.9.2" val scalaTest = "3.2.6" val upickle = "1.3.9" - val zioJson = "0.1.2" + val zioJson = "0.1.3" } + // format: off val akkaHttp = "com.typesafe.akka" %% "akka-http" % Version.akkaHttp val akkaHttpJacksonJava = "com.typesafe.akka" %% "akka-http-jackson" % Version.akkaHttp val akkaStream = "com.typesafe.akka" %% "akka-stream" % Version.akka val argonaut = "io.argonaut" %% "argonaut" % Version.argonaut val avro4sJson = "com.sksamuel.avro4s" %% "avro4s-json" % Version.avro4s val circe = "io.circe" %% "circe-core" % Version.circe - val circeParser = "io.circe" %% "circe-parser" % Version.circe val circeGeneric = "io.circe" %% "circe-generic" % Version.circe + val circeParser = "io.circe" %% "circe-parser" % Version.circe val jacksonModuleScala = "com.fasterxml.jackson.module" %% "jackson-module-scala" % Version.jacksonModuleScala val json4sCore = "org.json4s" %% "json4s-core" % Version.json4s val json4sJackson = "org.json4s" %% "json4s-jackson" % Version.json4s val json4sNative = "org.json4s" %% "json4s-native" % Version.json4s val jsoniterScalaCore = "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % Version.jsoniterScala val jsoniterScalaMacros = "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % Version.jsoniterScala - val playJson = "com.typesafe.play" %% "play-json" % Version.play val ninny = "io.github.kag0" %% "ninny" % Version.ninny + val playJson = "com.typesafe.play" %% "play-json" % Version.play val scalaTest = "org.scalatest" %% "scalatest" % Version.scalaTest val upickle = "com.lihaoyi" %% "upickle" % Version.upickle val zioJson = "dev.zio" %% "zio-json" % Version.zioJson - val scalaReflect = "org.scala-lang" % "scala-reflect" + // format: on } - -// ***************************************************************************** -// Settings -// ***************************************************************************** - -lazy val commonSettings = - Seq( - scalaVersion := "2.13.5", - crossScalaVersions := Seq(scalaVersion.value, "2.12.13"), - organizationName := "Heiko Seeberger", - startYear := Some(2015), - scalacOptions ++= Seq( - "-unchecked", - "-deprecation", - "-language:_", - "-target:jvm-1.8", - "-encoding", - "UTF-8", - ), - Compile / unmanagedSourceDirectories := Seq((Compile / scalaSource).value), - Test / unmanagedSourceDirectories := Seq((Test / scalaSource).value), - mimaPreviousArtifacts := previousStableVersion.value.map(organization.value %% name.value % _).toSet, - git.useGitDescribe := true, - scalafmtOnCompile := true, - pomIncludeRepository := (_ => false), - )