From f09897ca29c541fcb6e76f2f6b0f9ce6c98e7cbf Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 27 Feb 2017 13:40:59 +0000 Subject: [PATCH] Drop aggregation in querying settings --- .../sbt/internal/server/NetworkChannel.scala | 21 ++++++------------- .../sbt/protocol/SettingQueryResponse.scala | 18 ++++++++-------- .../codec/SettingQueryResponseFormats.scala | 6 +++--- protocol/src/main/contraband/server.contra | 2 +- 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/main/src/main/scala/sbt/internal/server/NetworkChannel.scala b/main/src/main/scala/sbt/internal/server/NetworkChannel.scala index a564e5044..790091aa6 100644 --- a/main/src/main/scala/sbt/internal/server/NetworkChannel.scala +++ b/main/src/main/scala/sbt/internal/server/NetworkChannel.scala @@ -83,7 +83,7 @@ final class NetworkChannel(val name: String, connection: Socket, state: State) e import sbt.internal.util.complete.Parser 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]) = 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) } - def zeroValues: Either[Vector[String], Vector[Any]] = Right(Vector.empty) - def anyLeftsOrAllRights[A, B](acc: Either[Vector[A], Vector[B]], elem: Either[A, B]): Either[Vector[A], Vector[B]] = - (acc, elem) match { - 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 values = key match { + case Left(msg) => Left(s"Invalid programmatic input: $msg") + case Right(key) => Right(getSettingValue(key)) } val jsonValues = values match { - case Left(errors) => errors - case Right(values) => values map (_.toString) + case Left(errors) => errors + case Right(value) => value.toString } StandardMain.exchange publishEventMessage SettingQueryResponse(jsonValues) diff --git a/protocol/src/main/contraband-scala/sbt/protocol/SettingQueryResponse.scala b/protocol/src/main/contraband-scala/sbt/protocol/SettingQueryResponse.scala index f89b2b6a3..ce844ff43 100644 --- a/protocol/src/main/contraband-scala/sbt/protocol/SettingQueryResponse.scala +++ b/protocol/src/main/contraband-scala/sbt/protocol/SettingQueryResponse.scala @@ -5,28 +5,28 @@ // DO NOT EDIT MANUALLY package sbt.protocol 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 { - case x: SettingQueryResponse => (this.values == x.values) + case x: SettingQueryResponse => (this.value == x.value) case _ => false } override def hashCode: Int = { - 37 * (17 + values.##) + 37 * (17 + value.##) } override def toString: String = { - "SettingQueryResponse(" + values + ")" + "SettingQueryResponse(" + value + ")" } - protected[this] def copy(values: Vector[String] = values): SettingQueryResponse = { - new SettingQueryResponse(values) + protected[this] def copy(value: String = value): SettingQueryResponse = { + new SettingQueryResponse(value) } - def withValues(values: Vector[String]): SettingQueryResponse = { - copy(values = values) + def withValue(value: String): SettingQueryResponse = { + copy(value = value) } } object SettingQueryResponse { - def apply(values: Vector[String]): SettingQueryResponse = new SettingQueryResponse(values) + def apply(value: String): SettingQueryResponse = new SettingQueryResponse(value) } diff --git a/protocol/src/main/contraband-scala/sbt/protocol/codec/SettingQueryResponseFormats.scala b/protocol/src/main/contraband-scala/sbt/protocol/codec/SettingQueryResponseFormats.scala index dfe1477fa..b6555f1c6 100644 --- a/protocol/src/main/contraband-scala/sbt/protocol/codec/SettingQueryResponseFormats.scala +++ b/protocol/src/main/contraband-scala/sbt/protocol/codec/SettingQueryResponseFormats.scala @@ -11,16 +11,16 @@ implicit lazy val SettingQueryResponseFormat: JsonFormat[sbt.protocol.SettingQue jsOpt match { case Some(js) => unbuilder.beginObject(js) - val values = unbuilder.readField[Vector[String]]("values") + val value = unbuilder.readField[String]("value") unbuilder.endObject() - sbt.protocol.SettingQueryResponse(values) + sbt.protocol.SettingQueryResponse(value) case None => deserializationError("Expected JsObject but found None") } } override def write[J](obj: sbt.protocol.SettingQueryResponse, builder: Builder[J]): Unit = { builder.beginObject() - builder.addField("values", obj.values) + builder.addField("value", obj.value) builder.endObject() } } diff --git a/protocol/src/main/contraband/server.contra b/protocol/src/main/contraband/server.contra index 129f1bb91..44103c0c1 100644 --- a/protocol/src/main/contraband/server.contra +++ b/protocol/src/main/contraband/server.contra @@ -41,7 +41,7 @@ type ExecStatusEvent implements EventMessage { } type SettingQueryResponse implements EventMessage { - values: [String] + value: String! } # enum Status {