scalafmt
parent
8f8af7d55a
commit
540e632404
|
@ -0,0 +1,6 @@
|
||||||
|
version = "2.3.2"
|
||||||
|
align = more
|
||||||
|
maxColumn = 110
|
||||||
|
spaces.inImportCurlyBraces = true
|
||||||
|
rewrite.rules = [SortImports, RedundantParens, SortModifiers]
|
||||||
|
rewrite.redundantBraces.stringInterpolation = true
|
12
build.sbt
12
build.sbt
|
@ -1,5 +1,4 @@
|
||||||
import com.typesafe.sbt.packager.Keys.scriptClasspath
|
import com.typesafe.sbt.packager.Keys.scriptClasspath
|
||||||
import com.typesafe.sbt.SbtScalariform.autoImport.scalariformFormat
|
|
||||||
|
|
||||||
import BuildSettings._
|
import BuildSettings._
|
||||||
import Dependencies._
|
import Dependencies._
|
||||||
|
@ -25,7 +24,10 @@ PlayKeys.playDefaultPort := 9663
|
||||||
PlayKeys.externalizeResources := false
|
PlayKeys.externalizeResources := false
|
||||||
// shorter prod classpath
|
// shorter prod classpath
|
||||||
scriptClasspath := Seq("*")
|
scriptClasspath := Seq("*")
|
||||||
// offline := true
|
// don't make an assets jar
|
||||||
|
resourceDirectory in Assets := (sourceDirectory in Compile).value / "assets"
|
||||||
|
|
||||||
|
// format: off
|
||||||
libraryDependencies ++= Seq(
|
libraryDependencies ++= Seq(
|
||||||
macwire.macros, macwire.util, play.json, jodaForms, ws,
|
macwire.macros, macwire.util, play.json, jodaForms, ws,
|
||||||
scalaz, chess, compression, scalalib, hasher,
|
scalaz, chess, compression, scalalib, hasher,
|
||||||
|
@ -35,12 +37,6 @@ libraryDependencies ++= Seq(
|
||||||
scrimage, scaffeine, lettuce, epoll
|
scrimage, scaffeine, lettuce, epoll
|
||||||
) ++ silencer.bundle
|
) ++ silencer.bundle
|
||||||
|
|
||||||
resourceDirectory in Assets := (sourceDirectory in Compile).value / "assets"
|
|
||||||
|
|
||||||
scalariformPreferences := scalariformPrefs(scalariformPreferences.value)
|
|
||||||
excludeFilter in scalariformFormat := "*Routes*"
|
|
||||||
routesGenerator := LilaRoutesGenerator
|
|
||||||
|
|
||||||
lazy val modules = Seq(
|
lazy val modules = Seq(
|
||||||
common, db, rating, user, security, hub, socket,
|
common, db, rating, user, security, hub, socket,
|
||||||
message, notifyModule, i18n, game, bookmark, search,
|
message, notifyModule, i18n, game, bookmark, search,
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import com.typesafe.sbt.SbtScalariform.autoImport.scalariformPreferences
|
|
||||||
import play.sbt.PlayImport._
|
import play.sbt.PlayImport._
|
||||||
import sbt._, Keys._
|
import sbt._, Keys._
|
||||||
import scalariform.formatter.preferences._
|
|
||||||
|
|
||||||
object BuildSettings {
|
object BuildSettings {
|
||||||
|
|
||||||
|
@ -19,29 +17,31 @@ object BuildSettings {
|
||||||
// disable publishing the main API jar
|
// disable publishing the main API jar
|
||||||
publishArtifact in (Compile, packageDoc) := false,
|
publishArtifact in (Compile, packageDoc) := false,
|
||||||
// disable publishing the main sources jar
|
// disable publishing the main sources jar
|
||||||
publishArtifact in (Compile, packageSrc) := false,
|
publishArtifact in (Compile, packageSrc) := false
|
||||||
scalariformPreferences := scalariformPrefs(scalariformPreferences.value)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def scalariformPrefs(prefs: IFormattingPreferences) = prefs
|
|
||||||
.setPreference(DanglingCloseParenthesis, Force)
|
|
||||||
.setPreference(DoubleIndentConstructorArguments, true)
|
|
||||||
|
|
||||||
def defaultLibs: Seq[ModuleID] = Seq(
|
def defaultLibs: Seq[ModuleID] = Seq(
|
||||||
play.api, scalaz, chess, scalalib, jodaTime, ws,
|
play.api,
|
||||||
macwire.macros, macwire.util, autoconfig, specs2
|
scalaz,
|
||||||
|
chess,
|
||||||
|
scalalib,
|
||||||
|
jodaTime,
|
||||||
|
ws,
|
||||||
|
macwire.macros,
|
||||||
|
macwire.util,
|
||||||
|
autoconfig,
|
||||||
|
specs2
|
||||||
)
|
)
|
||||||
|
|
||||||
def module(
|
def module(
|
||||||
name: String,
|
name: String,
|
||||||
deps: Seq[sbt.ClasspathDep[sbt.ProjectReference]],
|
deps: Seq[sbt.ClasspathDep[sbt.ProjectReference]],
|
||||||
libs: Seq[ModuleID]
|
libs: Seq[ModuleID]
|
||||||
) =
|
) =
|
||||||
Project(
|
Project(
|
||||||
name,
|
name,
|
||||||
file("modules/" + name)
|
file("modules/" + name)
|
||||||
)
|
).dependsOn(deps: _*)
|
||||||
.dependsOn(deps: _*)
|
|
||||||
.settings(
|
.settings(
|
||||||
libraryDependencies ++= defaultLibs ++ libs ++ silencer.bundle,
|
libraryDependencies ++= defaultLibs ++ libs ++ silencer.bundle,
|
||||||
buildSettings,
|
buildSettings,
|
||||||
|
@ -59,8 +59,10 @@ object BuildSettings {
|
||||||
"-Ywarn-macros:after",
|
"-Ywarn-macros:after",
|
||||||
"-Ywarn-unused:_",
|
"-Ywarn-unused:_",
|
||||||
// "-Xfatal-warnings",
|
// "-Xfatal-warnings",
|
||||||
"-Xmaxerrs", "12",
|
"-Xmaxerrs",
|
||||||
"-Xmaxwarns", "12"
|
"12",
|
||||||
|
"-Xmaxwarns",
|
||||||
|
"12"
|
||||||
)
|
)
|
||||||
|
|
||||||
val srcMain = Seq(
|
val srcMain = Seq(
|
||||||
|
|
|
@ -5,41 +5,41 @@ object Dependencies {
|
||||||
|
|
||||||
object Resolvers {
|
object Resolvers {
|
||||||
|
|
||||||
val sonatype = Resolver.sonatypeRepo("releases")
|
val sonatype = Resolver.sonatypeRepo("releases")
|
||||||
val lilaMaven = "lila-maven" at "https://raw.githubusercontent.com/ornicar/lila-maven/master"
|
val lilaMaven = "lila-maven" at "https://raw.githubusercontent.com/ornicar/lila-maven/master"
|
||||||
|
|
||||||
val commons = Seq(lilaMaven, sonatype)
|
val commons = Seq(lilaMaven, sonatype)
|
||||||
}
|
}
|
||||||
|
|
||||||
val scalaz = "org.scalaz" %% "scalaz-core" % "7.2.29"
|
val scalaz = "org.scalaz" %% "scalaz-core" % "7.2.29"
|
||||||
val scalalib = "com.github.ornicar" %% "scalalib" % "6.7"
|
val scalalib = "com.github.ornicar" %% "scalalib" % "6.7"
|
||||||
val hasher = "com.roundeights" %% "hasher" % "1.2.1"
|
val hasher = "com.roundeights" %% "hasher" % "1.2.1"
|
||||||
val jodaTime = "joda-time" % "joda-time" % "2.10.5"
|
val jodaTime = "joda-time" % "joda-time" % "2.10.5"
|
||||||
val chess = "org.lichess" %% "scalachess" % "9.0.27"
|
val chess = "org.lichess" %% "scalachess" % "9.0.27"
|
||||||
val compression = "org.lichess" %% "compression" % "1.5"
|
val compression = "org.lichess" %% "compression" % "1.5"
|
||||||
val maxmind = "com.sanoma.cda" %% "maxmind-geoip2-scala" % "1.3.1-THIB"
|
val maxmind = "com.sanoma.cda" %% "maxmind-geoip2-scala" % "1.3.1-THIB"
|
||||||
val prismic = "io.prismic" %% "scala-kit" % "1.2.13-THIB213"
|
val prismic = "io.prismic" %% "scala-kit" % "1.2.13-THIB213"
|
||||||
val scrimage = "com.sksamuel.scrimage" %% "scrimage-core" % "2.1.8-SNAPSHOT"
|
val scrimage = "com.sksamuel.scrimage" %% "scrimage-core" % "2.1.8-SNAPSHOT"
|
||||||
val scaffeine = "com.github.blemale" %% "scaffeine" % "3.1.0" % "compile"
|
val scaffeine = "com.github.blemale" %% "scaffeine" % "3.1.0" % "compile"
|
||||||
val googleOAuth = "com.google.auth" % "google-auth-library-oauth2-http" % "0.18.0"
|
val googleOAuth = "com.google.auth" % "google-auth-library-oauth2-http" % "0.18.0"
|
||||||
val scalaUri = "io.lemonlabs" %% "scala-uri" % "1.5.1"
|
val scalaUri = "io.lemonlabs" %% "scala-uri" % "1.5.1"
|
||||||
val scalatags = "com.lihaoyi" %% "scalatags" % "0.7.0"
|
val scalatags = "com.lihaoyi" %% "scalatags" % "0.7.0"
|
||||||
val lettuce = "io.lettuce" % "lettuce-core" % "5.2.1.RELEASE"
|
val lettuce = "io.lettuce" % "lettuce-core" % "5.2.1.RELEASE"
|
||||||
val epoll = "io.netty" % "netty-transport-native-epoll" % "4.1.43.Final" classifier "linux-x86_64"
|
val epoll = "io.netty" % "netty-transport-native-epoll" % "4.1.43.Final" classifier "linux-x86_64"
|
||||||
val markdown = "com.vladsch.flexmark" % "flexmark-all" % "0.50.44"
|
val markdown = "com.vladsch.flexmark" % "flexmark-all" % "0.50.44"
|
||||||
val autoconfig = "io.methvin.play" %% "autoconfig-macros" % "0.3.2-SNAPSHOT" % "provided"
|
val autoconfig = "io.methvin.play" %% "autoconfig-macros" % "0.3.2-SNAPSHOT" % "provided"
|
||||||
|
|
||||||
object macwire {
|
object macwire {
|
||||||
val version = "2.3.3"
|
val version = "2.3.3"
|
||||||
val macros = "com.softwaremill.macwire" %% "macros" % version % "provided"
|
val macros = "com.softwaremill.macwire" %% "macros" % version % "provided"
|
||||||
val util = "com.softwaremill.macwire" %% "util" % version % "provided"
|
val util = "com.softwaremill.macwire" %% "util" % version % "provided"
|
||||||
}
|
}
|
||||||
|
|
||||||
object reactivemongo {
|
object reactivemongo {
|
||||||
val version = "0.19.3"
|
val version = "0.19.3"
|
||||||
val driver = "org.reactivemongo" %% "reactivemongo" % "0.20.0-SNAPSHOT"
|
val driver = "org.reactivemongo" %% "reactivemongo" % "0.20.0-SNAPSHOT"
|
||||||
val bson = "org.reactivemongo" %% "reactivemongo-bson-api" % "0.20.0-SNAPSHOT"
|
val bson = "org.reactivemongo" %% "reactivemongo-bson-api" % "0.20.0-SNAPSHOT"
|
||||||
val stream = "org.reactivemongo" %% "reactivemongo-akkastream" % version
|
val stream = "org.reactivemongo" %% "reactivemongo-akkastream" % version
|
||||||
// val native = "org.reactivemongo" % "reactivemongo-shaded-native" % s"$version-linux-x86-64" classifier "linux-x86_64"
|
// val native = "org.reactivemongo" % "reactivemongo-shaded-native" % s"$version-linux-x86-64" classifier "linux-x86_64"
|
||||||
val native = "org.reactivemongo" % "reactivemongo-shaded-native" % s"$version-linux-x86-64"
|
val native = "org.reactivemongo" % "reactivemongo-shaded-native" % s"$version-linux-x86-64"
|
||||||
// #TODO remove compat
|
// #TODO remove compat
|
||||||
|
@ -49,19 +49,19 @@ object Dependencies {
|
||||||
|
|
||||||
object play {
|
object play {
|
||||||
val version = "2.8.0"
|
val version = "2.8.0"
|
||||||
val api = "com.typesafe.play" %% "play" % version
|
val api = "com.typesafe.play" %% "play" % version
|
||||||
val json = "com.typesafe.play" %% "play-json" % version
|
val json = "com.typesafe.play" %% "play-json" % version
|
||||||
}
|
}
|
||||||
object kamon {
|
object kamon {
|
||||||
val core = "io.kamon" %% "kamon-core" % "2.0.2"
|
val core = "io.kamon" %% "kamon-core" % "2.0.2"
|
||||||
val influxdb = "io.kamon" %% "kamon-influxdb" % "2.0.1-LILA"
|
val influxdb = "io.kamon" %% "kamon-influxdb" % "2.0.1-LILA"
|
||||||
val metrics = "io.kamon" %% "kamon-system-metrics" % "2.0.0"
|
val metrics = "io.kamon" %% "kamon-system-metrics" % "2.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
object silencer {
|
object silencer {
|
||||||
val version = "1.4.4"
|
val version = "1.4.4"
|
||||||
val plugin = "com.github.ghik" % "silencer-plugin" % version cross CrossVersion.full
|
val plugin = "com.github.ghik" % "silencer-plugin" % version cross CrossVersion.full
|
||||||
val lib = "com.github.ghik" % "silencer-lib" % version % Provided cross CrossVersion.full
|
val lib = "com.github.ghik" % "silencer-lib" % version % Provided cross CrossVersion.full
|
||||||
val bundle = Seq(compilerPlugin(plugin), lib)
|
val bundle = Seq(compilerPlugin(plugin), lib)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,24 +17,25 @@ object MessageCompiler {
|
||||||
|
|
||||||
private def doFile(db: String, sourceFile: File, destDir: File, compileTo: File): Seq[File] = {
|
private def doFile(db: String, sourceFile: File, destDir: File, compileTo: File): Seq[File] = {
|
||||||
destDir.mkdirs()
|
destDir.mkdirs()
|
||||||
val registry = ("en-GB" -> sourceFile) :: destDir.list.toList.map { f =>
|
val registry = ("en-GB" -> sourceFile) :: destDir.list.toList
|
||||||
f.takeWhile('.' !=) -> (destDir / f)
|
.map { f =>
|
||||||
}.sortBy(_._1)
|
f.takeWhile('.' !=) -> (destDir / f)
|
||||||
|
}
|
||||||
|
.sortBy(_._1)
|
||||||
compileTo.mkdirs()
|
compileTo.mkdirs()
|
||||||
var translatedLocales = Set.empty[String]
|
var translatedLocales = Set.empty[String]
|
||||||
val res = for {
|
val res = for {
|
||||||
entry <- registry
|
entry <- registry
|
||||||
compilable <- {
|
compilable <- {
|
||||||
val (locale, file) = entry
|
val (locale, file) = entry
|
||||||
val compileToFile = compileTo / s"$locale.scala"
|
val compileToFile = compileTo / s"$locale.scala"
|
||||||
if (!isFileEmpty(file)) {
|
if (!isFileEmpty(file)) {
|
||||||
translatedLocales = translatedLocales + locale
|
translatedLocales = translatedLocales + locale
|
||||||
if (file.lastModified > compileToFile.lastModified) {
|
if (file.lastModified > compileToFile.lastModified) {
|
||||||
printToFile(compileToFile)(render(db, locale, file))
|
printToFile(compileToFile)(render(db, locale, file))
|
||||||
}
|
}
|
||||||
Some(compileToFile)
|
Some(compileToFile)
|
||||||
}
|
} else None
|
||||||
else None
|
|
||||||
}
|
}
|
||||||
} yield compilable
|
} yield compilable
|
||||||
writeRegistry(db, compileTo, translatedLocales) :: res
|
writeRegistry(db, compileTo, translatedLocales) :: res
|
||||||
|
@ -77,25 +78,28 @@ private[i18n] object Registry {
|
||||||
}
|
}
|
||||||
|
|
||||||
private def render(db: String, locale: String, file: File): String = {
|
private def render(db: String, locale: String, file: File): String = {
|
||||||
val xml = try {
|
val xml =
|
||||||
XML.loadFile(file)
|
try {
|
||||||
}
|
XML.loadFile(file)
|
||||||
catch {
|
} catch {
|
||||||
case e: Exception => println(file); throw e;
|
case e: Exception => println(file); throw e;
|
||||||
}
|
}
|
||||||
def quote(msg: String) = s"""""\"$msg""\""""
|
def quote(msg: String) = s"""""\"$msg""\""""
|
||||||
val content = xml.child.collect {
|
val content = xml.child.collect {
|
||||||
case e if e.label == "string" =>
|
case e if e.label == "string" =>
|
||||||
val safe = escape(e.text)
|
val safe = escape(e.text)
|
||||||
val translation = escapeHtmlOption(safe) match {
|
val translation = escapeHtmlOption(safe) match {
|
||||||
case None => s"""new Simple(\"\"\"$safe\"\"\")"""
|
case None => s"""new Simple(\"\"\"$safe\"\"\")"""
|
||||||
case Some(escaped) => s"""new Escaped(\"\"\"$safe\"\"\",\"\"\"$escaped\"\"\")"""
|
case Some(escaped) => s"""new Escaped(\"\"\"$safe\"\"\",\"\"\"$escaped\"\"\")"""
|
||||||
}
|
}
|
||||||
s"""m.put(${toKey(e)},$translation)"""
|
s"""m.put(${toKey(e)},$translation)"""
|
||||||
case e if e.label == "plurals" =>
|
case e if e.label == "plurals" =>
|
||||||
val items: Map[String, String] = e.child.filter(_.label == "item").map { i =>
|
val items: Map[String, String] = e.child
|
||||||
ucfirst(i.\("@quantity").toString) -> s"""\"\"\"${escape(i.text)}\"\"\""""
|
.filter(_.label == "item")
|
||||||
}.toMap
|
.map { i =>
|
||||||
|
ucfirst(i.\("@quantity").toString) -> s"""\"\"\"${escape(i.text)}\"\"\""""
|
||||||
|
}
|
||||||
|
.toMap
|
||||||
s"""m.put(${toKey(e)},new Plurals(${pluralMap(items)}))"""
|
s"""m.put(${toKey(e)},new Plurals(${pluralMap(items)}))"""
|
||||||
}
|
}
|
||||||
s"""package lila.i18n
|
s"""package lila.i18n
|
||||||
|
@ -116,15 +120,14 @@ ${content mkString "\n"}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def pluralMap(items: Map[String, String]): String =
|
private def pluralMap(items: Map[String, String]): String =
|
||||||
if (items.size > 4) s"""Map(${items.map { case (k, v) => s"$k->$v" } mkString ","})"""
|
if (items.size > 4) s"""Map(${items.map { case (k, v) => s"$k->$v" } mkString ","})"""
|
||||||
else s"""new Map.Map${items.size}(${items.map { case (k, v) => s"$k,$v" } mkString ","})"""
|
else s"""new Map.Map${items.size}(${items.map { case (k, v) => s"$k,$v" } mkString ","})"""
|
||||||
|
|
||||||
|
|
||||||
private val badChars = """[<>&"'\r\n]""".r.pattern
|
private val badChars = """[<>&"'\r\n]""".r.pattern
|
||||||
private def escapeHtmlOption(s: String): Option[String] =
|
private def escapeHtmlOption(s: String): Option[String] =
|
||||||
if (badChars.matcher(s).find) Some {
|
if (badChars.matcher(s).find) Some {
|
||||||
val sb = new java.lang.StringBuilder(s.size + 10) // wet finger style
|
val sb = new java.lang.StringBuilder(s.size + 10) // wet finger style
|
||||||
var i = 0
|
var i = 0
|
||||||
while (i < s.length) {
|
while (i < s.length) {
|
||||||
s.charAt(i) match {
|
s.charAt(i) match {
|
||||||
case '<' => sb append "<"
|
case '<' => sb append "<"
|
||||||
|
@ -143,6 +146,10 @@ ${content mkString "\n"}
|
||||||
|
|
||||||
private def printToFile(f: File)(content: String): Unit = {
|
private def printToFile(f: File)(content: String): Unit = {
|
||||||
val p = new java.io.PrintWriter(f, "UTF-8")
|
val p = new java.io.PrintWriter(f, "UTF-8")
|
||||||
try { content.foreach(p.print) } finally { p.close() }
|
try {
|
||||||
|
content.foreach(p.print)
|
||||||
|
} finally {
|
||||||
|
p.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,19 @@ import play.routes.compiler.RoutesCompiler.RoutesCompilerTask
|
||||||
object LilaRoutesGenerator extends RoutesGenerator {
|
object LilaRoutesGenerator extends RoutesGenerator {
|
||||||
|
|
||||||
val ForwardsRoutesFile = "Routes.scala"
|
val ForwardsRoutesFile = "Routes.scala"
|
||||||
val ReverseRoutesFile = "ReverseRoutes.scala"
|
val ReverseRoutesFile = "ReverseRoutes.scala"
|
||||||
val RoutesPrefixFile = "RoutesPrefix.scala"
|
val RoutesPrefixFile = "RoutesPrefix.scala"
|
||||||
val JavaWrapperFile = "routes.java"
|
val JavaWrapperFile = "routes.java"
|
||||||
|
|
||||||
val id = "lila"
|
val id = "lila"
|
||||||
|
|
||||||
import InjectedRoutesGenerator.Dependency
|
import InjectedRoutesGenerator.Dependency
|
||||||
|
|
||||||
def generate(task: RoutesCompilerTask, namespace: Option[String], rules: List[Rule]): Seq[(String, String)] = {
|
def generate(
|
||||||
|
task: RoutesCompilerTask,
|
||||||
|
namespace: Option[String],
|
||||||
|
rules: List[Rule]
|
||||||
|
): Seq[(String, String)] = {
|
||||||
val folder = namespace.map(_.replace('.', '/') + "/").getOrElse("") + "/"
|
val folder = namespace.map(_.replace('.', '/') + "/").getOrElse("") + "/"
|
||||||
|
|
||||||
val sourceInfo =
|
val sourceInfo =
|
||||||
|
@ -25,16 +29,20 @@ object LilaRoutesGenerator extends RoutesGenerator {
|
||||||
|
|
||||||
val forwardsRoutesFiles = if (task.forwardsRouter) {
|
val forwardsRoutesFiles = if (task.forwardsRouter) {
|
||||||
Seq(folder + ForwardsRoutesFile -> generateRouter(sourceInfo, namespace, task.additionalImports, rules))
|
Seq(folder + ForwardsRoutesFile -> generateRouter(sourceInfo, namespace, task.additionalImports, rules))
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Nil
|
Nil
|
||||||
}
|
}
|
||||||
|
|
||||||
val reverseRoutesFiles = if (task.reverseRouter) {
|
val reverseRoutesFiles = if (task.reverseRouter) {
|
||||||
generateReverseRouters(sourceInfo, namespace, task.additionalImports, routes, task.namespaceReverseRouter) ++
|
generateReverseRouters(
|
||||||
|
sourceInfo,
|
||||||
|
namespace,
|
||||||
|
task.additionalImports,
|
||||||
|
routes,
|
||||||
|
task.namespaceReverseRouter
|
||||||
|
) ++
|
||||||
generateJavaWrappers(sourceInfo, namespace, rules, task.namespaceReverseRouter)
|
generateJavaWrappers(sourceInfo, namespace, rules, task.namespaceReverseRouter)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Nil
|
Nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,16 +50,16 @@ object LilaRoutesGenerator extends RoutesGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private def generateRouter(
|
private def generateRouter(
|
||||||
sourceInfo: RoutesSourceInfo,
|
sourceInfo: RoutesSourceInfo,
|
||||||
namespace: Option[String],
|
namespace: Option[String],
|
||||||
additionalImports: Seq[String],
|
additionalImports: Seq[String],
|
||||||
rules: List[Rule]
|
rules: List[Rule]
|
||||||
) = {
|
) = {
|
||||||
@annotation.tailrec
|
@annotation.tailrec
|
||||||
def prepare(
|
def prepare(
|
||||||
rules: List[Rule],
|
rules: List[Rule],
|
||||||
includes: Seq[Include],
|
includes: Seq[Include],
|
||||||
routes: Seq[Route]
|
routes: Seq[Route]
|
||||||
): (Seq[Include], Seq[Route]) = rules match {
|
): (Seq[Include], Seq[Route]) = rules match {
|
||||||
case (inc: Include) :: rs =>
|
case (inc: Include) :: rs =>
|
||||||
prepare(rs, inc +: includes, routes)
|
prepare(rs, inc +: includes, routes)
|
||||||
|
@ -89,7 +97,7 @@ object LilaRoutesGenerator extends RoutesGenerator {
|
||||||
routes.headOption.map { route =>
|
routes.headOption.map { route =>
|
||||||
val clazz = packageName.map(_ + ".").getOrElse("") + controller
|
val clazz = packageName.map(_ + ".").getOrElse("") + controller
|
||||||
// If it's using the @ syntax, we depend on the provider (ie, look it up each time)
|
// If it's using the @ syntax, we depend on the provider (ie, look it up each time)
|
||||||
val dep = if (instantiate) s"javax.inject.Provider[$clazz]" else clazz
|
val dep = if (instantiate) s"javax.inject.Provider[$clazz]" else clazz
|
||||||
val ident = controller + "_" + index
|
val ident = controller + "_" + index
|
||||||
|
|
||||||
key -> Dependency(ident, dep, route)
|
key -> Dependency(ident, dep, route)
|
||||||
|
@ -135,11 +143,11 @@ object LilaRoutesGenerator extends RoutesGenerator {
|
||||||
.body
|
.body
|
||||||
|
|
||||||
private def generateReverseRouters(
|
private def generateReverseRouters(
|
||||||
sourceInfo: RoutesSourceInfo,
|
sourceInfo: RoutesSourceInfo,
|
||||||
namespace: Option[String],
|
namespace: Option[String],
|
||||||
additionalImports: Seq[String],
|
additionalImports: Seq[String],
|
||||||
routes: List[Route],
|
routes: List[Route],
|
||||||
namespaceReverseRouter: Boolean
|
namespaceReverseRouter: Boolean
|
||||||
) = {
|
) = {
|
||||||
routes.groupBy(_.call.packageName).map {
|
routes.groupBy(_.call.packageName).map {
|
||||||
case (pn, routes) =>
|
case (pn, routes) =>
|
||||||
|
@ -149,24 +157,24 @@ object LilaRoutesGenerator extends RoutesGenerator {
|
||||||
.orElse(pn.orElse(namespace))
|
.orElse(pn.orElse(namespace))
|
||||||
(packageName.map(_.replace(".", "/") + "/").getOrElse("") + ReverseRoutesFile) ->
|
(packageName.map(_.replace(".", "/") + "/").getOrElse("") + ReverseRoutesFile) ->
|
||||||
static.twirl
|
static.twirl
|
||||||
.reverseRouter(
|
.reverseRouter(
|
||||||
sourceInfo,
|
sourceInfo,
|
||||||
namespace,
|
namespace,
|
||||||
additionalImports,
|
additionalImports,
|
||||||
packageName,
|
packageName,
|
||||||
routes,
|
routes,
|
||||||
namespaceReverseRouter,
|
namespaceReverseRouter,
|
||||||
_ => true
|
_ => true
|
||||||
)
|
)
|
||||||
.body
|
.body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def generateJavaWrappers(
|
private def generateJavaWrappers(
|
||||||
sourceInfo: RoutesSourceInfo,
|
sourceInfo: RoutesSourceInfo,
|
||||||
namespace: Option[String],
|
namespace: Option[String],
|
||||||
rules: List[Rule],
|
rules: List[Rule],
|
||||||
namespaceReverseRouter: Boolean
|
namespaceReverseRouter: Boolean
|
||||||
): Iterable[(String, String)] =
|
): Iterable[(String, String)] =
|
||||||
rules.collect { case r: Route => r }.groupBy(_.call.packageName).map {
|
rules.collect { case r: Route => r }.groupBy(_.call.packageName).map {
|
||||||
case (pn, routes) =>
|
case (pn, routes) =>
|
||||||
|
@ -177,7 +185,7 @@ object LilaRoutesGenerator extends RoutesGenerator {
|
||||||
val controllers = routes.groupBy(_.call.controller).keys.toSeq
|
val controllers = routes.groupBy(_.call.controller).keys.toSeq
|
||||||
(packageName.map(_.replace(".", "/") + "/").getOrElse("") + JavaWrapperFile) -> {
|
(packageName.map(_.replace(".", "/") + "/").getOrElse("") + JavaWrapperFile) -> {
|
||||||
val pack = packageName getOrElse "controllers"
|
val pack = packageName getOrElse "controllers"
|
||||||
val ns = namespace getOrElse "routes"
|
val ns = namespace getOrElse "routes"
|
||||||
s"""package $pack;
|
s"""package $pack;
|
||||||
|
|
||||||
import $ns.RoutesPrefix;
|
import $ns.RoutesPrefix;
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.0")
|
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.0")
|
||||||
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3")
|
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.0")
|
||||||
|
|
Loading…
Reference in New Issue