mirror of https://github.com/sbt/sbt.git
Define OptJsonWriter & put it on AttributeKey
This commit is contained in:
parent
a12045ed42
commit
bbeecae0b1
|
|
@ -75,7 +75,8 @@ lazy val utilCollection = (project in internalPath / "util-collection").
|
||||||
settings(
|
settings(
|
||||||
commonSettings,
|
commonSettings,
|
||||||
Util.keywordsSettings,
|
Util.keywordsSettings,
|
||||||
name := "Util Collection"
|
name := "Util Collection",
|
||||||
|
libraryDependencies ++= Seq(sjsonnew)
|
||||||
)
|
)
|
||||||
|
|
||||||
lazy val utilApplyMacro = (project in internalPath / "util-appmacro").
|
lazy val utilApplyMacro = (project in internalPath / "util-appmacro").
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@ sealed trait AttributeKey[T] {
|
||||||
|
|
||||||
/** Identifies the relative importance of a key among other keys.*/
|
/** Identifies the relative importance of a key among other keys.*/
|
||||||
def rank: Int
|
def rank: Int
|
||||||
|
|
||||||
|
def optJsonWriter: OptJsonWriter[T]
|
||||||
}
|
}
|
||||||
private[sbt] abstract class SharedAttributeKey[T] extends AttributeKey[T] {
|
private[sbt] abstract class SharedAttributeKey[T] extends AttributeKey[T] {
|
||||||
override final def toString = label
|
override final def toString = label
|
||||||
|
|
@ -50,32 +52,33 @@ private[sbt] abstract class SharedAttributeKey[T] extends AttributeKey[T] {
|
||||||
final def isLocal: Boolean = false
|
final def isLocal: Boolean = false
|
||||||
}
|
}
|
||||||
object AttributeKey {
|
object AttributeKey {
|
||||||
def apply[T](name: String)(implicit mf: Manifest[T]): AttributeKey[T] =
|
def apply[T](name: String)(implicit mf: Manifest[T], ojw: OptJsonWriter[T]): AttributeKey[T] =
|
||||||
make(name, None, Nil, Int.MaxValue)
|
make(name, None, Nil, Int.MaxValue)
|
||||||
|
|
||||||
def apply[T](name: String, rank: Int)(implicit mf: Manifest[T]): AttributeKey[T] =
|
def apply[T](name: String, rank: Int)(implicit mf: Manifest[T], ojw: OptJsonWriter[T]): AttributeKey[T] =
|
||||||
make(name, None, Nil, rank)
|
make(name, None, Nil, rank)
|
||||||
|
|
||||||
def apply[T](name: String, description: String)(implicit mf: Manifest[T]): AttributeKey[T] =
|
def apply[T](name: String, description: String)(implicit mf: Manifest[T], ojw: OptJsonWriter[T]): AttributeKey[T] =
|
||||||
apply(name, description, Nil)
|
apply(name, description, Nil)
|
||||||
|
|
||||||
def apply[T](name: String, description: String, rank: Int)(implicit mf: Manifest[T]): AttributeKey[T] =
|
def apply[T](name: String, description: String, rank: Int)(implicit mf: Manifest[T], ojw: OptJsonWriter[T]): AttributeKey[T] =
|
||||||
apply(name, description, Nil, rank)
|
apply(name, description, Nil, rank)
|
||||||
|
|
||||||
def apply[T](name: String, description: String, extend: Seq[AttributeKey[_]])(implicit mf: Manifest[T]): AttributeKey[T] =
|
def apply[T](name: String, description: String, extend: Seq[AttributeKey[_]])(implicit mf: Manifest[T], ojw: OptJsonWriter[T]): AttributeKey[T] =
|
||||||
apply(name, description, extend, Int.MaxValue)
|
apply(name, description, extend, Int.MaxValue)
|
||||||
|
|
||||||
def apply[T](name: String, description: String, extend: Seq[AttributeKey[_]], rank: Int)(implicit mf: Manifest[T]): AttributeKey[T] =
|
def apply[T](name: String, description: String, extend: Seq[AttributeKey[_]], rank: Int)(implicit mf: Manifest[T], ojw: OptJsonWriter[T]): AttributeKey[T] =
|
||||||
make(name, Some(description), extend, rank)
|
make(name, Some(description), extend, rank)
|
||||||
|
|
||||||
private[this] def make[T](name: String, description0: Option[String], extend0: Seq[AttributeKey[_]], rank0: Int)(implicit mf: Manifest[T]): AttributeKey[T] = new SharedAttributeKey[T] {
|
private[this] def make[T](name: String, description0: Option[String], extend0: Seq[AttributeKey[_]], rank0: Int)(implicit mf: Manifest[T], ojw: OptJsonWriter[T]): AttributeKey[T] = new SharedAttributeKey[T] {
|
||||||
def manifest = mf
|
def manifest = mf
|
||||||
val label = Util.hyphenToCamel(name)
|
val label = Util.hyphenToCamel(name)
|
||||||
def description = description0
|
def description = description0
|
||||||
def extend = extend0
|
def extend = extend0
|
||||||
def rank = rank0
|
def rank = rank0
|
||||||
|
def optJsonWriter = ojw
|
||||||
}
|
}
|
||||||
private[sbt] def local[T](implicit mf: Manifest[T]): AttributeKey[T] = new AttributeKey[T] {
|
private[sbt] def local[T](implicit mf: Manifest[T], ojw: OptJsonWriter[T]): AttributeKey[T] = new AttributeKey[T] {
|
||||||
def manifest = mf
|
def manifest = mf
|
||||||
def label = LocalLabel
|
def label = LocalLabel
|
||||||
def description = None
|
def description = None
|
||||||
|
|
@ -83,6 +86,7 @@ object AttributeKey {
|
||||||
override def toString = label
|
override def toString = label
|
||||||
def isLocal: Boolean = true
|
def isLocal: Boolean = true
|
||||||
def rank = Int.MaxValue
|
def rank = Int.MaxValue
|
||||||
|
val optJsonWriter = ojw
|
||||||
}
|
}
|
||||||
private[sbt] final val LocalLabel = "$" + "local"
|
private[sbt] final val LocalLabel = "$" + "local"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package sbt.internal.util
|
||||||
|
|
||||||
|
import sjsonnew.JsonWriter
|
||||||
|
|
||||||
|
sealed trait OptJsonWriter[A]
|
||||||
|
final case class NoJsonWriter[A]() extends OptJsonWriter[A]
|
||||||
|
final case class SomeJsonWriter[A](value: JsonWriter[A]) extends OptJsonWriter[A]
|
||||||
|
|
||||||
|
trait OptJsonWriter0 {
|
||||||
|
implicit def fallback[A]: NoJsonWriter[A] = NoJsonWriter()
|
||||||
|
}
|
||||||
|
object OptJsonWriter extends OptJsonWriter0 {
|
||||||
|
implicit def lift[A](implicit z: JsonWriter[A]): SomeJsonWriter[A] = SomeJsonWriter(z)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue