Skip to content

Commit

Permalink
WegenenVerkeer#47-introduce-scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Grutsch committed Jun 21, 2019
1 parent 28c2794 commit d3fa16f
Show file tree
Hide file tree
Showing 74 changed files with 1,295 additions and 1,160 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ project/plugins/project/
.worksheet
.idea


# scala metals specific
.metals
.bloop
7 changes: 7 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version = 2.0.0-RC5

style = defaultWithAlign

maxColumn = 120
rewrite.rules = [RedundantBraces, RedundantParens, SortImports]
optIn.breakChainOnFirstMethodDot = true
43 changes: 28 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
language: scala

scala:
- 2.11.12
- 2.12.8
- 2.11.12
- 2.12.8

script:
- sbt "++ $TRAVIS_SCALA_VERSION test"
- sbt "++ $TRAVIS_SCALA_VERSION test"

sudo: false

jdk:
- oraclejdk8
- oraclejdk8

services:
- postgresql
- postgresql

addons:
postgresql: '9.4'

before_script:
- psql -c 'create database akkapg;' -U postgres
- psql akkapg -c "create extension hstore;" -U postgres
- psql -c "create user akkapg with password 'akkapg';" -U postgres
- psql -c "grant all privileges on database akkapg to akkapg;" -U postgres
- sbt scalafmtCheckAll || { echo "[error] Unformatted code found. Please run 'scalafmtAll' and commit the reformatted code."; false; }
- sbt scalafmtSbtCheck || { echo "[error] Unformatted sbt code found. Please run 'scalafmtSbt' and commit the reformatted code."; false; }
- psql -c 'create database akkapg;' -U postgres
- psql akkapg -c "create extension hstore;" -U postgres
- psql -c "create user akkapg with password 'akkapg';" -U postgres
- psql -c "grant all privileges on database akkapg to akkapg;" -U postgres

cache:
directories:
- "$HOME/.ivy2"
- "$HOME/.sbt"
- "$HOME/.ivy2"
- "$HOME/.sbt"

notifications:
email:
recipients:
- [email protected]
- [email protected]
- [email protected]
- [email protected]

#after_success:
#- '[[ $TRAVIS_BRANCH == "develop" ]] && { sbt "++ $TRAVIS_SCALA_VERSION publish"; };'

