Skip to content

Commit

Permalink
hack to detect if sbt if logging or if it's a user println
Browse files Browse the repository at this point in the history
  • Loading branch information
MasseGuillaume committed Feb 24, 2017
1 parent 234175a commit 142eec8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 35 deletions.
10 changes: 1 addition & 9 deletions sbt-api/src/main/scala/sbtapi/SbtApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,4 @@ case class Problem(severity: Severity, line: Option[Int], message: String)
// TODO: range pos ?
case class RuntimeError(message: String, line: Option[Int], fullStack: String)

sealed trait SbtLogLevel
object SbtLogLevel {
case object Debug extends SbtLogLevel
case object Info extends SbtLogLevel
case object Warn extends SbtLogLevel
case object Error extends SbtLogLevel
}

case class SbtOutput(line: String, level: Option[SbtLogLevel])
case class SbtOutput(line: String)
25 changes: 10 additions & 15 deletions sbt-runner/src/main/scala/com.olegych.scastie.sbt/SbtActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,35 +212,30 @@ class SbtActor(runTimeout: FiniteDuration, production: Boolean) extends Actor {
val runtimeError = extractRuntimeError(line, lineOffset)
val sbtOutput = extract[sbtapi.SbtOutput](line)

// sbt plugin is not loaded at this stage. we need to drop those messages
val initializationMessages = List(
"[info] Loading global plugins from",
"[info] Loading project definition from",
"[info] Set current project to scastie",
"[info] Updating {file:"
// look like our sbt logger is not catching all messages
val sbtMessages = List(
"[info]",
"[success]",
"[error]",
"[warn]"
)
// "[info] Resolving",
// "[info] Done updating.",
// "[info] Compiling",
// "[success] Total time",
// "[info] Running Main"
// )

val isSbtMessage = sbtMessages.exists(message => line.startsWith(message))

val userOutput =
if (problems.isEmpty
&& instrumentations.isEmpty
&& runtimeError.isEmpty
&& !done
&& !initializationMessages.exists(
message => line.startsWith(message))
&& !isSbtMessage
&& sbtOutput.isEmpty)
Some(line)
else None

val progress = PasteProgress(
id = id,
userOutput = userOutput,
sbtOutput = sbtOutput.map(_.line),
sbtOutput = if(isSbtMessage) Some(line) else sbtOutput.map(_.line),
compilationInfos = problems.getOrElse(Nil),
instrumentations = instrumentations.getOrElse(Nil),
runtimeError = runtimeError,
Expand Down
1 change: 0 additions & 1 deletion sbt-runner/src/test/scala/SbtActorTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class SbtActorTest()

test("Encoding issues #100"){
run("""println("€")"""){progress =>
println(progress)
val gotHelloMessage = progress.userOutput == Some("")
if (!gotHelloMessage) assert(progress.userOutput == None)
gotHelloMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import upickle.default.{write => uwrite}
object RuntimeErrorLogger {
private object NoOp {
def apply(): NoOp = {
def out(in: String): Unit = println(uwrite(SbtOutput(in.trim, None)))
def out(in: String): Unit = println(uwrite(SbtOutput(in.trim)))

new NoOp(new OutputStream {
override def close(): Unit = ()
Expand All @@ -28,15 +28,7 @@ object RuntimeErrorLogger {
extraLoggers := {
val clientLogger = FullLogger {
new Logger {
def log(level: Level.Value, message: => String): Unit = {
val apiLevel = level match {
case Level.Debug => SbtLogLevel.Debug
case Level.Info => SbtLogLevel.Info
case Level.Warn => SbtLogLevel.Warn
case Level.Error => SbtLogLevel.Error
}
println(uwrite(SbtOutput(message, Some(apiLevel))))
}
def log(level: Level.Value, message: => String): Unit = ()

def success(message: => String): Unit = () // << this is never called

Expand Down

0 comments on commit 142eec8

Please sign in to comment.