Skip to content

Commit

Permalink
Feature/2.12 (#51)
Browse files Browse the repository at this point in the history
Add support for Scala 2.12. 

- Certain integrations are still AWOL but Circe is in
- Gave up on Scalafmt for now.
  • Loading branch information
lloydmeta authored Nov 10, 2016
1 parent b5a3dd9 commit c5eb813
Show file tree
Hide file tree
Showing 96 changed files with 1,679 additions and 1,605 deletions.
18 changes: 14 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ language: scala
jdk:
- oraclejdk8
scala:
- 2.10.6
- 2.11.8
- 2.12.0
script:
- sbt clean +test:compile
- sbt coverage +test coverageReport && sbt coverageAggregate
# Only run aggregation 2.11, for 2.12, only run the special dummy project
- if [[ $TRAVIS_SCALA_VERSION == "2.12"* ]]; then
sbt ++$TRAVIS_SCALA_VERSION scala_2_12/test;
elif [[ $TRAVIS_SCALA_VERSION == "2.11"* ]]; then
sbt ++$TRAVIS_SCALA_VERSION coverage test coverageReport &&
sbt ++$TRAVIS_SCALA_VERSION coverageAggregate;
else
sbt ++$TRAVIS_SCALA_VERSION clean test;
fi
after_success:
- sbt coveralls
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && sbt coreJVM/updateImpactSubmit || true'
- if [[ $TRAVIS_SCALA_VERSION == "2.11"* ]]; then
sbt ++$TRAVIS_SCALA_VERSION coveralls;
fi
cache:
directories:
- $HOME/.sbt/0.13
Expand Down
105 changes: 56 additions & 49 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,65 @@ import com.typesafe.sbt.SbtGit.{GitKeys => git}

lazy val theVersion = "1.4.18-SNAPSHOT"
lazy val theScalaVersion = "2.11.8"
lazy val scalaVersions = Seq("2.10.6", "2.11.8")
/*
2.12.0 support is currently defined as a separate project (scala_2_12) for convenience while
integration libraries are still gaining 2.12.0 support
*/
lazy val scalaVersions = Seq("2.10.6", "2.11.8")

lazy val scalaTestVersion = "3.0.0"

// Library versions
lazy val reactiveMongoVersion = "0.12.0"
lazy val circeVersion = "0.6.0"
lazy val uPickleVersion = "0.4.3"
lazy val argonautVersion ="6.1"
def thePlayVersion(scalaVersion: String) =
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, scalaMajor)) if scalaMajor >= 11 => "2.5.9"
case Some((2, scalaMajor)) if scalaMajor == 10 => "2.4.8"
case _ =>
throw new IllegalArgumentException(s"Unsupported Scala version $scalaVersion")
}
lazy val scalaTestVersion = "3.0.0"
lazy val reactiveMongoVersion = "0.12.0"
}

lazy val baseProjectRefs =
Seq(macrosJs, macrosJvm, coreJs, coreJvm, coreJVMTests).map(Project.projectToRef)

lazy val integrationProjectRefs = Seq(
enumeratumPlay,
enumeratumPlayJson,
enumeratumUPickleJs,
enumeratumUPickleJvm,
enumeratumCirceJs,
enumeratumCirceJvm,
enumeratumReactiveMongoBson,
enumeratumArgonaut
).map(Project.projectToRef)

lazy val root =
Project(id = "enumeratum-root", base = file("."), settings = commonWithPublishSettings)
.settings(
name := "enumeratum-root",
crossScalaVersions := scalaVersions,
crossVersion := CrossVersion.binary
)
.settings(
git.gitRemoteRepo := "git@github.com:lloydmeta/enumeratum.git"
)
.settings(
crossVersion := CrossVersion.binary,
git.gitRemoteRepo := "git@github.com:lloydmeta/enumeratum.git",
// Do not publish the root project (it just serves as an aggregate)
publishArtifact := false,
publishLocal := {}
)
.aggregate(macrosJs,
macrosJvm,
coreJs,
coreJvm,
coreJVMTests,
enumeratumPlay,
enumeratumPlayJson,
enumeratumUPickleJs,
enumeratumUPickleJvm,
enumeratumCirceJs,
enumeratumCirceJvm,
enumeratumReactiveMongoBson,
enumeratumArgonaut)
.aggregate(baseProjectRefs ++ integrationProjectRefs: _*)

lazy val scala_2_12 = Project(id = "scala_2_12",
base = file("scala_2_12"),
settings = commonSettings ++ publishSettings)
.settings(name := "enumeratum-scala_2_12",
scalaVersion := "2.12.0", //not sure if this and below are needed
crossScalaVersions := Seq("2.12.0"),
crossVersion := CrossVersion.binary,
// Do not publish this project (it just serves as an aggregate)
publishArtifact := false,
publishLocal := {})
.aggregate(baseProjectRefs ++ Seq(enumeratumCirceJs, enumeratumCirceJvm).map(Project.projectToRef): _*) // base plus known 2.12 friendly libs

