Skip to content

Commit

Permalink
Update to sbt 1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ochrons committed Apr 29, 2018
1 parent 61d4719 commit 7c57ba6
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 81 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
language: scala
scala:
- 2.12.4
- 2.12.5
sudo: false
jdk:
- oraclejdk8
script:
- sbt ++$TRAVIS_SCALA_VERSION router/test compilerServer/test
- sbt ++2.11.12 compilerServer/test
# Tricks to avoid unnecessary cache updates, from
# http://www.scala-sbt.org/0.13/docs/Travis-CI-with-sbt.html
- find $HOME/.sbt -name "*.lock" | xargs rm
Expand Down
67 changes: 36 additions & 31 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ import sbt._
import Keys._
import Settings._

scalafmtOnCompile in ThisBuild := true
scalafmtVersion in ThisBuild := "1.3.0"
ThisBuild / scalafmtOnCompile := true

val commonSettings = Seq(
scalacOptions := scalacArgs,
scalaVersion := "2.12.4",
scalaVersion := "2.12.5",
version := versions.fiddle,
libraryDependencies ++= Seq(
)
libraryDependencies ++= Seq()
)

val crossVersions = crossScalaVersions := Seq("2.12.5", "2.11.12")

lazy val root = project
.in(file("."))
.aggregate(page, compilerServer, runtime, client, router)
.aggregate(shared, page, compilerServer, runtime, client, router)

lazy val shared = project
.enablePlugins(ScalaJSPlugin)
.settings(commonSettings)
.settings(
crossVersions
)

lazy val client = project
.enablePlugins(ScalaJSPlugin)
Expand All @@ -30,17 +33,18 @@ lazy val client = project
"org.scala-js" %%% "scalajs-dom" % versions.dom,
"com.github.marklister" %%% "base64" % versions.base64
),
//scalaJSLinkerConfig in (Compile, fullOptJS) ~= { _.withClosureCompilerIfAvailable(false) },
//Compile / fullOptJS / scalaJSLinkerConfig ~= { _.withClosureCompilerIfAvailable(false) },
// rename output always to -opt.js
artifactPath in (Compile, fastOptJS) := ((crossTarget in (Compile, fastOptJS)).value /
((moduleName in fastOptJS).value + "-opt.js")),
Compile / fastOptJS / artifactPath := ((Compile / fastOptJS / crossTarget).value /
((fastOptJS / moduleName).value + "-opt.js")),
relativeSourceMaps := true
)

