Start system implementation
This commit is contained in:
parent
82cca24a52
commit
af5ddb516c
|
@ -8,6 +8,7 @@ trait Resolvers {
|
||||||
val iliaz = "iliaz.com" at "http://scala.iliaz.com/"
|
val iliaz = "iliaz.com" at "http://scala.iliaz.com/"
|
||||||
val sonatype = "sonatype" at "http://oss.sonatype.org/content/repositories/releases"
|
val sonatype = "sonatype" at "http://oss.sonatype.org/content/repositories/releases"
|
||||||
val sonatypeS = "sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots"
|
val sonatypeS = "sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots"
|
||||||
|
val novusS = "repo.novus snaps" at "http://repo.novus.com/snapshots/"
|
||||||
}
|
}
|
||||||
|
|
||||||
trait Dependencies {
|
trait Dependencies {
|
||||||
|
@ -22,6 +23,7 @@ trait Dependencies {
|
||||||
val gson = "com.google.code.gson" % "gson" % "1.7.1"
|
val gson = "com.google.code.gson" % "gson" % "1.7.1"
|
||||||
val scalalib = "com.github.ornicar" %% "scalalib" % "1.15"
|
val scalalib = "com.github.ornicar" %% "scalalib" % "1.15"
|
||||||
val hasher = "com.roundeights" % "hasher" % "0.3" from "http://cloud.github.com/downloads/Nycto/Hasher/hasher_2.9.1-0.3.jar"
|
val hasher = "com.roundeights" % "hasher" % "0.3" from "http://cloud.github.com/downloads/Nycto/Hasher/hasher_2.9.1-0.3.jar"
|
||||||
|
val config = "com.typesafe.config" % "config" % "0.2.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
object ApplicationBuild extends Build with Resolvers with Dependencies {
|
object ApplicationBuild extends Build with Resolvers with Dependencies {
|
||||||
|
@ -30,7 +32,7 @@ object ApplicationBuild extends Build with Resolvers with Dependencies {
|
||||||
organization := "com.github.ornicar",
|
organization := "com.github.ornicar",
|
||||||
version := "0.1",
|
version := "0.1",
|
||||||
scalaVersion := "2.9.1",
|
scalaVersion := "2.9.1",
|
||||||
resolvers := Seq(iliaz, codahale, sonatype),
|
resolvers := Seq(iliaz, codahale, sonatype, novusS, typesafe),
|
||||||
libraryDependencies in test := Seq(specs2),
|
libraryDependencies in test := Seq(specs2),
|
||||||
shellPrompt := {
|
shellPrompt := {
|
||||||
(state: State) ⇒ "%s> ".format(Project.extract(state).currentProject.id)
|
(state: State) ⇒ "%s> ".format(Project.extract(state).currentProject.id)
|
||||||
|
@ -43,7 +45,7 @@ object ApplicationBuild extends Build with Resolvers with Dependencies {
|
||||||
)
|
)
|
||||||
|
|
||||||
lazy val system = Project("system", file("system"), settings = buildSettings).settings(
|
lazy val system = Project("system", file("system"), settings = buildSettings).settings(
|
||||||
libraryDependencies := Seq(scalalib, scalaz, redis, json, casbah, salat)
|
libraryDependencies := Seq(scalalib, scalaz, config, redis, json, casbah, salat)
|
||||||
) dependsOn (chess)
|
) dependsOn (chess)
|
||||||
|
|
||||||
lazy val http = Project("http", file("http"), settings = buildSettings).settings(
|
lazy val http = Project("http", file("http"), settings = buildSettings).settings(
|
||||||
|
|
12
system/src/main/resources/system.conf
Normal file
12
system/src/main/resources/system.conf
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
mongo {
|
||||||
|
host = 127.0.0.1
|
||||||
|
port = 27017
|
||||||
|
dbName = lichess
|
||||||
|
collection {
|
||||||
|
game = game2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
redis {
|
||||||
|
host = localhost
|
||||||
|
port = 6379
|
||||||
|
}
|
44
system/src/main/scala/SystemEnv.scala
Normal file
44
system/src/main/scala/SystemEnv.scala
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package lila.system
|
||||||
|
|
||||||
|
import com.mongodb.casbah.MongoConnection
|
||||||
|
import com.mongodb.casbah.commons.conversions.scala._
|
||||||
|
import com.redis.RedisClient
|
||||||
|
import com.typesafe.config._
|
||||||
|
|
||||||
|
import repo._
|
||||||
|
|
||||||
|
trait SystemEnv {
|
||||||
|
|
||||||
|
val config: Config
|
||||||
|
|
||||||
|
def gameRepo = new GameRepo(
|
||||||
|
mongodb(config getString "mongo.collection.game"))
|
||||||
|
|
||||||
|
def mongodb = MongoConnection(
|
||||||
|
config getString "mongo.host",
|
||||||
|
config getInt "mongo.port"
|
||||||
|
)(config getString "mongo.dbname")
|
||||||
|
|
||||||
|
def redis = new RedisClient(
|
||||||
|
config getString "redis.host",
|
||||||
|
config getInt "redis.port")
|
||||||
|
}
|
||||||
|
|
||||||
|
trait EnvBuilder {
|
||||||
|
|
||||||
|
def apply(overrides: String = "") = new SystemEnv {
|
||||||
|
val config = makeConfig(overrides, "lila.conf", "system")
|
||||||
|
}
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
def makeConfig(sources: String*) = sources.foldLeft(ConfigFactory.defaultOverrides) {
|
||||||
|
case (config, source) if source isEmpty ⇒ config
|
||||||
|
case (config, source) if source contains '=' ⇒
|
||||||
|
config.withFallback(ConfigFactory parseString source)
|
||||||
|
case (config, source) if source contains '.' ⇒
|
||||||
|
config.withFallback(ConfigFactory parseFile (new File(source)))
|
||||||
|
case (config, source) ⇒
|
||||||
|
config.withFallback(ConfigFactory load source)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
package lila
|
package lila.system
|
||||||
package repo
|
package model
|
||||||
|
|
||||||
import com.novus.salat.annotations._
|
import com.novus.salat.annotations._
|
||||||
import com.mongodb.casbah.Imports._
|
import com.mongodb.casbah.Imports._
|
|
@ -1,5 +1,5 @@
|
||||||
package lila
|
package lila.system
|
||||||
package repo
|
package model
|
||||||
|
|
||||||
import com.novus.salat.annotations._
|
import com.novus.salat.annotations._
|
||||||
import com.mongodb.casbah.Imports._
|
import com.mongodb.casbah.Imports._
|
|
@ -1,6 +1,8 @@
|
||||||
package lila
|
package lila.system
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
|
import model._
|
||||||
|
|
||||||
import com.novus.salat._
|
import com.novus.salat._
|
||||||
import com.novus.salat.global._
|
import com.novus.salat.global._
|
||||||
import com.novus.salat.dao._
|
import com.novus.salat.dao._
|
||||||
|
@ -9,5 +11,5 @@ import com.mongodb.casbah.Imports._
|
||||||
|
|
||||||
class GameRepo(collection: MongoCollection) extends SalatDAO[Game, String](collection) {
|
class GameRepo(collection: MongoCollection) extends SalatDAO[Game, String](collection) {
|
||||||
|
|
||||||
def game(id: String) = findOneByID(id)
|
def game(id: String): Option[Game] = findOneByID(id)
|
||||||
}
|
}
|
4
system/src/test/resources/log4j.properties
Normal file
4
system/src/test/resources/log4j.properties
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
log4j.rootLogger=info, R
|
||||||
|
log4j.appender.R=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.R.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.R.layout.ConversionPattern=%-5p %-30.30c{1} %x - %m%n
|
Loading…
Reference in a new issue