lazy val core = crossProject
.crossType(CrossType.Pure)
Expand All @@ -51,7 +71,6 @@ lazy val core = crossProject
.settings(testSettings: _*)
.settings(commonWithPublishSettings: _*)
.dependsOn(macros)

lazy val coreJs = core.js
lazy val coreJvm = core.jvm

Expand Down Expand Up @@ -133,7 +152,7 @@ lazy val enumeratumUPickle = crossProject
else
CrossVersion.binary
}
Seq(impl.ScalaJSGroupID.withCross("com.lihaoyi", "upickle", cross) % "0.4.1")
Seq(impl.ScalaJSGroupID.withCross("com.lihaoyi", "upickle", cross) % uPickleVersion)
} ++ {
val additionalMacroDeps =
CrossVersion.partialVersion(scalaVersion.value) match {
Expand Down Expand Up @@ -166,7 +185,7 @@ lazy val enumeratumCirce = crossProject
else
CrossVersion.binary
}
Seq(impl.ScalaJSGroupID.withCross("io.circe", "circe-core", cross) % "0.5.1")
Seq(impl.ScalaJSGroupID.withCross("io.circe", "circe-core", cross) % circeVersion)
}
)
.settings(testSettings: _*)
Expand All @@ -180,7 +199,7 @@ lazy val enumeratumArgonaut =
settings = commonWithPublishSettings)
.settings(
libraryDependencies ++= Seq(
"io.argonaut" %% "argonaut" % "6.1"
"io.argonaut" %% "argonaut" % argonautVersion
)
)
.settings(testSettings: _*)
Expand All @@ -190,17 +209,18 @@ lazy val commonSettings = Seq(
organization := "com.beachape",
version := theVersion,
incOptions := incOptions.value.withLogRecompileOnMacro(false),
scalaVersion := theScalaVersion,
scalafmtConfig := Some(file(".scalafmt.conf"))
scalaVersion := theScalaVersion
) ++
scoverageSettings ++
reformatOnCompileSettings ++
compilerSettings ++
resolverSettings ++
ideSettings

lazy val commonWithPublishSettings =
lazy val commonSettingsWithTrimmings =
commonSettings ++
scoverageSettings

lazy val commonWithPublishSettings =
commonSettingsWithTrimmings ++
publishSettings

