Drop aggregation in querying settings

This commit is contained in:
Dale Wijnand 2017-02-27 13:40:59 +00:00
parent 2efacb8c46
commit f09897ca29
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
4 changed files with 19 additions and 28 deletions

View File

@ -83,7 +83,7 @@ final class NetworkChannel(val name: String, connection: Socket, state: State) e
import sbt.internal.util.complete.Parser import sbt.internal.util.complete.Parser
val extracted = Project extract state val extracted = Project extract state
val keys = Parser.parse(req.setting, Act aggregatedKeyParser extracted) val key = Parser.parse(req.setting, Act scopedKeyParser extracted)
def getSettingValue[A](key: Def.ScopedKey[A]) = def getSettingValue[A](key: Def.ScopedKey[A]) =
extracted.structure.data.get(key.scope, key.key) extracted.structure.data.get(key.scope, key.key)
@ -94,23 +94,14 @@ final class NetworkChannel(val name: String, connection: Socket, state: State) e
case x => Right(x) case x => Right(x)
} }
def zeroValues: Either[Vector[String], Vector[Any]] = Right(Vector.empty) val values = key match {
def anyLeftsOrAllRights[A, B](acc: Either[Vector[A], Vector[B]], elem: Either[A, B]): Either[Vector[A], Vector[B]] = case Left(msg) => Left(s"Invalid programmatic input: $msg")
(acc, elem) match { case Right(key) => Right(getSettingValue(key))
case (Right(a), Right(x)) => Right(a :+ x)
case (Right(_), Left(x)) => Left(Vector(x))
case (Left(a), Right(_)) => Left(a)
case (Left(a), Left(x)) => Left(a :+ x)
}
val values = keys match {
case Left(msg) => Left(s"Invalid programmatic input:" +: (msg.lines.toVector map (" " + _)))
case Right(keys) => keys.map(getSettingValue(_)).foldLeft(zeroValues)(anyLeftsOrAllRights)
} }
val jsonValues = values match { val jsonValues = values match {
case Left(errors) => errors case Left(errors) => errors
case Right(values) => values map (_.toString) case Right(value) => value.toString
} }
StandardMain.exchange publishEventMessage SettingQueryResponse(jsonValues) StandardMain.exchange publishEventMessage SettingQueryResponse(jsonValues)

View File

@ -5,28 +5,28 @@
// DO NOT EDIT MANUALLY // DO NOT EDIT MANUALLY
package sbt.protocol package sbt.protocol
final class SettingQueryResponse private ( final class SettingQueryResponse private (
val values: Vector[String]) extends sbt.protocol.EventMessage() with Serializable { val value: String) extends sbt.protocol.EventMessage() with Serializable {
override def equals(o: Any): Boolean = o match { override def equals(o: Any): Boolean = o match {
case x: SettingQueryResponse => (this.values == x.values) case x: SettingQueryResponse => (this.value == x.value)
case _ => false case _ => false
} }
override def hashCode: Int = { override def hashCode: Int = {
37 * (17 + values.##) 37 * (17 + value.##)
} }
override def toString: String = { override def toString: String = {
"SettingQueryResponse(" + values + ")" "SettingQueryResponse(" + value + ")"
} }
protected[this] def copy(values: Vector[String] = values): SettingQueryResponse = { protected[this] def copy(value: String = value): SettingQueryResponse = {
new SettingQueryResponse(values) new SettingQueryResponse(value)
} }
def withValues(values: Vector[String]): SettingQueryResponse = { def withValue(value: String): SettingQueryResponse = {
copy(values = values) copy(value = value)
} }
} }
object SettingQueryResponse { object SettingQueryResponse {
def apply(values: Vector[String]): SettingQueryResponse = new SettingQueryResponse(values) def apply(value: String): SettingQueryResponse = new SettingQueryResponse(value)
} }

View File

@ -11,16 +11,16 @@ implicit lazy val SettingQueryResponseFormat: JsonFormat[sbt.protocol.SettingQue
jsOpt match { jsOpt match {
case Some(js) => case Some(js) =>
unbuilder.beginObject(js) unbuilder.beginObject(js)
val values = unbuilder.readField[Vector[String]]("values") val value = unbuilder.readField[String]("value")
unbuilder.endObject() unbuilder.endObject()
sbt.protocol.SettingQueryResponse(values) sbt.protocol.SettingQueryResponse(value)
case None => case None =>
deserializationError("Expected JsObject but found None") deserializationError("Expected JsObject but found None")
} }
} }
override def write[J](obj: sbt.protocol.SettingQueryResponse, builder: Builder[J]): Unit = { override def write[J](obj: sbt.protocol.SettingQueryResponse, builder: Builder[J]): Unit = {
builder.beginObject() builder.beginObject()
builder.addField("values", obj.values) builder.addField("value", obj.value)
builder.endObject() builder.endObject()
} }
} }

View File

@ -41,7 +41,7 @@ type ExecStatusEvent implements EventMessage {
} }
type SettingQueryResponse implements EventMessage { type SettingQueryResponse implements EventMessage {
values: [String] value: String!
} }
# enum Status { # enum Status {