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

Feature/upgrade scala #22

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,4 @@ snapshots
native.iml

checkpoint
.bsp
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ language: scala
sudo: false

scala:
- 2.11.12
- 2.12.4
- 2.12.12
- 2.13.5

jdk:
- oraclejdk8
- openjdk11

script:
- sbt ++$TRAVIS_SCALA_VERSION clean coverage test
Expand Down
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM adoptopenjdk/openjdk11 as dev
LABEL Author="Keshav Murthy"

RUN apt-get update && apt-get install -y gnupg2 apt-transport-https

RUN \
echo "deb https://dl.bintray.com/sbt/debian /" | tee -a /etc/apt/sources.list.d/sbt.list && \
apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823 && \
apt-get update && \
apt-get install -y \
sbt=1.4.9 \
ca-certificates

RUN update-ca-certificates

WORKDIR /app

#Create docker container with the dependencies so subsequent builds are faster
ADD build.sbt ./
ADD ./project ./project
RUN sbt update

ADD . /app
3 changes: 0 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import Dependencies._
name := "validated-config"

CommonProject.settings

ScalaDoc.settings
enablePlugins(GhpagesPlugin)
enablePlugins(SiteScaladocPlugin)

Publish.settings

resolvers += Resolver.jcenterRepo

libraryDependencies ++= Seq(
cats,
ficus,
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'

services:
dev:
build:
context: .
volumes:
- .:/app:cached
environment:
- SBT_OPTS=-Xms512M -Xmx2G -Xss2M -XX:MaxMetaspaceSize=1024M -XX:+CMSClassUnloadingEnabled
4 changes: 0 additions & 4 deletions project/CommonProject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ object CommonProject {
"-language:postfixOps",
"-language:implicitConversions",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Xfuture",
"-Ywarn-unused-import",
"-Ypartial-unification",
"-Xfatal-warnings"
),
scalacOptions in (Compile, doc) ++= {
Expand Down
9 changes: 4 additions & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright 2016 Carl Pulley

import sbt.Keys._
import sbt._

object Dependencies {
val cats: ModuleID = "org.typelevel" %% "cats-core" % "1.0.1"
val ficus: ModuleID = "com.iheart" %% "ficus" % "1.4.3"
val refined: ModuleID = "eu.timepit" %% "refined" % "0.8.7"
val scalatest: ModuleID = "org.scalatest" %% "scalatest" % "3.0.5"
val cats: ModuleID = "org.typelevel" %% "cats-core" % "2.5.0"
val ficus: ModuleID = "com.iheart" %% "ficus" % "1.5.0"
val refined: ModuleID = "eu.timepit" %% "refined" % "0.9.23"
val scalatest: ModuleID = "org.scalatest" %% "scalatest" % "3.2.5"
val typesafeConfig: ModuleID = "com.typesafe" % "config" % "1.3.3"
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.15
sbt.version=1.4.7
15 changes: 5 additions & 10 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@

// Copyright 2016 Carl Pulley

scalacOptions ++= Seq("-deprecation", "-Xlint", "-unchecked", "-language:_")

resolvers += "Typesafe Repository" at "https://repo.typesafe.com/typesafe/releases/"
resolvers += "jgit-repo" at "http://download.eclipse.org/jgit/maven"

addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.8")
addSbtPlugin("com.dwijnand" % "sbt-travisci" % "1.1.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0-M1")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.2.1")
addSbtPlugin("com.updateimpact" % "updateimpact-sbt-plugin" % "2.1.2")
addSbtPlugin("com.versioneye" % "sbt-versioneye-plugin" % "0.2.0")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC6")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.0")
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "3.0.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.1")
7 changes: 2 additions & 5 deletions src/main/scala/net/cakesolutions/config/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package net.cakesolutions

import scala.language.implicitConversions
import scala.util.{Failure, Success, Try}

import cats.data.{NonEmptyList => NEL, Validated}
Expand Down Expand Up @@ -66,10 +65,8 @@ package object config extends FicusInstances {
implicit def toRefinementType[Base, Refinement](
implicit reader: ValueReader[Base],
witness: Validate[Base, Refinement]
): ValueReader[Base Refined Refinement] = new ValueReader[Base Refined Refinement] {
override def read(config: Config, path: String): Base Refined Refinement = {
refineV[Refinement](config.as[Base](path)).right.get
}
): ValueReader[Base Refined Refinement] = (config: Config, path: String) => {
refineV[Refinement](config.as[Base](path)).toOption.get
}

/**
Expand Down
32 changes: 28 additions & 4 deletions src/test/scala/net/cakesolutions/config/ValidatedConfigTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
package net.cakesolutions.config

import scala.concurrent.duration._

import cats._
import cats.data.{NonEmptyList => NEL, Validated}
import cats.data.{Validated, NonEmptyList => NEL}
import com.typesafe.config.{Config, ConfigException, ConfigFactory}
import eu.timepit.refined._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric._
import eu.timepit.refined.string._
import org.scalatest.FreeSpec
import org.scalatest.freespec.AnyFreeSpec

object ValidatedConfigTest {
case object GenericTestFailure extends Exception
Expand All @@ -25,7 +24,7 @@ object ValidatedConfigTest {
final case class Settings(name: String Refined MatchesRegex[W.`"[a-z0-9_-]+"`.T], timeout: FiniteDuration, http: HttpConfig)
}

class ValidatedConfigTest extends FreeSpec {
class ValidatedConfigTest extends AnyFreeSpec {
import ValidatedConfigTest._

private def matchOrFail[Value](value: => Value)(matcher: PartialFunction[Value, Unit]): Unit = {
Expand Down Expand Up @@ -100,54 +99,63 @@ class ValidatedConfigTest extends FreeSpec {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("invalid-path", _: ConfigException.Missing)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(validate[String](required("invalid-path"), GenericTestFailure)(_ => true)) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("invalid-path", RequiredValueNotSet)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(validate[String](required("invalid-path", "NOT_SET"), GenericTestFailure)(_ => true)) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("invalid-path", _: ConfigException.Missing)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(validate[String]("test.invalid-path", GenericTestFailure)(_ => true)) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("test.invalid-path", _: ConfigException.Missing)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(validate[String](required("test.invalid-path", "NOT_SET"), GenericTestFailure)(_ => true)) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("test.invalid-path", _: ConfigException.Missing)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(validate[Int]("top-level-name", GenericTestFailure)(_ => true)) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("top-level-name", _: ConfigException.WrongType)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(validate[Int](required("top-level-name", "NOT_SET"), GenericTestFailure)(_ => true)) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("top-level-name", _: ConfigException.WrongType)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(validate[String]("top-level-name", GenericTestFailure)(_ => throw fakeException)) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("top-level-name", `fakeException`)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(validate[String](required("top-level-name", "NOT_SET"), GenericTestFailure)(_ => throw fakeException)) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("top-level-name", `fakeException`)) =>
assert(true)
case _ => assert(false)
}
}
}
Expand Down Expand Up @@ -184,42 +192,49 @@ class ValidatedConfigTest extends FreeSpec {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("invalid-path", NullValue)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(unchecked[String](required("invalid-path"))) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("invalid-path", NullValue)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(unchecked[String](required("invalid-path", "NOT_SET"))) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("invalid-path", NullValue)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(unchecked[String]("test.invalid-path")) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("test.invalid-path", NullValue)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(unchecked[String](required("test.invalid-path", "NOT_SET"))) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("test.invalid-path", NullValue)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(unchecked[Int]("top-level-name")) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("top-level-name", _)) =>
assert(true)
case _ => assert(false)
}
}
matchOrFail(unchecked[Int](required("top-level-name", "NOT_SET"))) {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("top-level-name", _)) =>
assert(true)
case _ => assert(false)
}
}
}
Expand Down Expand Up @@ -256,6 +271,7 @@ class ValidatedConfigTest extends FreeSpec {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("test.bad-path.nestedVal", _: ConfigException.Missing), ValueFailure("test.context.valueStrList", GenericTestFailure)) =>
assert(true)
case _ => assert(false)
}
}
val testConfig4 = via[TestSettings]("test") { implicit config =>
Expand All @@ -272,6 +288,7 @@ class ValidatedConfigTest extends FreeSpec {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("test.nestedRequired", _: ConfigException.BadValue), ValueFailure("test.context.valueStrList", GenericTestFailure)) =>
assert(true)
case _ => assert(false)
}
}
val testConfig5 = via[TestSettings]("test") { implicit config =>
Expand All @@ -288,6 +305,7 @@ class ValidatedConfigTest extends FreeSpec {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("test.nestedRequired", RequiredValueNotSet), ValueFailure("test.context.valueStrList", GenericTestFailure)) =>
assert(true)
case _ => assert(false)
}
}
}
Expand Down Expand Up @@ -321,6 +339,7 @@ class ValidatedConfigTest extends FreeSpec {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("test.bad-path.nestedVal", NullValue)) =>
assert(true)
case _ => assert(false)
}
}
val testConfig4 = via[TestSettings]("test") { implicit config =>
Expand All @@ -337,6 +356,7 @@ class ValidatedConfigTest extends FreeSpec {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("test.nestedRequired", _: ConfigException.BadValue)) =>
assert(true)
case _ => assert(false)
}
}
val testConfig5 = via[TestSettings]("test") { implicit config =>
Expand All @@ -353,6 +373,7 @@ class ValidatedConfigTest extends FreeSpec {
case Validated.Invalid(errors) => errors.toList match {
case List(ValueFailure("test.nestedRequired", RequiredValueNotSet)) =>
assert(true)
case _ => assert(false)
}
}
}
Expand All @@ -378,6 +399,7 @@ class ValidatedConfigTest extends FreeSpec {
matchOrFail(validatedConfig) {
case Validated.Invalid(FileNotFound("non-existent.conf", _)) =>
assert(true)
case _ => assert(false)
}
}

Expand All @@ -399,6 +421,7 @@ class ValidatedConfigTest extends FreeSpec {
matchOrFail(validatedConfig) {
case Validated.Invalid(FileNotFound(_, _: ConfigException)) =>
assert(true)
case _ => assert(false)
}
}

Expand Down Expand Up @@ -434,6 +457,7 @@ class ValidatedConfigTest extends FreeSpec {
matchOrFail(validatedConfig) {
case Validated.Invalid(ValueErrors(ValueFailure("http.heartbeat", RequiredValueNotSet))) =>
assert(true)
case _ => assert(false)
}
}

Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Copyright 2016 Carl Pulley

version in ThisBuild := "1.1.3"
version in ThisBuild := "1.1.4"