Skip to content

Commit

Permalink
Refactor sbt-runners to use NonBlockingProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
MasseGuillaume committed Oct 12, 2017
1 parent d100ad5 commit c9f2af7
Show file tree
Hide file tree
Showing 59 changed files with 1,914 additions and 1,280 deletions.
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ brew install openjdk sbt nodejs yarn
### Get latest Scala.js Bundler

git clone [email protected]:scalacenter/scalajs-bundler.git
git checkout master
sbt publishLocal

```
Expand Down
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ window.addEventListener('load', function() {
scastie.Embedded('.full', {
theme: 'light', // default: 'light'; ('dark' or 'light')
code: '1 + 1', // default: DOM node content
worksheetMode: true,
isWorksheetMode: true,
sbtConfig: 'libraryDependencies += "org.json4s" %% "json4s-native" % "3.5.2"',
targetType: 'jvm', // jvm, dotty, typelevel, js
scalaVersion: '2.12.3'
Expand Down
6 changes: 3 additions & 3 deletions api/src/main/scala/com.olegych.scastie.api/ApiModels.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object FormatRequest {

case class FormatRequest(
code: String,
worksheetMode: Boolean,
isWorksheetMode: Boolean,
scalaTarget: ScalaTarget
)

Expand Down Expand Up @@ -206,8 +206,8 @@ object Project {
case class Project(
organization: String,
repository: String,
logo: Option[List[String]] = None,
artifacts: List[String] = Nil
logo: Option[String],
artifacts: List[String]
)

// Keep websocket connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ sealed trait ConsoleOutput {
}

object ConsoleOutput {
case class SbtOutput(line: String) extends ConsoleOutput {
def show: String = s"sbt: $line"
case class SbtOutput(output: ProcessOutput) extends ConsoleOutput {
def show: String = s"sbt: ${output.line}"
}

case class UserOutput(line: String) extends ConsoleOutput {
def show: String = line
case class UserOutput(output: ProcessOutput) extends ConsoleOutput {
def show: String = output.line
}

case class ScastieOutput(line: String) extends ConsoleOutput {
Expand Down
14 changes: 7 additions & 7 deletions api/src/main/scala/com.olegych.scastie.api/Inputs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Inputs {
val defaultCode = """List("Hello", "World").mkString("", ", ", "!")"""

def default: Inputs = Inputs(
worksheetMode = true,
isWorksheetMode = true,
code = defaultCode,
target = ScalaTarget.Jvm.default,
libraries = Set(),
Expand All @@ -21,7 +21,7 @@ object Inputs {
| "-unchecked"
|)""".stripMargin,
sbtPluginsConfigExtra = "",
showInUserProfile = false,
isShowingInUserProfile = false,
forked = None
)

Expand All @@ -30,14 +30,14 @@ object Inputs {
}

case class Inputs(
worksheetMode: Boolean = false,
isWorksheetMode: Boolean,
code: String,
target: ScalaTarget,
libraries: Set[ScalaDependency],
librariesFromList: List[(ScalaDependency, Project)] = List(),
librariesFromList: List[(ScalaDependency, Project)],
sbtConfigExtra: String,
sbtPluginsConfigExtra: String,
showInUserProfile: Boolean = false,
isShowingInUserProfile: Boolean,
forked: Option[SnippetId] = None
) {

Expand All @@ -60,7 +60,7 @@ case class Inputs(
if (sbtConfigExtra == Inputs.default.sbtConfigExtra) "default"
else sbtConfigExtra

s"""|worksheetMode = $worksheetMode
s"""|isWorksheetMode = $isWorksheetMode
|target = $target
|libraries
|${libraries.mkString(nl)}
Expand Down Expand Up @@ -100,7 +100,7 @@ case class Inputs(
val targetConfig = target.sbtConfig

val optionalTargetDependency =
if (worksheetMode) target.runtimeDependency
if (isWorksheetMode) target.runtimeDependency
else None

val allLibraries =
Expand Down
43 changes: 43 additions & 0 deletions api/src/main/scala/com.olegych.scastie.api/ProcessOutput.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.olegych.scastie.api

import play.api.libs.json._

trait ProcessOutputType
object ProcessOutputType {
case object StdOut extends ProcessOutputType
case object StdErr extends ProcessOutputType

implicit object ProcessOutputTypeFormat extends Format[ProcessOutputType] {
def writes(processOutputType: ProcessOutputType): JsValue = {
JsString(processOutputType.toString)
}

private val values =
List(
StdOut,
StdErr
).map(v => (v.toString, v)).toMap

def reads(json: JsValue): JsResult[ProcessOutputType] = {
json match {
case JsString(tpe) => {
values.get(tpe) match {
case Some(v) => JsSuccess(v)
case _ => JsError(Seq())
}
}
case _ => JsError(Seq())
}
}
}
}

object ProcessOutput {
implicit val formatProcessOutput: OFormat[ProcessOutput] =
Json.format[ProcessOutput]
}

case class ProcessOutput(
line: String,
tpe: ProcessOutputType
)
8 changes: 7 additions & 1 deletion api/src/main/scala/com.olegych.scastie.api/SbtState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ object SbtState {
def isReady: Boolean = true
}

case object Disconnected extends SbtState {
override def toString: String = "Disconnected"
def isReady: Boolean = false
}

implicit object SbtStateFormat extends Format[SbtState] {
def writes(state: SbtState): JsValue = {
JsString(state.toString)
}

private val values =
List(
Unknown
Unknown,
Disconnected
).map(v => (v.toString, v)).toMap

def reads(json: JsValue): JsResult[SbtState] = {
Expand Down
24 changes: 12 additions & 12 deletions api/src/main/scala/com.olegych.scastie.api/SnippetProgress.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ object SnippetProgress {
runtimeError = None,
scalaJsContent = None,
scalaJsSourceMapContent = None,
done = true,
timeout = false,
sbtError = false,
forcedProgramMode = false
isDone = true,
isTimeout = false,
isSbtError = false,
isForcedProgramMode = false
)

implicit val formatSnippetProgress: OFormat[SnippetProgress] =
Expand All @@ -25,15 +25,15 @@ object SnippetProgress {

case class SnippetProgress(
snippetId: Option[SnippetId],
userOutput: Option[String],
sbtOutput: Option[String],
userOutput: Option[ProcessOutput],
sbtOutput: Option[ProcessOutput],
compilationInfos: List[Problem],
instrumentations: List[Instrumentation],
runtimeError: Option[RuntimeError],
scalaJsContent: Option[String] = None,
scalaJsSourceMapContent: Option[String] = None,
done: Boolean,
timeout: Boolean,
sbtError: Boolean = false,
forcedProgramMode: Boolean
scalaJsContent: Option[String],
scalaJsSourceMapContent: Option[String],
isDone: Boolean,
isTimeout: Boolean,
isSbtError: Boolean,
isForcedProgramMode: Boolean
)
Loading

0 comments on commit c9f2af7

Please sign in to comment.