Skip to content

Commit

Permalink
Updated to latest version of Profig and Scribe.
Browse files Browse the repository at this point in the history
Updated to latest version of Scala.js.
  • Loading branch information
darkfrog26 committed Feb 12, 2018
1 parent 2fc796b commit a7152d0
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 49 deletions.
10 changes: 3 additions & 7 deletions app/js/src/main/scala/io/youi/app/ClientApplication.scala
Expand Up @@ -8,9 +8,7 @@ import org.scalajs.dom._
import io.youi.dom._
import io.youi.net.URL
import profig.JsonUtil
import scribe.formatter.Formatter
import scribe.writer.Writer
import scribe.LogRecord

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
Expand All @@ -33,7 +31,7 @@ trait ClientApplication extends YouIApplication with ScreenManager {

if (logJavaScriptErrors) {
js.Dynamic.global.window.onerror = errorFunction
scribe.Logger.root.addHandler(ErrorTrace)
scribe.Logger.update(scribe.Logger.rootName)(_.withHandler(ErrorTrace))
}

connectivityEntries.attachAndFire { entries =>
Expand All @@ -51,10 +49,8 @@ trait ClientApplication extends YouIApplication with ScreenManager {

object ClientApplication {
lazy val logWriter: Writer = new Writer {
override def write(record: LogRecord, formatter: Formatter): Unit = {
val message = formatter.format(record)
sendLog(JavaScriptLog(message, record.level.name))
}

override def write(output: String): Unit = sendLog(JavaScriptLog(output))
}

private var instance: ClientApplication = _
Expand Down
18 changes: 12 additions & 6 deletions app/js/src/main/scala/io/youi/app/sourceMap/ErrorTrace.scala
Expand Up @@ -5,7 +5,9 @@ import io.youi.{History, _}
import io.youi.net.URL
import io.youi.stream.StreamURL
import org.scalajs.dom.{ErrorEvent, Event}
import scribe.{Level, LogHandler, LogRecord}
import scribe.handler.LogHandler
import scribe.modify.LogModifier
import scribe.{Level, LogRecord}

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
Expand Down Expand Up @@ -38,12 +40,16 @@ object ErrorTrace extends LogHandler {
toError(message, source, line, column, Some(throwable))
}

override def level: Level = Level.Error
override def modifiers: List[LogModifier] = Nil

override protected def publish(record: LogRecord): Unit = record.messageObject match {
case evt: Event if evt.`type` == "error" => ClientApplication.sendError(evt.asInstanceOf[ErrorEvent])
case t: Throwable => ClientApplication.sendError(t)
case _ => // Ignore others
override def setModifiers(modifiers: List[LogModifier]): LogHandler = this

override def log(record: LogRecord): Unit = if (record.level.value >= Level.Error.value) {
record.messageFunction() match {
case evt: Event if evt.`type` == "error" => ClientApplication.sendError(evt.asInstanceOf[ErrorEvent])
case t: Throwable => ClientApplication.sendError(t)
case _ => // Ignore others
}
}

/**
Expand Down
7 changes: 4 additions & 3 deletions app/jvm/src/main/scala/io/youi/app/ServerApplication.scala
Expand Up @@ -12,13 +12,13 @@ import io.youi.{JavaScriptError, JavaScriptLog, Priority, http}
import net.sf.uadetector.UserAgentType
import net.sf.uadetector.service.UADetectorServiceFactory
import org.powerscala.io._
import profig.{ConfigApplication, JsonUtil}
import profig.{JsonUtil, Profig}
import reactify.{Channel, Var}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._

trait ServerApplication extends YouIApplication with Server with ConfigApplication {
trait ServerApplication extends YouIApplication with Server {
private lazy val system = ActorSystem("ServerApplication")

val connected: Channel[Connection] = Channel[Connection]
Expand Down Expand Up @@ -274,7 +274,8 @@ trait ServerApplication extends YouIApplication with Server with ConfigApplicati
path
}

override protected def run(): Unit = {
def main(args: Array[String]): Unit = {
Profig.merge(args)
start()
}

Expand Down
4 changes: 2 additions & 2 deletions app/shared/src/main/scala/io/youi/app/YouIApplication.scala
Expand Up @@ -2,7 +2,7 @@ package io.youi.app

import reactify._
import io.youi.{Cache, CacheImplementation, ErrorSupport}
import profig.Config
import profig.Profig

import scala.language.experimental.macros

Expand All @@ -19,7 +19,7 @@ trait YouIApplication extends ErrorSupport with CacheImplementation {
*
* Defaults to true.
*/
protected def logJavaScriptErrors: Boolean = Config("logJavaScriptErrors").as[Option[Boolean]].getOrElse(true)
protected def logJavaScriptErrors: Boolean = Profig("logJavaScriptErrors").as[Option[Boolean]].getOrElse(true)

protected val logPath: String = "/client/log"

Expand Down
16 changes: 8 additions & 8 deletions build.sbt
Expand Up @@ -7,10 +7,10 @@ resolvers in ThisBuild += Resolver.sonatypeRepo("releases")
resolvers in ThisBuild += Resolver.sonatypeRepo("snapshots")
scalacOptions in ThisBuild ++= Seq("-unchecked", "-deprecation")

val profigVersion = "1.1.4"
val scribeVersion = "1.4.5"
val profigVersion = "2.0.1"
val scribeVersion = "2.1.0"
val powerScalaVersion = "2.0.5"
val reactifyVersion = "2.2.0"
val reactifyVersion = "2.3.0"
val hasherVersion = "1.2.1"
val canvgVersion = "1.4.0_1"
val openTypeVersion = "0.7.3"
Expand All @@ -19,15 +19,15 @@ val picaVersion = "3.0.5"
val akkaVersion = "2.5.9"
val scalaJSDOM = "0.9.4"
val httpAsyncClientVersion = "4.1.3"
val httpMimeVersion = "4.5.4"
val circeVersion = "0.8.0"
val httpMimeVersion = "4.5.5"
val circeVersion = "0.9.1"
val uaDetectorVersion = "2014.10"
val undertowVersion = "1.4.22.Final"
val closureCompilerVersion = "v20180101"
val closureCompilerVersion = "v20180204"
val jSoupVersion = "1.11.2"
val scalaXMLVersion = "1.0.6"
val scalacticVersion = "3.0.4"
val scalaTestVersion = "3.0.4"
val scalacticVersion = "3.0.5"
val scalaTestVersion = "3.0.5"
val scalaCheckVersion = "1.13.5"

lazy val root = project.in(file("."))
Expand Down
4 changes: 2 additions & 2 deletions client/src/main/scala/io/youi/client/HttpClient.scala
Expand Up @@ -27,8 +27,8 @@ import scala.concurrent.ExecutionContext.Implicits.global
*
* @param saveDirectory the directory to save response content of a non-textual type
*/
class HttpClient(saveDirectory: File = new File(System.getProperty("java.io.tmpdir")), dropNullKeys: Boolean = false) {
private lazy val printer = Printer.spaces2.copy(dropNullKeys = dropNullKeys)
class HttpClient(saveDirectory: File = new File(System.getProperty("java.io.tmpdir")), dropNullValues: Boolean = false) {
private lazy val printer = Printer.spaces2.copy(dropNullValues = dropNullValues)
private val asyncClient: CloseableHttpAsyncClient = {
val client = HttpAsyncClients.createDefault()
client.start()
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/io/youi/JavaScriptLog.scala
@@ -1,3 +1,3 @@
package io.youi

case class JavaScriptLog(message: String, level: String)
case class JavaScriptLog(message: String)
10 changes: 5 additions & 5 deletions dom/src/main/scala/io/youi/Template.scala
Expand Up @@ -4,7 +4,7 @@ import java.io.File

import io.youi.stream.{ByClass, ById, HTMLParser}
import org.scalajs.dom.Element
import profig.Config
import profig.Profig

import scala.annotation.compileTimeOnly
import scala.language.experimental.macros
Expand All @@ -23,7 +23,7 @@ object TemplateMacros {
import context.universe._

// Initialize Profig
context.eval(reify(profig.Config.initMacro(Nil)))
context.eval(reify(Profig.initMacro(Nil)))

val pathValue = path match {
case Expr(Literal(Constant(value: String))) => value
Expand All @@ -34,7 +34,7 @@ object TemplateMacros {
val pathKey = appName match {
case Expr(Literal(Constant(value: String))) => s"$value.template.path"
}
val templatePath = Config(pathKey).as[Option[String]]
val templatePath = Profig(pathKey).as[Option[String]]
val file = templatePath match {
case Some(basePath) => new File(basePath, pathValue)
case None => {
Expand Down Expand Up @@ -67,7 +67,7 @@ object TemplateMacros {
import context.universe._

// Initialize Profig
context.eval(reify(profig.Config.initMacro(Nil)))
context.eval(reify(Profig.initMacro(Nil)))

val pathValue = path match {
case Expr(Literal(Constant(value: String))) => value
Expand All @@ -78,7 +78,7 @@ object TemplateMacros {
val pathKey = appName match {
case Expr(Literal(Constant(value: String))) => s"$value.template.path"
}
val templatePath = Config(pathKey).as[Option[String]]
val templatePath = Profig(pathKey).as[Option[String]]
val file = templatePath match {
case Some(basePath) => new File(basePath, pathValue)
case None => {
Expand Down
Expand Up @@ -10,7 +10,6 @@ import io.youi.example.ui.HelloWorld
//import io.youi.example.ui.hypertext.DataTransferExample
//import io.youi.util.DebugSupport
import org.scalajs.dom._
import scribe.LogHandler

import scala.scalajs.js.annotation.JSExportTopLevel

Expand Down Expand Up @@ -69,7 +68,7 @@ object ClientExampleApplication extends ExampleApplication with ClientApplicatio
@JSExportTopLevel("application")
def main(): Unit = {
// Write the JavaScript logging messages to the server console
scribe.Logger.root.addHandler(LogHandler(writer = ClientApplication.logWriter))
scribe.Logger.update(scribe.Logger.rootName)(_.withHandler(writer = ClientApplication.logWriter))

scribe.info("Initialized!")
}
Expand Down
Expand Up @@ -12,9 +12,7 @@ object ServerExampleApplication extends ExampleApplication with ServerApplicatio
override protected def applicationBasePath = s"app/youi-example"
override protected def applicationJSBasePath = s"/app/example"

override def main(args: Array[String]): Unit = start(args)

override protected def run(): Unit = {
override def start(): Unit = {
handler.matcher(path.exact("/hello.txt")).caching(CachingManager.MaxAge(120L)).resource {
Content.string("Hello World!", ContentType.`text/plain`)
}
Expand All @@ -27,6 +25,6 @@ object ServerExampleApplication extends ExampleApplication with ServerApplicatio
handler.caching(CachingManager.LastModified()).classLoader("", (path: String) => s"content$path")
handler.caching(CachingManager.LastModified()).matcher(path.startsWith("/app")).classLoader()

super.run()
super.start()
}
}
2 changes: 1 addition & 1 deletion project/plugins.sbt
Expand Up @@ -2,7 +2,7 @@ resolvers += "Artima Maven Repository" at "http://repo.artima.com/releases"

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.21")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.22")
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.11")
4 changes: 2 additions & 2 deletions server/src/main/scala/io/youi/server/Server.scala
Expand Up @@ -5,7 +5,7 @@ import io.youi.{ErrorSupport, ItemContainer}
import io.youi.http.{HttpConnection, ProxyHandler, Status}
import io.youi.server.handler.{HttpHandler, HttpHandlerBuilder}
import io.youi.server.session.SessionStore
import profig.{Config, ConfigPath}
import profig.{Profig, ProfigPath}

import scala.annotation.tailrec

Expand Down Expand Up @@ -111,5 +111,5 @@ trait Server extends HttpHandler with ErrorSupport {
}

object Server {
def config: ConfigPath = Config("youi.server")
def config: ProfigPath = Profig("youi.server")
}
10 changes: 5 additions & 5 deletions server/src/main/scala/io/youi/server/ServerConfig.scala
Expand Up @@ -2,12 +2,12 @@ package io.youi.server

import java.io.File

import profig.Config
import profig.Profig
import reactify._

class ServerConfig(server: Server) {
object session {
private val config = Config("session").as[SessionConfig]
private val config = Profig("session").as[SessionConfig]

val name: Var[String] = Var(config.name)
val maxAge: Var[Option[Long]] = Var(config.maxAge)
Expand All @@ -21,7 +21,7 @@ class ServerConfig(server: Server) {
*
* Default is true.
*/
lazy val autoRestart: Var[Boolean] = Var(if (Config("autoRestart").exists()) Config("autoRestart").as[Boolean] else true)
lazy val autoRestart: Var[Boolean] = Var(if (Profig("autoRestart").exists()) Profig("autoRestart").as[Boolean] else true)

/**
* Listeners for the server. Support HTTP and HTTPS listeners. Use addHttpListener and addHttpsListener for easier
Expand All @@ -34,8 +34,8 @@ class ServerConfig(server: Server) {
* To easily enable HTTPS just pass "-listeners.https.enabled=true".
*/
lazy val listeners: Var[List[ServerSocketListener]] = prop(List(
Config("listeners.http").as[HttpServerListener],
Config("listeners.https").as[HttpsServerListener]
Profig("listeners.http").as[HttpServerListener],
Profig("listeners.https").as[HttpsServerListener]
))

def enabledListeners: List[ServerSocketListener] = listeners().filter(_.enabled)
Expand Down
Expand Up @@ -107,7 +107,7 @@ case class HttpHandlerBuilder(server: Server,

def restful[Request, Response](handler: Request => Response)
(implicit decoder: Decoder[Request], encoder: Encoder[Response]): HttpHandler = {
val printer = Printer.spaces2.copy(dropNullKeys = false)
val printer = Printer.spaces2.copy(dropNullValues = false)
handle { connection =>
val jsonOption: Option[Json] = connection.request.method match {
case Method.Get => {
Expand Down

0 comments on commit a7152d0

Please sign in to comment.