Add an optional exitCode to ExecStatusEvent so clients can use it

This commit is contained in:
Dale Wijnand 2018-03-12 19:00:24 +00:00
parent 7baf97d2a6
commit bde6365013
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
3 changed files with 20 additions and 8 deletions

View File

@ -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[Long]) 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 + ")"
}
private[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)
private[this] def copy(status: String = status, channelName: Option[String] = channelName, execId: Option[String] = execId, commandQueue: Vector[String] = commandQueue, exitCode: Option[Long] = exitCode): ExecStatusEvent = {
new ExecStatusEvent(status, channelName, execId, commandQueue, exitCode)
}
def withStatus(status: String): ExecStatusEvent = {
copy(status = status)
@ -44,9 +45,17 @@ final class ExecStatusEvent private (
def withCommandQueue(commandQueue: Vector[String]): ExecStatusEvent = {
copy(commandQueue = commandQueue)
}
def withExitCode(exitCode: Option[Long]): ExecStatusEvent = {
copy(exitCode = exitCode)
}
def withExitCode(exitCode: Long): 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[Long]): ExecStatusEvent = new ExecStatusEvent(status, channelName, execId, commandQueue, exitCode)
def apply(status: String, channelName: String, execId: String, commandQueue: Vector[String], exitCode: Long): ExecStatusEvent = new ExecStatusEvent(status, Option(channelName), Option(execId), commandQueue, Option(exitCode))
}

View File

@ -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[Long]]("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")
}
@ -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()
}
}

View File

@ -43,6 +43,7 @@ type ExecStatusEvent implements EventMessage {
channelName: String
execId: String
commandQueue: [String]
exitCode: Long @since("1.1.2")
}
interface SettingQueryResponse implements EventMessage {}