Skip to content

Commit

Permalink
Scala 2.13.0 Support & Libraries update
Browse files Browse the repository at this point in the history
  • Loading branch information
chrilves committed Sep 20, 2019
1 parent b807023 commit 2a7086c
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 62 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: scala
scala:
- 2.12.8
- 2.13.0
- 2.12.10
jdk:
- openjdk8
- openjdk11
cache:
directories:
- "$HOME/.ivy2/cache"
Expand Down
36 changes: 22 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ lazy val warts = Warts.allBut(
Wart.Nothing
)

lazy val catsVersion = "2.0.0-RC1"
lazy val catsMTLVersion = "0.6.0"
lazy val silencerVersion = "1.4.2"
lazy val applicationInsightsVersion = "2.5.0"
lazy val catsVersion = "2.0.0"
lazy val catsMTLVersion = "0.7.0"
lazy val silencerVersion = "1.4.3"
lazy val scalaTestVersion = "3.0.8"
lazy val akkaStreamVersion = "2.5.23"
lazy val playVersion = "2.6.23"
lazy val akkaStreamVersion = "2.5.25"
lazy val playVersion = "2.7.3"
lazy val anormVersion = "2.6.4"
lazy val specs2Version = "4.7.0"
lazy val specs2Version = "4.7.1"

val safeScalaOptionsCommon =
Seq(
Expand All @@ -32,6 +33,12 @@ val safeScalaOptionsCommon_2_12 =
"-Ywarn-self-implicit",
)

val safeScalaOptionsCommon_2_13 =
Seq(
"-Ywarn-macros:both",
"-Ywarn-self-implicit",
)

lazy val publishSettings = Seq(
homepage := Some(url("https://github.com/MfgLabs/precepte")),
licenses := Seq("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.html")),
Expand All @@ -43,13 +50,13 @@ lazy val publishSettings = Seq(

lazy val commonSettings = Seq(
organization := "com.mfglabs"
, version := "0.5.0-rc2"
, version := "0.5.0-rc3"
, isSnapshot := false
, crossScalaVersions := Seq("2.12.8")
, crossScalaVersions := List("2.13.0", "2.12.10")
, resolvers ++= Seq(
"Scalaz Bintray Repo" at "http://dl.bintray.com/scalaz/releases"
, "Oncue Bintray Repo" at "http://dl.bintray.com/oncue/releases"
, "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/" //for play 2.3.9
"Scalaz Bintray Repo" at "https://dl.bintray.com/scalaz/releases"
, "Oncue Bintray Repo" at "https://dl.bintray.com/oncue/releases"
, "Typesafe Releases" at "https://repo.typesafe.com/typesafe/releases/" //for play 2.3.9
, "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots" //for play 2.3.9
)
, logLevel in update := Level.Warn
Expand All @@ -58,13 +65,14 @@ lazy val commonSettings = Seq(
, scalacOptions ++= safeScalaOptionsCommon ++ {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => safeScalaOptionsCommon_2_12
case Some((2, 13)) => safeScalaOptionsCommon_2_13
case Some((p,s)) => throw new Exception(s"Uknown scala binary version $p.$s")
case _ => throw new Exception(s"Bad scala version: ${scalaVersion.value}")
}
}
, addCompilerPlugin("io.tryp" % "splain" % "0.4.1" cross CrossVersion.patch)
, addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3" cross CrossVersion.binary)
, addCompilerPlugin("com.github.ghik" %% "silencer-plugin" % silencerVersion)
, addCompilerPlugin("com.github.ghik" % "silencer-plugin" % silencerVersion cross CrossVersion.patch)
, scalacOptions += "-P:silencer:globalFilters=The outer reference in this type test cannot be checked at run time"
, scalafmtOnCompile := true
, wartremoverErrors in (Compile, compile) := warts
Expand Down Expand Up @@ -162,7 +170,7 @@ lazy val applicationinsights =
.settings(commonSettings:_*)
.settings(
name := "precepte-applicationinsights",
libraryDependencies += "com.microsoft.azure" % "applicationinsights-core" % "2.4.1"
libraryDependencies += "com.microsoft.azure" % "applicationinsights-core" % applicationInsightsVersion
)
.dependsOn(core)

Expand All @@ -173,7 +181,7 @@ lazy val logback =
name := "precepte-logback",
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % "1.2.3",
"net.logstash.logback" % "logstash-logback-encoder" % "6.1"))
"net.logstash.logback" % "logstash-logback-encoder" % "6.2"))
.dependsOn(core)

lazy val play =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ object ApplicationInsights {
implicit executionContext: ExecutionContext)
: Precepte[BaseTags, MS, U, Future, Unit] =
Precepte
.deferredLift(Future(client.track(timeMesurementToTelemetry(tm))))
.deferredLift[BaseTags, MS, U, Future, Unit](
Future(client.track(timeMesurementToTelemetry(tm))))
.recoverWith(errorHandler)

def createClient(instrumentationKey: String,
Expand Down
3 changes: 2 additions & 1 deletion precepte-core-cats/src/test/scala/SamplesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class SamplesSpec extends FlatSpec with ScalaFutures {
_ <- s.unmanaged.metric
.metric(s"$stuff going to pay $amount")
.unify(s)
r <- Precepte.liftF(Future(Paid(stuff.id, amount)))
r <- Precepte.liftF[BaseTags, MS, PayCtx, Future, Paid](
Future(Paid(stuff.id, amount)))
_ <- s.unmanaged.logger.info(s"$stuff paid $amount").unify(s)
} yield (r)
}
Expand Down
8 changes: 4 additions & 4 deletions precepte-core-scalaz/src/test/scala/SamplesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ class SamplesSpec extends FlatSpec with ScalaFutures {
// Type alias are always advised to make syntax nicer and help sometimes scalac with HK types
type Pre[A] = DefaultPre[Future, Unit, A]

// using a Precepte of future for the logger... yes this is expensive as it will as the exectx for a thread
// but let's be pure for samples :D
@inline def info(m: String): Pre[Unit] = println(m).point[Pre]
@inline def info(m: String): Pre[Unit] =
Precepte.delay(println(m))
}

final case class Stuff(id: Long, name: String)
Expand Down Expand Up @@ -113,7 +112,8 @@ class SamplesSpec extends FlatSpec with ScalaFutures {
_ <- s.unmanaged.metric
.metric(s"$stuff going to pay $amount")
.unify(s)
r <- Precepte.liftF(Future(Paid(stuff.id, amount)))
r <- Precepte.liftF[BaseTags, MS, PayCtx, Future, Paid](
Future(Paid(stuff.id, amount)))
_ <- s.unmanaged.logger.info(s"$stuff paid $amount").unify(s)
} yield (r)
}
Expand Down
2 changes: 1 addition & 1 deletion precepte-influx/src/main/scala/Influx.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ object Influx {
implicit executionContext: ExecutionContext)
: Precepte[BaseTags, MS, U, Future, Unit] =
Precepte
.deferredLift(
.deferredLift[BaseTags, MS, U, Future, Unit](
Future(
client.write(dbName, retentionPolicy, timeMeasurementToPoint(tm))))
.recoverWith(errorHandler)
Expand Down
4 changes: 2 additions & 2 deletions precepte-sample/app/Boostrap.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package env

import play.api.ApplicationLoader.Context
import play.api.db.{DBComponents}
import play.api.db.DBComponents
import play.api.db.evolutions.EvolutionsComponents
import router.Routes
import play.api.{Application, ApplicationLoader, Environment, Logger}

final class BootstrapLoader extends ApplicationLoader {
def load(context: Context): Application = {
// Bootstrap the injected application
Logger.info("All good")
Logger("application").info("All good")
new env.ApplicationEnv(context).application
}
}
Expand Down
20 changes: 10 additions & 10 deletions precepte-sample/app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ final class Application(
/**
* This result directly redirect to the application home.
*/
val Home = Redirect(routes.Application.list(0, 2, ""))
val Home: Result = Redirect(routes.Application.list(0, 2, ""))

/**
* Describe the computer form (used in both edit and create screens).
*/
val computerForm = Form(
val computerForm: Form[Computer] = Form(
mapping(
"id" -> ignored[Option[Long]](None),
"name" -> nonEmptyText,
Expand All @@ -80,22 +80,22 @@ final class Application(
* @param orderBy Column to be sorted
* @param filter Filter applied on computer names
*/
def list(page: Int, orderBy: Int, filter: String) = async(TimedAction) {
req =>
def list(page: Int, orderBy: Int, filter: String): Action[AnyContent] =
async(TimedAction) { req =>
implicit val r = req._2
for {
cs <- computerDB.list(page = page,
orderBy = orderBy,
filter = ("%" + filter + "%"))
} yield Ok(html.list(cs, orderBy, filter))
}
}

/**
* Display the 'edit form' of a existing Computer.
*
* @param id Id of the computer to edit
*/
def edit(id: Long) = async(TimedAction) { req =>
def edit(id: Long): Action[AnyContent] = async(TimedAction) { req =>
implicit val r = req._2

(for {
Expand All @@ -111,7 +111,7 @@ final class Application(
*
* @param id Id of the computer to edit
*/
def update(id: Long) = async(TimedAction) { req =>
def update(id: Long): Action[AnyContent] = async(TimedAction) { req =>
implicit val r = req._2
computerForm.bindFromRequest.fold(
formWithErrors =>
Expand All @@ -130,7 +130,7 @@ final class Application(
/**
* Display the 'new computer form'.
*/
def create = async(TimedAction) { req =>
def create: Action[AnyContent] = async(TimedAction) { req =>
implicit val r = req._2
for {
options <- companyDB.options
Expand All @@ -140,7 +140,7 @@ final class Application(
/**
* Handle the 'new computer form' submission.
*/
def save = async(TimedAction) { req =>
def save: Action[AnyContent] = async(TimedAction) { req =>
implicit val r = req._2
computerForm.bindFromRequest.fold(
formWithErrors =>
Expand All @@ -160,7 +160,7 @@ final class Application(
/**
* Handle computer deletion.
*/
def delete(id: Long) = async(TimedAction) { _ =>
def delete(id: Long): Action[AnyContent] = async(TimedAction) { _ =>
for {
_ <- computerDB.delete(id)
} yield Home.flashing("success" -> "Computer has been deleted")
Expand Down
23 changes: 16 additions & 7 deletions precepte-sample/test/ApplicationSpec.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.mfglabs.precepte
import play.api.mvc.{Action, AnyContent}
import play.api.test._

class ApplicationSpec extends PlaySpecification {
Expand All @@ -10,28 +12,31 @@ class ApplicationSpec extends PlaySpecification {

"Application" should {

"redirect to the computer list on /" in new WithApplication {
"redirect to the computer list on /" in new precepte.test.WithApplication {
val result = Controllers.application.index(FakeRequest())

status(result) must equalTo(SEE_OTHER)
redirectLocation(result) must beSome.which(_ == "/computers")
}

"list computers on the the first page" in new WithApplication {
val result = Controllers.application.list(0, 2, "")(FakeRequest())
"list computers on the the first page" in new precepte.test.WithApplication {
val action: Action[AnyContent] = Controllers.application.list(0, 2, "")
val result = action(FakeRequest())

status(result) must equalTo(OK)
contentAsString(result) must contain("574 computers found")
}

"filter computer by name" in new WithApplication {
val result = Controllers.application.list(0, 2, "Apple")(FakeRequest())
"filter computer by name" in new precepte.test.WithApplication {
val action: Action[AnyContent] =
Controllers.application.list(0, 2, "Apple")
val result = action(FakeRequest())

status(result) must equalTo(OK)
contentAsString(result) must contain("13 computers found")
}

"create new computer" in new WithApplication {
"create new computer" in new precepte.test.WithApplication {
val badResult = Controllers.application.save(FakeRequest())

status(badResult) must equalTo(BAD_REQUEST)
Expand Down Expand Up @@ -61,7 +66,11 @@ class ApplicationSpec extends PlaySpecification {
flash(result).get("success") must beSome.which(
_ == "Computer FooBar has been created")

val list = Controllers.application.list(0, 2, "FooBar")(FakeRequest())
val list = {
val action: Action[AnyContent] =
Controllers.application.list(0, 2, "FooBar")
action(FakeRequest())
}

status(list) must equalTo(OK)
contentAsString(list) must contain("One computer found")
Expand Down
5 changes: 2 additions & 3 deletions precepte-sample/test/IntegrationSpec.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import com.mfglabs.precepte
import org.specs2.runner._
import org.junit.runner._

import play.api.test._

import org.fluentlenium.core.filter.FilterConstructor._

@RunWith(classOf[JUnitRunner])
class IntegrationSpec extends PlaySpecification {

"Application" should {

"work from within a browser" in new WithApplication {
"work from within a browser" in new precepte.test.WithApplication {
new WithBrowser(webDriver = WebDriverFactory(HTMLUNIT), app = app) {
browser.goTo("http://localhost:19001/")

Expand Down
7 changes: 4 additions & 3 deletions precepte-sample/test/ModelSpec.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.mfglabs.precepte
import org.specs2.mutable._

import scala.concurrent.Await
Expand Down Expand Up @@ -31,7 +32,7 @@ class ModelSpec extends Specification {

"Computer model" should {

"be retrieved by id" in new WithApplication {
"be retrieved by id" in new precepte.test.WithApplication {
val Some(macintosh) =
Await.result(Services.computerDB.findById(21).eval(nostate),
Duration.Inf)
Expand All @@ -40,15 +41,15 @@ class ModelSpec extends Specification {
macintosh.introduced must beSome.which(dateIs(_, "1984-01-24"))
}

"be listed along its companies" in new WithApplication {
"be listed along its companies" in new precepte.test.WithApplication {
val computers =
Await.result(Services.computerDB.list().eval(nostate), Duration.Inf)

computers.total must equalTo(574)
computers.items must have length (10)
}

"be updated if needed" in new WithApplication {
"be updated if needed" in new precepte.test.WithApplication {
Await.result(
Services.computerDB
.update(21,
Expand Down
17 changes: 11 additions & 6 deletions precepte-sample/test/WithApplication.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.mfglabs
package precepte
package test

import org.specs2.execute._
import org.specs2.mutable._
import org.specs2.specification.Scope

import play.api._

abstract class WithApplication extends Around with Scope {
lazy val context = ApplicationLoader.createContext(
new Environment(new java.io.File("."),
ApplicationLoader.getClass.getClassLoader,
Mode.Test)
)
lazy val context = ApplicationLoader.Context.create {
new Environment(
new java.io.File("."),
ApplicationLoader.getClass.getClassLoader,
Mode.Test
)
}

lazy val applicationEnv = new env.ApplicationEnv(context)
implicit lazy val app = applicationEnv.application
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.2.8
sbt.version=1.3.0
Loading

0 comments on commit 2a7086c

Please sign in to comment.