env:
global:
- SONATYPE_USERNAME=kmaesen
- secure: ZU+VxelX+z1nvPOJ+62hl4e6W8k3i2zjq/A1Sz1BSfgbjcTF94az+86YbiyCrpKYc6seUWGswneUOBSX6ib1PONFeLMlKwIUyRPXJIYuJxgYeF4uuJnGtSrzrpVxuFAh0e7Ju/p1A/EleKlfdtjdH4Lr9jFoHGKItcxMxVOQWk6NMvopevpD3+2asPY5dYv5rR5sCHT9fpCh0pvYVN9iQRl+0kzYBYUcC8En307USfx8rl7qHFaAiHe69g4JMBoBR2GmSbFfcSaq7/NCSz3qu/wpk7pNA9ieyChQaotrZxdlQLmO75Jo6mqw/8sCZIqw4OrWS7oNmMzZ1MPNsWEJ820vr56+S/ij0Vz8uns3xakxKky3bJ6Oeg8dFQe0Bj76MCN6y/V+aGQcqMcQmIovbskUyPC0KK62K9gMvwOm7zrrvT6xDOpsTSAVW4yZPGDGY6Jc5DJWT1833qgYJMYcAd+pZSnaE4gvINsjqSHieCIGjxtR+3xhqZ+xqyoDFQl3GejKpmVXbiGR+W2WE/GJRHNWQaC6nhg/Cy+zwObDl1B3TwBBwC0xi8FYfi8pUeNgqH5N35e3XWB9JiBRHWbfwnlcJOmquaduKhA6DMntB15EB/9mM2oLSRazvnkCtof45O9Zm2OTkpqbJ3I/jbaoOMKMWXmhLHsBBmvkxicPsao=
- SONATYPE_USERNAME=kmaesen
- secure: ZU+VxelX+z1nvPOJ+62hl4e6W8k3i2zjq/A1Sz1BSfgbjcTF94az+86YbiyCrpKYc6seUWGswneUOBSX6ib1PONFeLMlKwIUyRPXJIYuJxgYeF4uuJnGtSrzrpVxuFAh0e7Ju/p1A/EleKlfdtjdH4Lr9jFoHGKItcxMxVOQWk6NMvopevpD3+2asPY5dYv5rR5sCHT9fpCh0pvYVN9iQRl+0kzYBYUcC8En307USfx8rl7qHFaAiHe69g4JMBoBR2GmSbFfcSaq7/NCSz3qu/wpk7pNA9ieyChQaotrZxdlQLmO75Jo6mqw/8sCZIqw4OrWS7oNmMzZ1MPNsWEJ820vr56+S/ij0Vz8uns3xakxKky3bJ6Oeg8dFQe0Bj76MCN6y/V+aGQcqMcQmIovbskUyPC0KK62K9gMvwOm7zrrvT6xDOpsTSAVW4yZPGDGY6Jc5DJWT1833qgYJMYcAd+pZSnaE4gvINsjqSHieCIGjxtR+3xhqZ+xqyoDFQl3GejKpmVXbiGR+W2WE/GJRHNWQaC6nhg/Cy+zwObDl1B3TwBBwC0xi8FYfi8pUeNgqH5N35e3XWB9JiBRHWbfwnlcJOmquaduKhA6DMntB15EB/9mM2oLSRazvnkCtof45O9Zm2OTkpqbJ3I/jbaoOMKMWXmhLHsBBmvkxicPsao=
42 changes: 25 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ concurrentRestrictions in Global += Tags.limit(Tags.Test, 1)
scalacOptions in ThisBuild := {
val commonOptions = Seq(
"-target:jvm-1.8",
"-encoding", "UTF-8",
"-deprecation", // warning and location for usages of deprecated APIs
"-feature", // warning and location for usages of features that should be imported explicitly
"-unchecked", // additional warnings where generated code depends on assumptions
"-Xlint", // recommended additional warnings
"-Ywarn-adapted-args", // Warn if an argument list is modified to match the receiver
"-encoding",
"UTF-8",
"-deprecation", // warning and location for usages of deprecated APIs
"-feature", // warning and location for usages of features that should be imported explicitly
"-unchecked", // additional warnings where generated code depends on assumptions
"-Xlint", // recommended additional warnings
"-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",
Expand All @@ -27,16 +28,26 @@ scalacOptions in ThisBuild := {

lazy val akkaPersistencePgModule = {

val mainDeps = Seq(scalaJava8Compat, slick, slickHikariCp, postgres,
akkaPersistence, akkaPersistenceQuery, akkaActor, akkaStreams, akkaTest, akkaPersistenceTestkit, slf4jSimple)
val mainDeps = Seq(
scalaJava8Compat,
slick,
slickHikariCp,
postgres,
akkaPersistence,
akkaPersistenceQuery,
akkaActor,
akkaStreams,
akkaTest,
akkaPersistenceTestkit,
slf4jSimple
)

val It = config("it") extend Test

Project(
id = "akka-persistence-pg",
base = file("modules/akka-persistence-pg")
)
.configs(It)
).configs(It)
.settings(Defaults.coreDefaultSettings ++ commonSettings ++ publishSettings)
.settings(Defaults.itSettings: _*)
.settings(crossScalaVersions := (crossScalaVersions in ThisBuild).value)
Expand All @@ -53,23 +64,20 @@ lazy val benchmarkModule = {
Project(
id = "benchmark",
base = file("modules/benchmark")
)
.dependsOn(akkaPersistencePgModule % "it->test;test->test;compile->compile")
).dependsOn(akkaPersistencePgModule % "it->test;test->test;compile->compile")
.enablePlugins(GatlingPlugin)
.configs(GatlingIt)
.settings(Defaults.coreDefaultSettings ++ commonSettings ++ Seq(skip in publish := true))

.settings(crossScalaVersions := (crossScalaVersions in ThisBuild).value.filter(_ startsWith "2.12"))
.settings(scalaVersion := crossScalaVersions.value.last)


}

val main = Project(
id = "akka-persistence-postgresql",
base = file(".")
)
.settings(Defaults.coreDefaultSettings ++ commonSettings ++
Seq(publishLocal := {}, publish := {}, packagedArtifacts := Map.empty, crossScalaVersions := Seq.empty)
).settings(
Defaults.coreDefaultSettings ++ commonSettings ++
Seq(publishLocal := {}, publish := {}, packagedArtifacts := Map.empty, crossScalaVersions := Seq.empty)
)
.aggregate(akkaPersistencePgModule, benchmarkModule)
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ trait AkkaPgJdbcTypes extends JdbcTypesComponent { driver: PostgresProfile =>

import driver.api._

private[this] class GenericJdbcType[T](val sqlTypeName: String,
fnFromString: String => T,
fnToString: T => String = (r: T) => r.toString,
val sqlType: Int = java.sql.Types.OTHER,
zero: T = null.asInstanceOf[T],
override val hasLiteralForm: Boolean = false)(
implicit override val classTag: ClassTag[T]) extends DriverJdbcType[T] {
private[this] class GenericJdbcType[T](
val sqlTypeName: String,
fnFromString: String => T,
fnToString: T => String = (r: T) => r.toString,
val sqlType: Int = java.sql.Types.OTHER,
zero: T = null.asInstanceOf[T],
override val hasLiteralForm: Boolean = false
)(implicit override val classTag: ClassTag[T])
extends DriverJdbcType[T] {

override def sqlTypeName(sym: Option[FieldSymbol]): String = sqlTypeName

Expand All @@ -40,30 +42,30 @@ trait AkkaPgJdbcTypes extends JdbcTypesComponent { driver: PostgresProfile =>

override def updateValue(v: T, r: ResultSet, idx: Int): Unit = r.updateObject(idx, toStr(v), java.sql.Types.OTHER)

override def valueToSQLLiteral(v: T): String = if(v == null) "NULL" else s"'${fnToString(v)}'"
override def valueToSQLLiteral(v: T): String = if (v == null) "NULL" else s"'${fnToString(v)}'"

private def toStr(v: T) = if(v == null) null else fnToString(v)
private def toStr(v: T) = if (v == null) null else fnToString(v)
}

protected def fromInfinitable[T](max: T, min: T, parse: String => T): String => T = {
case "infinity" => max
case "infinity" => max
case "-infinity" => min
case finite => parse(finite)
case finite => parse(finite)
}

protected def toInfinitable[T](max: T, min: T, format: T => String): T => String = {
case `max` => "infinity"
case `min` => "-infinity"
case `max` => "infinity"
case `min` => "-infinity"
case finite => format(finite)
}

private val date2TzDateTimeFormatter =
new DateTimeFormatterBuilder()
.append(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
.optionalStart()
.appendFraction(ChronoField.NANO_OF_SECOND,0,6,true)
.appendFraction(ChronoField.NANO_OF_SECOND, 0, 6, true)
.optionalEnd()
.appendOffset("+HH:mm","+00")
.appendOffset("+HH:mm", "+00")
.toFormatter()

protected val fromOffsetDateTimeOrInfinity: String => OffsetDateTime =
Expand All @@ -73,8 +75,12 @@ trait AkkaPgJdbcTypes extends JdbcTypesComponent { driver: PostgresProfile =>

trait AkkaPgImplicits {

implicit val date2TzTimestampTypeMapper: JdbcType[OffsetDateTime] = new GenericJdbcType[OffsetDateTime]("timestamptz",
fromOffsetDateTimeOrInfinity, toOffsetDateTimeOrInfinity, hasLiteralForm = false)
implicit val date2TzTimestampTypeMapper: JdbcType[OffsetDateTime] = new GenericJdbcType[OffsetDateTime](
"timestamptz",
fromOffsetDateTimeOrInfinity,
toOffsetDateTimeOrInfinity,
hasLiteralForm = false
)

implicit val simpleHStoreTypeMapper: JdbcType[Map[String, String]] =
new GenericJdbcType[Map[String, String]](
Expand All @@ -84,9 +90,10 @@ trait AkkaPgJdbcTypes extends JdbcTypesComponent { driver: PostgresProfile =>
hasLiteralForm = false
)

implicit def simpleHStoreColumnExtensionMethods(c: Rep[Map[String, String]]): HStoreColumnExtensionMethods[Map[String, String]] = {
implicit def simpleHStoreColumnExtensionMethods(
c: Rep[Map[String, String]]
): HStoreColumnExtensionMethods[Map[String, String]] =
new HStoreColumnExtensionMethods[Map[String, String]](c)
}

implicit val jsonStringTypeMapper: JdbcType[JsonString] =
new GenericJdbcType[JsonString](
Expand All @@ -99,19 +106,15 @@ trait AkkaPgJdbcTypes extends JdbcTypesComponent { driver: PostgresProfile =>
}

/** Extension methods for hstore Columns */
class HStoreColumnExtensionMethods[P1](val c: Rep[P1])(
implicit tm: JdbcType[Map[String, String]])
extends ExtensionMethods[Map[String, String], P1] {
class HStoreColumnExtensionMethods[P1](val c: Rep[P1])(implicit tm: JdbcType[Map[String, String]])
extends ExtensionMethods[Map[String, String], P1] {

val Contains = new SqlOperator("@>")

protected implicit def b1Type: TypedType[Map[String, String]] = implicitly[TypedType[Map[String, String]]]

def @>[P2, R](c2: Rep[P2])(implicit om: o#arg[Map[String, String], P2]#to[Boolean, R]): Rep[R] = {
def @>[P2, R](c2: Rep[P2])(implicit om: o#arg[Map[String, String], P2]#to[Boolean, R]): Rep[R] =
om.column(Contains, n, c2.toNode)
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import slick.jdbc.JdbcBackend
trait PgConfig {

def pluginConfig: PluginConfig
lazy val driver: PgPostgresProfile = pluginConfig.pgPostgresProfile
lazy val driver: PgPostgresProfile = pluginConfig.pgPostgresProfile
lazy val database: JdbcBackend.DatabaseDef = pluginConfig.database

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import scala.concurrent.duration._
import scala.concurrent.Future
import scala.language.postfixOps


object PgExtension extends ExtensionId[PgExtension] with ExtensionIdProvider {

override def createExtension(system: ExtendedActorSystem): PgExtension = new PgExtension(system)
Expand All @@ -36,8 +35,9 @@ class PgExtension(system: ExtendedActorSystem) extends Extension {

implicit val timeout = Timeout(5 seconds)

def isBusy: Future[Boolean] = {
system.actorSelection("/user/AkkaPgRowIdUpdater")
def isBusy: Future[Boolean] =
system
.actorSelection("/user/AkkaPgRowIdUpdater")
.resolveOne()
.flatMap { rowIdUpdater =>
rowIdUpdater ? IsBusy
Expand All @@ -46,10 +46,9 @@ class PgExtension(system: ExtendedActorSystem) extends Extension {
.recover {
case e: ActorNotFound => false
}
}

def go(): Future[T] = isBusy.flatMap {
case true => Thread.sleep(100); go()
case true => Thread.sleep(100); go()
case false => t
}

Expand All @@ -59,8 +58,7 @@ class PgExtension(system: ExtendedActorSystem) extends Extension {

def terminateWhenReady(): Future[Terminated] = whenDone(system.terminate())

def getClassFor[T: ClassTag](s: String): Class[_ <: T] = {
def getClassFor[T: ClassTag](s: String): Class[_ <: T] =
system.dynamicAccess.getClassFor[T](s).getOrElse(sys.error(s"could not find class with name $s"))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ trait PgPostgresProfile extends PostgresProfile with AkkaPgJdbcTypes {
}

class PgPostgresProfileImpl(override val pgjson: String) extends PgPostgresProfile

Loading

0 comments on commit d3fa16f

Please sign in to comment.