Skip to content

Commit

Permalink
Add an optional exitCode to ExecStatusEvent so clients can use it
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Mar 8, 2018
1 parent ed5a8c1 commit 8227cef
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
21 changes: 20 additions & 1 deletion main/src/main/scala/sbt/MainLoop.scala
Expand Up @@ -155,11 +155,30 @@ object MainLoop {
state.log error errMsg
state.fail
}
def handleUnknownMainResult(x: xsbti.MainResult) = {
val clazz = if (x eq null) "" else " (class: " + x.getClass + ")"
newState.log debug s"Unknown main result: $x$clazz"
None
}
val exitCode = newState.next match {
case State.Continue => Some(0)
case State.ClearGlobalLog => Some(0)
case State.KeepLastLog => Some(0)
case ret: State.Return =>
ret.result match {
case exit: xsbti.Exit => Some(exit.code())
case _: xsbti.Continue => Some(0)
case _: xsbti.Reboot => Some(0)
case x => handleUnknownMainResult(x)
}
}
StandardMain.exchange publishEventMessage ExecStatusEvent(
"Done",
channelName,
exec.execId,
newState.remainingCommands.toVector map (_.commandLine))
newState.remainingCommands.toVector map (_.commandLine),
exitCode,
)
newState
}

Expand Down
Expand Up @@ -9,22 +9,23 @@ final class ExecStatusEvent private (
val status: String,
val channelName: Option[String],
val execId: Option[String],
val commandQueue: Vector[String]) extends sbt.protocol.EventMessage() with Serializable {

val commandQueue: Vector[String],
val exitCode: Option[Int]) extends sbt.protocol.EventMessage() with Serializable {

private def this(status: String, channelName: Option[String], execId: Option[String], commandQueue: Vector[String]) = this(status, channelName, execId, commandQueue, None)

override def equals(o: Any): Boolean = o match {
case x: ExecStatusEvent => (this.status == x.status) && (this.channelName == x.channelName) && (this.execId == x.execId) && (this.commandQueue == x.commandQueue)
case x: ExecStatusEvent => (this.status == x.status) && (this.channelName == x.channelName) && (this.execId == x.execId) && (this.commandQueue == x.commandQueue) && (this.exitCode == x.exitCode)
case _ => false
}
override def hashCode: Int = {
37 * (37 * (37 * (37 * (37 * (17 + "sbt.protocol.ExecStatusEvent".##) + status.##) + channelName.##) + execId.##) + commandQueue.##)
37 * (37 * (37 * (37 * (37 * (37 * (17 + "sbt.protocol.ExecStatusEvent".##) + status.##) + channelName.##) + execId.##) + commandQueue.##) + exitCode.##)
}
override def toString: String = {
"ExecStatusEvent(" + status + ", " + channelName + ", " + execId + ", " + commandQueue + ")"
"ExecStatusEvent(" + status + ", " + channelName + ", " + execId + ", " + commandQueue + ", " + exitCode + ")"
}
protected[this] def copy(status: String = status, channelName: Option[String] = channelName, execId: Option[String] = execId, commandQueue: Vector[String] = commandQueue): ExecStatusEvent = {
new ExecStatusEvent(status, channelName, execId, commandQueue)
protected[this] def copy(status: String = status, channelName: Option[String] = channelName, execId: Option[String] = execId, commandQueue: Vector[String] = commandQueue, exitCode: Option[Int] = exitCode): ExecStatusEvent = {
new ExecStatusEvent(status, channelName, execId, commandQueue, exitCode)
}
def withStatus(status: String): ExecStatusEvent = {
copy(status = status)
Expand All @@ -44,9 +45,17 @@ final class ExecStatusEvent private (
def withCommandQueue(commandQueue: Vector[String]): ExecStatusEvent = {
copy(commandQueue = commandQueue)
}
def withExitCode(exitCode: Option[Int]): ExecStatusEvent = {
copy(exitCode = exitCode)
}
def withExitCode(exitCode: Int): ExecStatusEvent = {
copy(exitCode = Option(exitCode))
}
}
object ExecStatusEvent {

def apply(status: String, channelName: Option[String], execId: Option[String], commandQueue: Vector[String]): ExecStatusEvent = new ExecStatusEvent(status, channelName, execId, commandQueue)
def apply(status: String, channelName: String, execId: String, commandQueue: Vector[String]): ExecStatusEvent = new ExecStatusEvent(status, Option(channelName), Option(execId), commandQueue)
def apply(status: String, channelName: Option[String], execId: Option[String], commandQueue: Vector[String], exitCode: Option[Int]): ExecStatusEvent = new ExecStatusEvent(status, channelName, execId, commandQueue, exitCode)
def apply(status: String, channelName: String, execId: String, commandQueue: Vector[String], exitCode: Int): ExecStatusEvent = new ExecStatusEvent(status, Option(channelName), Option(execId), commandQueue, Option(exitCode))
}
Expand Up @@ -15,8 +15,9 @@ implicit lazy val ExecStatusEventFormat: JsonFormat[sbt.protocol.ExecStatusEvent
val channelName = unbuilder.readField[Option[String]]("channelName")
val execId = unbuilder.readField[Option[String]]("execId")
val commandQueue = unbuilder.readField[Vector[String]]("commandQueue")
val exitCode = unbuilder.readField[Option[Int]]("exitCode")
unbuilder.endObject()
sbt.protocol.ExecStatusEvent(status, channelName, execId, commandQueue)
sbt.protocol.ExecStatusEvent(status, channelName, execId, commandQueue, exitCode)
case None =>
deserializationError("Expected JsObject but found None")
}
Expand All @@ -27,6 +28,7 @@ implicit lazy val ExecStatusEventFormat: JsonFormat[sbt.protocol.ExecStatusEvent
builder.addField("channelName", obj.channelName)
builder.addField("execId", obj.execId)
builder.addField("commandQueue", obj.commandQueue)
builder.addField("exitCode", obj.exitCode)
builder.endObject()
}
}
Expand Down
1 change: 1 addition & 0 deletions protocol/src/main/contraband/server.contra
Expand Up @@ -43,6 +43,7 @@ type ExecStatusEvent implements EventMessage {
channelName: String
execId: String
commandQueue: [String]
exitCode: Int @since("1.1.2")
}

interface SettingQueryResponse implements EventMessage {}
Expand Down

0 comments on commit 8227cef

Please sign in to comment.