lazy val page = project
.enablePlugins(ScalaJSPlugin)
.settings(commonSettings)
.settings(
crossVersions,
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % versions.dom,
"com.lihaoyi" %%% "scalatags" % versions.scalatags
Expand All @@ -65,7 +69,7 @@ lazy val compilerServer = project
.settings(Revolver.settings: _*)
.settings(
name := "scalafiddle-core",
crossScalaVersions := Seq("2.11.12", "2.12.4"),
crossVersions,
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scala-js" % "scalajs-compiler" % scalaJSVersion cross CrossVersion.full,
Expand All @@ -81,17 +85,17 @@ lazy val compilerServer = project
"org.xerial.snappy" % "snappy-java" % "1.1.2.6",
"org.xerial.larray" %% "larray" % "0.4.0"
) ++ kamon ++ akka ++ logging,
(resources in Compile) ++= {
(managedClasspath in (runtime, Compile)).value.map(_.data) ++ Seq(
(packageBin in (page, Compile)).value
(Compile / resources) ++= {
(runtime / Compile / managedClasspath).value.map(_.data) ++ Seq(
(page / Compile / packageBin).value
)
},
resolvers += "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/",
javaOptions in reStart ++= Seq("-Xmx3g", "-Xss4m"),
javaOptions in Universal ++= Seq("-J-Xss4m"),
resourceGenerators in Compile += Def.task {
// store build version in a property file
val file = (resourceManaged in Compile).value / "version.properties"
reStart / javaOptions ++= Seq("-Xmx3g", "-Xss4m"),
Universal / javaOptions ++= Seq("-J-Xss4m"),
Compile / resourceGenerators += Def.task {
// store build a / version property file
val file = (Compile / resourceManaged).value / "version.properties"
val contents =
s"""
|version=${version.value}
Expand All @@ -103,7 +107,7 @@ lazy val compilerServer = project
Seq(file)
}.taskValue,
scriptClasspath := Seq("../config/") ++ scriptClasspath.value,
dockerfile in docker := {
docker / dockerfile := {
val appDir: File = stage.value
val targetDir = "/app"

Expand All @@ -114,7 +118,7 @@ lazy val compilerServer = project
copy(appDir, targetDir)
}
},
imageNames in docker := Seq(
docker / imageNames := Seq(
ImageName(
namespace = Some("scalafiddle"),
repository = s"scalafiddle-core-${scalaBinaryVersion.value}",
Expand All @@ -128,7 +132,8 @@ lazy val compilerServer = project
)
)

lazy val router = (project in file("router"))
lazy val router = project
.in(file("router"))
.enablePlugins(JavaAppPackaging)
.enablePlugins(sbtdocker.DockerPlugin)
.dependsOn(shared)
Expand All @@ -144,13 +149,13 @@ lazy val router = (project in file("router"))
"org.webjars.npm" % "js-sha1" % "0.4.0",
"com.lihaoyi" %% "upickle" % versions.upickle,
"com.github.marklister" %% "base64" % versions.base64,
"ch.megard" %% "akka-http-cors" % "0.2.1"
"ch.megard" %% "akka-http-cors" % "0.3.0"
) ++ kamon ++ akka ++ logging,
javaOptions in reStart ++= Seq("-Xmx1g"),
reStart / javaOptions ++= Seq("-Xmx1g"),
scriptClasspath := Seq("../config/") ++ scriptClasspath.value,
resourceGenerators in Compile += Def.task {
// store build version in a property file
val file = (resourceManaged in Compile).value / "version.properties"
Compile / resourceGenerators += Def.task {
// store build a / version property file
val file = (Compile / resourceManaged).value / "version.properties"
val contents =
s"""
|version=${version.value}
Expand All @@ -161,11 +166,11 @@ lazy val router = (project in file("router"))
IO.write(file, contents)
Seq(file)
}.taskValue,
(resources in Compile) ++= {
// Seq((fullOptJS in (client, Compile)).value.data)
Seq((fastOptJS in (client, Compile)).value.data)
(Compile / resources) ++= {
// Seq((client / Compile / fullOptJS).value.data)
Seq((client / Compile / fastOptJS).value.data)
},
dockerfile in docker := {
docker / dockerfile := {
val appDir: File = stage.value
val targetDir = "/app"

Expand All @@ -177,7 +182,7 @@ lazy val router = (project in file("router"))
expose(8880)
}
},
imageNames in docker := Seq(
docker / imageNames := Seq(
ImageName(
namespace = Some("scalafiddle"),
repository = "scalafiddle-router",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ object GlobalInitCompat {
}
}

def initInteractiveGlobal(settings: Settings, reporter: StoreReporter, libs: Seq[io.AbstractFile]): nsc.interactive.Global = {
def initInteractiveGlobal(settings: Settings,
reporter: StoreReporter,
libs: Seq[io.AbstractFile]): nsc.interactive.Global = {
val jCtx = new JavaContext()
new nsc.interactive.Global(settings, reporter) with InMemoryGlobal { g =>
def ctx = jCtx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,23 @@ object GlobalInitCompat {
file.lookupName(pathParts.last, directory = directory)
}

private def buildClassPath(absFile: AbstractFile) = new VirtualDirectoryClassPath(new VirtualDirectory(absFile.name, None){
override def iterator = absFile.iterator
private def buildClassPath(absFile: AbstractFile) =
new VirtualDirectoryClassPath(new VirtualDirectory(absFile.name, None) {
override def iterator = absFile.iterator

override def lookupName(name: String, directory: Boolean) = absFile.lookupName(name, directory)
override def lookupName(name: String, directory: Boolean) = absFile.lookupName(name, directory)

override def subdirectoryNamed(name: String) = absFile.subdirectoryNamed(name)
}) {
override def getSubDir(packageDirName: String): Option[AbstractFile] = {
Option(lookupPath(absFile)(packageDirName.split('/'), directory = true))
}
override def subdirectoryNamed(name: String) = absFile.subdirectoryNamed(name)
}) {
override def getSubDir(packageDirName: String): Option[AbstractFile] = {
Option(lookupPath(absFile)(packageDirName.split('/'), directory = true))
}

override def findClassFile(className: String): Option[AbstractFile] = {
val relativePath = FileUtils.dirPath(className) + ".class"
Option(lookupPath(absFile)(relativePath.split('/'), directory = false))
override def findClassFile(className: String): Option[AbstractFile] = {
val relativePath = FileUtils.dirPath(className) + ".class"
Option(lookupPath(absFile)(relativePath.split('/'), directory = false))
}
}
}

def initGlobal(settings: Settings, reporter: StoreReporter, libs: Seq[io.AbstractFile]): nsc.Global = {
val cp = new AggregateClassPath(libs.map(buildClassPath))
Expand All @@ -96,7 +97,7 @@ object GlobalInitCompat {
override lazy val plugins = List[Plugin](
new org.scalajs.core.compiler.ScalaJSPlugin(this),
new org.scalamacros.paradise.Plugin(this),
new d_m.KindProjector(this)
new d_m.KindProjector(this)
)

override lazy val platform: ThisPlatform = new GlobalPlatform {
Expand All @@ -123,7 +124,7 @@ object GlobalInitCompat {
override lazy val plugins = List[Plugin](
new org.scalajs.core.compiler.ScalaJSPlugin(this),
new org.scalamacros.paradise.Plugin(this),
new d_m.KindProjector(this)
new d_m.KindProjector(this)
)

override lazy val platform: ThisPlatform = new GlobalPlatform {
Expand Down
45 changes: 33 additions & 12 deletions page/src/main/scala/fiddle/Fiddle.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package fiddle

import org.scalajs.dom
import org.scalajs.dom.html
import org.scalajs.dom.{CanvasRenderingContext2D, html}
import org.scalajs.dom.html.{Canvas, Div}

import scala.concurrent.{Future, Promise}
import scala.scalajs.js
import scala.scalajs.js.annotation.JSExportTopLevel
import scala.util.Try
import scalatags.JsDom.all._

import scala.scalajs.js.timers.{SetIntervalHandle, SetTimeoutHandle}

/**
* API for things that belong to the page, and are useful to both the fiddle
* client, user code as well as exported read-only pages.
Expand All @@ -28,14 +31,14 @@ object Fiddle {
* Gets the element from the given ID and casts it,
* shortening that common pattern
*/
def getElem[T](id: String) = dom.document.getElementById(id).asInstanceOf[T]
private def getElem[T](id: String): T = dom.document.getElementById(id).asInstanceOf[T]

val sandbox = getElem[html.Div]("container")
val canvas = getElem[html.Canvas]("canvas")
val draw = canvas.getContext("2d").asInstanceOf[dom.CanvasRenderingContext2D]
val panel = getElem[html.Div]("output")
val sandbox: Div = getElem[html.Div]("container")
val canvas: Canvas = getElem[html.Canvas]("canvas")
val draw: CanvasRenderingContext2D = canvas.getContext("2d").asInstanceOf[dom.CanvasRenderingContext2D]
val panel: Div = getElem[html.Div]("output")

def println(ss: Any) = {
def println(ss: Any): Unit = {
ss match {
case null =>
print(div(cls := "monospace", "null"))
Expand All @@ -46,16 +49,16 @@ object Fiddle {
}
}

def printDiv(ss: Modifier*) = {
def printDiv(ss: Modifier*): Unit = {
print(div(ss))
}

def print(ss: Modifier*) = {
def print(ss: Modifier*): Unit = {
ss.foreach(_.applyTo(panel))
panel.scrollTop = panel.scrollHeight - panel.clientHeight
}

def clear() = {
def clear(): Unit = {
// clear panel and canvas
panel.innerHTML = ""
canvas.height = sandbox.clientHeight
Expand All @@ -73,13 +76,31 @@ object Fiddle {
p.future
}

def scheduleOnce(delay: Int)(f: => Unit) = {
def scheduleOnce(delay: Int)(f: => Unit): SetTimeoutHandle = {
val handle = js.timers.setTimeout(delay)(f)
handle
}

def schedule(interval: Int)(f: => Unit) = {
def schedule(interval: Int)(f: => Unit): SetIntervalHandle = {
val handle = js.timers.setInterval(interval)(f)
handle
}

def loadJS(url: String): Future[Unit] = {
val script = dom.document.createElement("script").asInstanceOf[html.Script]
script.`type` = "text/javascript"
script.src = url
val p = Promise[Unit]
script.onload = (e: dom.Event) => p.success(())
dom.document.body.appendChild(script)
p.future
}

def loadCSS(url: String): Unit = {
val link = dom.document.createElement("link").asInstanceOf[html.Link]
link.rel = "stylesheet"
link.href = url
dom.document.head.appendChild(link)
}

}
14 changes: 7 additions & 7 deletions project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ object Settings {

/** Declare global dependency versions here to avoid mismatches in multi part dependencies */
object versions {
val fiddle = "1.2.5"
val fiddle = "1.2.7"
val scalatest = "3.0.3"
val macroParadise = "2.1.0"
val kindProjector = "0.9.5"
val akka = "2.5.7"
val akkaHttp = "10.0.11"
val kindProjector = "0.9.6"
val akka = "2.5.12"
val akkaHttp = "10.1.1"
val upickle = "0.4.4"
val ace = "1.2.2"
val dom = "0.9.4"
val dom = "0.9.5"
val scalatags = "0.6.7"
val async = "0.9.7"
val coursier = "1.0.2"
val coursier = "1.0.3"
val kamon = "0.6.7"
val base64 = "0.2.4"
}
Expand All @@ -45,7 +45,7 @@ object Settings {
)

val logging = Seq(
"net.logstash.logback" % "logstash-logback-encoder" % "4.11",
"net.logstash.logback" % "logstash-logback-encoder" % "5.0",
"ch.qos.logback" % "logback-classic" % "1.2.3"
)
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.16
sbt.version=1.1.4
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.2")

addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.4.1")

addSbtPlugin("io.spray" % "sbt-revolver" % "0.8.0")
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.0")

addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.14")
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1")

addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.3")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.4")
Loading

0 comments on commit 7c57ba6

Please sign in to comment.