From 7c57ba6f217774d5c974dd5bbc280193ce85809c Mon Sep 17 00:00:00 2001 From: Otto Chrons Date: Sun, 29 Apr 2018 16:01:48 +0300 Subject: [PATCH] Update to sbt 1.1.4 --- .travis.yml | 3 +- build.sbt | 67 ++++++++++--------- .../compiler/GlobalInitCompat.scala | 4 +- .../compiler/GlobalInitCompat.scala | 29 ++++---- page/src/main/scala/fiddle/Fiddle.scala | 45 +++++++++---- project/Settings.scala | 14 ++-- project/build.properties | 2 +- project/plugins.sbt | 6 +- router/src/main/resources/libraries.json | 23 ++++++- router/src/main/resources/reference.conf | 4 +- .../scalafiddle/router/CompilerManager.scala | 2 +- .../scala/scalafiddle/router/WebService.scala | 2 +- .../scalafiddle/router/frontend/Static.scala | 10 +-- 13 files changed, 130 insertions(+), 81 deletions(-) diff --git a/.travis.yml b/.travis.yml index b5dcb58..413b6ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/build.sbt b/build.sbt index 0c8ab2c..6e85478 100644 --- a/build.sbt +++ b/build.sbt @@ -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) @@ -30,10 +33,10 @@ 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 ) @@ -41,6 +44,7 @@ lazy val page = project .enablePlugins(ScalaJSPlugin) .settings(commonSettings) .settings( + crossVersions, libraryDependencies ++= Seq( "org.scala-js" %%% "scalajs-dom" % versions.dom, "com.lihaoyi" %%% "scalatags" % versions.scalatags @@ -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, @@ -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} @@ -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" @@ -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}", @@ -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) @@ -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} @@ -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" @@ -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", diff --git a/compiler-server/src/main/scala-2.11/scalafiddle/compiler/GlobalInitCompat.scala b/compiler-server/src/main/scala-2.11/scalafiddle/compiler/GlobalInitCompat.scala index ea2fbcc..28b3ca4 100644 --- a/compiler-server/src/main/scala-2.11/scalafiddle/compiler/GlobalInitCompat.scala +++ b/compiler-server/src/main/scala-2.11/scalafiddle/compiler/GlobalInitCompat.scala @@ -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 diff --git a/compiler-server/src/main/scala-2.12/scalafiddle/compiler/GlobalInitCompat.scala b/compiler-server/src/main/scala-2.12/scalafiddle/compiler/GlobalInitCompat.scala index 68a8811..a5c4e6c 100644 --- a/compiler-server/src/main/scala-2.12/scalafiddle/compiler/GlobalInitCompat.scala +++ b/compiler-server/src/main/scala-2.12/scalafiddle/compiler/GlobalInitCompat.scala @@ -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)) @@ -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 { @@ -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 { diff --git a/page/src/main/scala/fiddle/Fiddle.scala b/page/src/main/scala/fiddle/Fiddle.scala index 14d6418..1c9c9e7 100644 --- a/page/src/main/scala/fiddle/Fiddle.scala +++ b/page/src/main/scala/fiddle/Fiddle.scala @@ -1,7 +1,8 @@ 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 @@ -9,6 +10,8 @@ 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. @@ -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")) @@ -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 @@ -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) + } + } diff --git a/project/Settings.scala b/project/Settings.scala index e234bd7..3ffcbae 100644 --- a/project/Settings.scala +++ b/project/Settings.scala @@ -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" } @@ -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" ) } diff --git a/project/build.properties b/project/build.properties index c091b86..2305049 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.16 +sbt.version=1.1.4 \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index 302795e..112d811 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -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") diff --git a/router/src/main/resources/libraries.json b/router/src/main/resources/libraries.json index 37c75ac..37474c2 100644 --- a/router/src/main/resources/libraries.json +++ b/router/src/main/resources/libraries.json @@ -1,4 +1,22 @@ [ + { + "group": "FP", + "libraries": [ + { + "name": "Scalaz", + "organization": "org.scalaz", + "artifact": "scalaz-core", + "doc": "scalaz/scalaz", + "versions": [ + { + "version": "7.2.16", + "scalaVersions": ["2.11", "2.12"] + } + ], + "compileTimeOnly": false + } + ] + }, { "group": "Web", "libraries": [ @@ -66,7 +84,8 @@ "scalaVersions": ["2.11", "2.12"], "jsDeps": [ "d3js % 3.5.17 % https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js" - ] + ], + "example": "https://gist.githubusercontent.com/ochrons/78ebefcc978168f73b5ad8e5f2e1973e/raw/844121bf764cec1ddddff0d12ac5e9dc3fd73ee9/ScalaFiddle%2520D3%2520test" } ], "compileTimeOnly": false @@ -98,6 +117,6 @@ ], "compileTimeOnly": false } - ] + ] } ] diff --git a/router/src/main/resources/reference.conf b/router/src/main/resources/reference.conf index 1692577..1026129 100644 --- a/router/src/main/resources/reference.conf +++ b/router/src/main/resources/reference.conf @@ -51,8 +51,8 @@ fiddle { extLibsUrl = "https://raw.githubusercontent.com/scalafiddle/scalafiddle-io/master/libraries.json" extLibsUrl = ${?SCALAFIDDLE_LIBRARIES_URL} defaultLibs = """{ - "2.11": ["org.scala-js %%% scalajs-dom % 0.9.4", "com.lihaoyi %%% scalatags % 0.6.7"], - "2.12": ["org.scala-js %%% scalajs-dom % 0.9.4", "com.lihaoyi %%% scalatags % 0.6.7"] + "2.11": ["org.scala-js %%% scalajs-dom % 0.9.5", "com.lihaoyi %%% scalatags % 0.6.7"], + "2.12": ["org.scala-js %%% scalajs-dom % 0.9.5", "com.lihaoyi %%% scalatags % 0.6.7"] }""" refreshLibraries = 300s refreshLibraries = ${?SCALAFIDDLE_REFRESH_LIBRARIES} diff --git a/router/src/main/scala/scalafiddle/router/CompilerManager.scala b/router/src/main/scala/scalafiddle/router/CompilerManager.scala index 3fc68c2..8cc0c73 100644 --- a/router/src/main/scala/scalafiddle/router/CompilerManager.scala +++ b/router/src/main/scala/scalafiddle/router/CompilerManager.scala @@ -106,7 +106,7 @@ class CompilerManager extends Actor with ActorLogging { log.debug(s"Selecting compiler for Scala $scalaVersion and libs $libs") // check that all libs are supported val versionLibs = currentLibs.getOrElse(scalaVersion, Set.empty) - log.debug(s"Libraries:\n$versionLibs") + // log.debug(s"Libraries:\n$versionLibs") libs.foreach(lib => if (!versionLibs.exists(_.sameAs(lib))) throw new IllegalArgumentException(s"Library $lib is not supported")) // select the best available compiler server based on: diff --git a/router/src/main/scala/scalafiddle/router/WebService.scala b/router/src/main/scala/scalafiddle/router/WebService.scala index a91996c..05d8017 100644 --- a/router/src/main/scala/scalafiddle/router/WebService.scala +++ b/router/src/main/scala/scalafiddle/router/WebService.scala @@ -54,7 +54,7 @@ class WebService(system: ActorSystem, cache: Cache, compilerManager: ActorRef) { val log = LoggerFactory.getLogger(getClass) val corsSettings = - CorsSettings.defaultSettings.copy(allowedOrigins = HttpOriginRange(Config.corsOrigins.map(HttpOrigin(_)): _*)) + CorsSettings.defaultSettings.withAllowedOrigins(HttpOriginRange(Config.corsOrigins.map(HttpOrigin(_)): _*)) type ParamValidator = Map[String, Validator] val embedValidator: ParamValidator = Map( diff --git a/router/src/main/scala/scalafiddle/router/frontend/Static.scala b/router/src/main/scala/scalafiddle/router/frontend/Static.scala index e6d6773..fccb9fd 100644 --- a/router/src/main/scala/scalafiddle/router/frontend/Static.scala +++ b/router/src/main/scala/scalafiddle/router/frontend/Static.scala @@ -197,7 +197,7 @@ object Static { width := "100%", height := "100%", attr("frameborder") := "0", - attr("sandbox") := "allow-scripts", + attr("sandbox") := "allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox", src := s"codeframe?theme=${paramMap.getOrElse("theme", "light")}" ) ) @@ -249,11 +249,11 @@ object Static { script( `type` := "text/javascript", raw(""" - |var label = document.getElementById("output-tag"); - |var canvas = document.getElementById("canvas"); - |var panel = document.getElementById("output"); - |var container = document.getElementById("container"); |window.addEventListener('message', function (e) { + | var label = document.getElementById("output-tag"); + | var canvas = document.getElementById("canvas"); + | var panel = document.getElementById("output"); + | var container = document.getElementById("container"); | var mainWindow = e.source; | var msg = e.data; | switch(msg.cmd) {