lazy val resolverSettings = Seq(
Expand Down Expand Up @@ -246,9 +266,9 @@ lazy val publishSettings = Seq(
<url>https://beachape.com</url>
</developer>
</developers>,
publishTo <<= version { v =>
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (v.trim.endsWith("SNAPSHOT"))
if (version.value.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
Expand Down Expand Up @@ -286,18 +306,7 @@ lazy val benchmarking =
publishArtifact := false,
publishLocal := {}
)
.dependsOn(macrosJs,
macrosJvm,
coreJs,
coreJvm,
coreJVMTests,
enumeratumPlay,
enumeratumPlayJson,
enumeratumUPickleJs,
enumeratumUPickleJvm,
enumeratumCirceJs,
enumeratumCirceJvm,
enumeratumReactiveMongoBson)
.dependsOn((baseProjectRefs ++ integrationProjectRefs).map(ClasspathDependency(_, None)): _*)
.enablePlugins(JmhPlugin)
.settings(libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.7.21")

Expand Down Expand Up @@ -337,6 +346,4 @@ def withCompatUnmanagedSources(jsJvmCrossProject: Boolean,
} else {
unmanagedMainDirsSetting
}
}

scalafmtConfig := Some(file(".scalafmt.conf"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package enumeratum
import argonaut._

/**
* Created by alonsodomin on 14/10/2016.
*/
* Created by alonsodomin on 14/10/2016.
*/
trait ArgonautEnum[A <: EnumEntry] { this: Enum[A] =>

implicit val argonautEncoder: EncodeJson[A] = Argonauter.encoder(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import argonaut._
import Argonaut._

/**
* Created by alonsodomin on 14/10/2016.
*/
* Created by alonsodomin on 14/10/2016.
*/
object Argonauter {

private def encoder0[A <: EnumEntry](f: A => String): EncodeJson[A] =
Expand All @@ -25,7 +25,7 @@ object Argonauter {
stringDecoder(cursor).flatMap { enumStr =>
f(enumStr) match {
case Some(a) => okResult(a)
case _ => failResult(s"$enumStr' is not a member of enum $enum", cursor.history)
case _ => failResult(s"$enumStr' is not a member of enum $enum", cursor.history)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import argonaut._
import Argonaut._

/**
* Created by alonsodomin on 14/10/2016.
*/
* Created by alonsodomin on 14/10/2016.
*/
sealed trait ArgonautValueEnum[ValueType, EntryType <: ValueEnumEntry[ValueType]] {
this: ValueEnum[ValueType, EntryType] =>

Expand All @@ -15,8 +15,8 @@ sealed trait ArgonautValueEnum[ValueType, EntryType <: ValueEnumEntry[ValueType]
}

/**
* ArgonautEnum for IntEnumEntry
*/
* ArgonautEnum for IntEnumEntry
*/
trait IntArgonautEnum[EntryType <: IntEnumEntry] extends ArgonautValueEnum[Int, EntryType] {
this: ValueEnum[Int, EntryType] =>

Expand All @@ -25,8 +25,8 @@ trait IntArgonautEnum[EntryType <: IntEnumEntry] extends ArgonautValueEnum[Int,
}

/**
* ArgonautEnum for LongEnumEntry
*/
* ArgonautEnum for LongEnumEntry
*/
trait LongArgonautEnum[EntryType <: LongEnumEntry] extends ArgonautValueEnum[Long, EntryType] {
this: ValueEnum[Long, EntryType] =>

Expand All @@ -35,8 +35,8 @@ trait LongArgonautEnum[EntryType <: LongEnumEntry] extends ArgonautValueEnum[Lon
}

/**
* ArgonautEnum for ShortEnumEntry
*/
* ArgonautEnum for ShortEnumEntry
*/
trait ShortArgonautEnum[EntryType <: ShortEnumEntry] extends ArgonautValueEnum[Short, EntryType] {
this: ValueEnum[Short, EntryType] =>

Expand All @@ -45,8 +45,8 @@ trait ShortArgonautEnum[EntryType <: ShortEnumEntry] extends ArgonautValueEnum[S
}

/**
* ArgonautEnum for StringEnumEntry
*/
* ArgonautEnum for StringEnumEntry
*/
trait StringArgonautEnum[EntryType <: StringEnumEntry]
extends ArgonautValueEnum[String, EntryType] { this: ValueEnum[String, EntryType] =>

Expand All @@ -55,8 +55,8 @@ trait StringArgonautEnum[EntryType <: StringEnumEntry]
}

/**
* ArgonautEnum for CharEnumEntry
*/
* ArgonautEnum for CharEnumEntry
*/
trait CharArgonautEnum[EntryType <: CharEnumEntry] extends ArgonautValueEnum[Char, EntryType] {
this: ValueEnum[Char, EntryType] =>

Expand All @@ -65,8 +65,8 @@ trait CharArgonautEnum[EntryType <: CharEnumEntry] extends ArgonautValueEnum[Cha
}

/**
* ArgonautEnum for ByteEnumEntry
*/
* ArgonautEnum for ByteEnumEntry
*/
trait ByteArgonautEnum[EntryType <: ByteEnumEntry] extends ArgonautValueEnum[Byte, EntryType] {
this: ValueEnum[Byte, EntryType] =>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ import argonaut._
import Argonaut._

/**
* Created by alonsodomin on 14/10/2016.
*/
* Created by alonsodomin on 14/10/2016.
*/
object Argonauter {

def encoder[ValueType: EncodeJson, EntryType <: ValueEnumEntry[ValueType]](
enum: ValueEnum[ValueType, EntryType]): EncodeJson[EntryType] = {
enum: ValueEnum[ValueType, EntryType]
): EncodeJson[EntryType] = {
val encodeValue = implicitly[EncodeJson[ValueType]]
EncodeJson { entry =>
encodeValue(entry.value)
}
}

def decoder[ValueType: DecodeJson, EntryType <: ValueEnumEntry[ValueType]](
enum: ValueEnum[ValueType, EntryType]): DecodeJson[EntryType] = {
enum: ValueEnum[ValueType, EntryType]
): DecodeJson[EntryType] = {
val decodeValue = implicitly[DecodeJson[ValueType]]
DecodeJson { cursor =>
decodeValue(cursor).flatMap { value =>
enum.withValueOpt(value) match {
case Some(entry) => okResult(entry)
case _ => failResult(s"$value is not a member of enum $enum", cursor.history)
case _ => failResult(s"$value is not a member of enum $enum", cursor.history)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package enumeratum

import argonaut.Argonaut._
import argonaut.{DecodeJson, EncodeJson}
import argonaut.{ DecodeJson, EncodeJson }

/**
* Created by alonsodomin on 15/10/2016.
*/
* Created by alonsodomin on 15/10/2016.
*/
package object values {

implicit val argonautByteEncoder: EncodeJson[Byte] = EncodeJson { byte =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package enumeratum

import org.scalatest.{FunSpec, Matchers}
import org.scalatest.{ FunSpec, Matchers }

import argonaut._
import Argonaut._

/**
* Created by alonsodomin on 14/10/2016.
*/
* Created by alonsodomin on 14/10/2016.
*/
class ArgonautSpec extends FunSpec with Matchers {

describe("to JSON") {
Expand Down
Loading

0 comments on commit c5eb813

Please sign in to comment.