mirror of https://github.com/sbt/sbt.git
Disallow SettingQuery relying on currentProject
Introduce a specialised scopedKeyParser on SettingQuery to redefine the "projectRef" parser to never match "*" or omitted project refereneces.
This commit is contained in:
parent
b282ea51d7
commit
bf5bc46d3c
|
|
@ -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 key = Parser.parse(req.setting, Act scopedKeyParser extracted)
|
||||
val key = Parser.parse(req.setting, SettingQuery scopedKeyParser extracted)
|
||||
|
||||
def getSettingValue[A](key: Def.ScopedKey[A]) =
|
||||
extracted.structure.data.get(key.scope, key.key)
|
||||
|
|
@ -113,3 +113,61 @@ final class NetworkChannel(val name: String, connection: Socket, state: State) e
|
|||
out.close()
|
||||
}
|
||||
}
|
||||
|
||||
object SettingQuery {
|
||||
import java.net.URI
|
||||
import sbt.internal.util.{ AttributeKey, Settings }
|
||||
import sbt.internal.util.complete.{ DefaultParsers, Parser }, DefaultParsers._
|
||||
import sbt.Def.{ showBuildRelativeKey, ScopedKey }
|
||||
|
||||
// Similar to Act.projectRef, except doesn't match "*" or omitted project references
|
||||
def projectRef(index: KeyIndex, currentBuild: URI): Parser[ResolvedReference] = {
|
||||
val trailing = '/' !!! "Expected '/' (if selecting a project)"
|
||||
Act.resolvedReference(index, currentBuild, trailing)
|
||||
}
|
||||
|
||||
def scopedKeyFull(
|
||||
index: KeyIndex,
|
||||
currentBuild: URI,
|
||||
defaultConfigs: Option[ResolvedReference] => Seq[String],
|
||||
keyMap: Map[String, AttributeKey[_]]
|
||||
): Parser[Seq[Parser[ParsedKey]]] = {
|
||||
for {
|
||||
proj <- projectRef(index, currentBuild)
|
||||
confAmb <- Act.config(index configs Some(proj))
|
||||
partialMask = ScopeMask(true, confAmb.isExplicit, false, false)
|
||||
} yield Act.taskKeyExtra(index, defaultConfigs, keyMap, Some(proj), confAmb, partialMask)
|
||||
}
|
||||
|
||||
def scopedKeyParser(structure: BuildStructure, currentBuild: URI): Parser[ScopedKey[_]] =
|
||||
scopedKey(
|
||||
structure.index.keyIndex,
|
||||
currentBuild,
|
||||
structure.extra.configurationsForAxis,
|
||||
structure.index.keyMap,
|
||||
structure.data
|
||||
)
|
||||
|
||||
def scopedKeySelected(
|
||||
index: KeyIndex,
|
||||
currentBuild: URI,
|
||||
defaultConfigs: Option[ResolvedReference] => Seq[String],
|
||||
keyMap: Map[String, AttributeKey[_]],
|
||||
data: Settings[Scope]
|
||||
): Parser[ParsedKey] =
|
||||
scopedKeyFull(index, currentBuild, defaultConfigs, keyMap) flatMap { choices =>
|
||||
Act.select(choices, data)(showBuildRelativeKey(currentBuild, index.buildURIs.size > 1))
|
||||
}
|
||||
|
||||
def scopedKey(
|
||||
index: KeyIndex,
|
||||
currentBuild: URI,
|
||||
defaultConfigs: Option[ResolvedReference] => Seq[String],
|
||||
keyMap: Map[String, AttributeKey[_]],
|
||||
data: Settings[Scope]
|
||||
): Parser[ScopedKey[_]] =
|
||||
scopedKeySelected(index, currentBuild, defaultConfigs, keyMap, data).map(_.key)
|
||||
|
||||
def scopedKeyParser(extracted: Extracted): Parser[ScopedKey[_]] =
|
||||
scopedKeyParser(extracted.structure, extracted.currentRef.build)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue