Merge pull request #18 from sbt/wip/fileinfo

Adds picklers to FileInfo, also new house rules
This commit is contained in:
eugene yokota 2015-09-25 17:34:19 -04:00
commit 57286cfc5b
13 changed files with 78 additions and 47 deletions

View File

@ -1,10 +1,11 @@
import Dependencies._
import Util._
def baseVersion: String = "0.1.0-M4"
def internalPath = file("internal")
def commonSettings: Seq[Setting[_]] = Seq(
scalaVersion := "2.10.5",
scalaVersion := scala211,
// publishArtifact in packageDoc := false,
resolvers += Resolver.typesafeIvyRepo("releases"),
resolvers += Resolver.sonatypeRepo("snapshots"),
@ -27,8 +28,6 @@ def commonSettings: Seq[Setting[_]] = Seq(
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard"),
bintrayPackage := (bintrayPackage in ThisBuild).value,
bintrayRepository := (bintrayRepository in ThisBuild).value,
publishArtifact in Compile := true,
publishArtifact in Test := true
)
@ -40,22 +39,11 @@ lazy val utilRoot: Project = (project in file(".")).
).
settings(
inThisBuild(Seq(
organization := "org.scala-sbt",
version := "0.1.0-SNAPSHOT",
git.baseVersion := baseVersion,
bintrayPackage := "util",
homepage := Some(url("https://github.com/sbt/util")),
description := "Util module for sbt",
licenses := List("BSD New" -> url("https://github.com/sbt/sbt/blob/0.13/LICENSE")),
scmInfo := Some(ScmInfo(url("https://github.com/sbt/util"), "git@github.com:sbt/util.git")),
developers := List(
Developer("harrah", "Mark Harrah", "@harrah", url("https://github.com/harrah")),
Developer("eed3si9n", "Eugene Yokota", "@eed3si9n", url("https://github.com/eed3si9n")),
Developer("jsuereth", "Josh Suereth", "@jsuereth", url("https://github.com/jsuereth")),
Developer("dwijnand", "Dale Wijnand", "@dwijnand", url("https://github.com/dwijnand"))
),
bintrayReleaseOnPublish := false,
bintrayOrganization := Some("sbt"),
bintrayRepository := "maven-releases",
bintrayPackage := "util"
scmInfo := Some(ScmInfo(url("https://github.com/sbt/util"), "git@github.com:sbt/util.git"))
)),
commonSettings,
name := "Util Root",

View File

@ -77,7 +77,9 @@ object Instance {
* this should be the argument wrapped in Right.
*/
def contImpl[T, N[_]](c: Context, i: Instance with Singleton, convert: Convert, builder: TupleBuilder)(t: Either[c.Expr[T], c.Expr[i.M[T]]], inner: Transform[c.type, N])(
implicit tt: c.WeakTypeTag[T], nt: c.WeakTypeTag[N[T]], it: c.TypeTag[i.type]): c.Expr[i.M[N[T]]] =
implicit
tt: c.WeakTypeTag[T], nt: c.WeakTypeTag[N[T]], it: c.TypeTag[i.type]
): c.Expr[i.M[N[T]]] =
{
import c.universe.{ Apply => ApplyTree, _ }

View File

@ -8,31 +8,61 @@ import sbinary.{ DefaultProtocol, Format }
import DefaultProtocol._
import scala.reflect.Manifest
import sbt.io.Hash
import sbt.serialization._
sealed trait FileInfo extends NotNull {
val file: File
}
@directSubclasses(Array(classOf[FileHash], classOf[HashModifiedFileInfo]))
sealed trait HashFileInfo extends FileInfo {
val hash: List[Byte]
}
object HashFileInfo {
implicit val pickler: Pickler[HashFileInfo] with Unpickler[HashFileInfo] = PicklerUnpickler.generate[HashFileInfo]
}
@directSubclasses(Array(classOf[FileModified], classOf[HashModifiedFileInfo]))
sealed trait ModifiedFileInfo extends FileInfo {
val lastModified: Long
}
object ModifiedFileInfo {
implicit val pickler: Pickler[ModifiedFileInfo] with Unpickler[ModifiedFileInfo] = PicklerUnpickler.generate[ModifiedFileInfo]
}
@directSubclasses(Array(classOf[PlainFile]))
sealed trait PlainFileInfo extends FileInfo {
def exists: Boolean
}
object PlainFileInfo {
implicit val pickler: Pickler[PlainFileInfo] with Unpickler[PlainFileInfo] = PicklerUnpickler.generate[PlainFileInfo]
}
@directSubclasses(Array(classOf[FileHashModified]))
sealed trait HashModifiedFileInfo extends HashFileInfo with ModifiedFileInfo
object HashModifiedFileInfo {
implicit val pickler: Pickler[HashModifiedFileInfo] with Unpickler[HashModifiedFileInfo] = PicklerUnpickler.generate[HashModifiedFileInfo]
}
private final case class PlainFile(file: File, exists: Boolean) extends PlainFileInfo
private final case class FileHash(file: File, hash: List[Byte]) extends HashFileInfo
private final case class FileModified(file: File, lastModified: Long) extends ModifiedFileInfo
private final case class FileHashModified(file: File, hash: List[Byte], lastModified: Long) extends HashModifiedFileInfo
private[sbt] final case class PlainFile(file: File, exists: Boolean) extends PlainFileInfo
private[sbt] object PlainFile {
implicit val pickler: Pickler[PlainFile] with Unpickler[PlainFile] = PicklerUnpickler.generate[PlainFile]
}
private[sbt] final case class FileHash(file: File, hash: List[Byte]) extends HashFileInfo
private[sbt] object FileHash {
implicit val pickler: Pickler[FileHash] with Unpickler[FileHash] = PicklerUnpickler.generate[FileHash]
}
private[sbt] final case class FileModified(file: File, lastModified: Long) extends ModifiedFileInfo
private[sbt] object FileModified {
implicit val pickler: Pickler[FileModified] with Unpickler[FileModified] = PicklerUnpickler.generate[FileModified]
}
private[sbt] final case class FileHashModified(file: File, hash: List[Byte], lastModified: Long) extends HashModifiedFileInfo
private[sbt] object FileHashModified {
implicit val pickler: Pickler[FileHashModified] with Unpickler[FileHashModified] = PicklerUnpickler.generate[FileHashModified]
}
object FileInfo {
implicit def existsInputCache: InputCache[PlainFileInfo] = exists.infoInputCache
implicit def modifiedInputCache: InputCache[ModifiedFileInfo] = lastModified.infoInputCache
implicit def hashInputCache: InputCache[HashFileInfo] = hash.infoInputCache
implicit def fullInputCache: InputCache[HashModifiedFileInfo] = full.infoInputCache
implicit val pickler: Pickler[FileInfo] with Unpickler[FileInfo] = PicklerUnpickler.generate[FileInfo]
sealed trait Style {
type F <: FileInfo

View File

@ -56,9 +56,8 @@ object Dag {
finished;
}
final class Cyclic(val value: Any, val all: List[Any], val complete: Boolean)
extends Exception("Cyclic reference involving " +
(if (complete) all.mkString("\n ", "\n ", "") else value)
) {
extends Exception("Cyclic reference involving " +
(if (complete) all.mkString("\n ", "\n ", "") else value)) {
def this(value: Any) = this(value, value :: Nil, false)
override def toString = getMessage
def ::(a: Any): Cyclic =

View File

@ -49,7 +49,8 @@ object SettingsUsage {
val mySettings: Seq[Setting[_]] = Seq(
setting(a3, value(3)),
setting(b4, map(a4)(_ * 3)),
update(a5)(_ + 1))
update(a5)(_ + 1)
)
// "compiles" and applies the settings.
// This can be split into multiple steps to access intermediate results if desired.

View File

@ -55,7 +55,8 @@ object SettingsTest extends Properties("settings") {
List(scoped0, scoped1) <- chk :: scopedKeys sliding 2
nextInit = if (scoped0 == chk) chk
else (scoped0 zipWith chk) { (p, _) => p + 1 }
} yield derive(setting(scoped1, nextInit))).toSeq
} yield derive(setting(scoped1, nextInit))
).toSeq
{
// Note: This causes a cycle refernec error, quite frequently.
@ -95,7 +96,8 @@ object SettingsTest extends Properties("settings") {
setting(b, value(6)),
derive(setting(b, a)),
setting(a, value(5)),
setting(b, value(8)))
setting(b, value(8))
)
val ev = evaluate(settings)
checkKey(a, Some(5), ev) && checkKey(b, Some(8), ev)
}
@ -104,7 +106,8 @@ object SettingsTest extends Properties("settings") {
setting(a, value(3)),
setting(b, value(6)),
derive(setting(b, a)),
setting(a, value(5)))
setting(a, value(5))
)
val ev = evaluate(settings)
checkKey(a, Some(5), ev) && checkKey(b, Some(5), ev)
}

View File

@ -34,7 +34,8 @@ object HistoryCommands {
Nth -> ("Execute the command with index n, as shown by the " + ListFull + " command"),
Previous -> "Execute the nth command before this one",
StartsWithString -> "Execute the most recent command starting with 'string'",
ContainsString -> "Execute the most recent command containing 'string'")
ContainsString -> "Execute the most recent command containing 'string'"
)
def helpString = "History commands:\n " + (descriptions.map { case (c, d) => c + " " + d }).mkString("\n ")
def printHelp(): Unit =
println(helpString)
@ -46,8 +47,7 @@ object HistoryCommands {
val MaxLines = 500
lazy val num = token(NatBasic, "<integer>")
lazy val last = Last ^^^ { execute(_.!!) }
lazy val list = ListCommands ~> (num ?? Int.MaxValue) map { show =>
(h: History) => { printHistory(h, MaxLines, show); Some(Nil) }
lazy val list = ListCommands ~> (num ?? Int.MaxValue) map { show => (h: History) => { printHistory(h, MaxLines, show); Some(Nil) }
}
lazy val execStr = flag('?') ~ token(any.+.string, "<string>") map {
case (contains, str) =>

View File

@ -426,11 +426,10 @@ trait ParserMain {
case _ =>
val ci = i + 1
if (ci >= s.length)
a.resultEmpty.toEither.left.map { msgs0 =>
() =>
val msgs = msgs0()
val nonEmpty = if (msgs.isEmpty) "Unexpected end of input" :: Nil else msgs
(nonEmpty, ci)
a.resultEmpty.toEither.left.map { msgs0 => () =>
val msgs = msgs0()
val nonEmpty = if (msgs.isEmpty) "Unexpected end of input" :: Nil else msgs
(nonEmpty, ci)
}
else
loop(ci, a derive s(ci))

View File

@ -62,7 +62,8 @@ private[sbt] object TypeString {
val TypeMap = Map(
"java.io.File" -> "File",
"java.net.URL" -> "URL",
"java.net.URI" -> "URI")
"java.net.URI" -> "URI"
)
/**
* A Parser that extracts basic structure from the string representation of a type from Manifest.toString.

View File

@ -18,7 +18,8 @@ class ParserWithExamplesTest extends UnitSpec {
val _ = new ParserWithValidExamples {
val validCompletions = Completions(Set(
suggestion("blue"),
suggestion("red")))
suggestion("red")
))
parserWithExamples.completions(0) shouldEqual validCompletions
}
}
@ -27,7 +28,8 @@ class ParserWithExamplesTest extends UnitSpec {
"produce only valid examples that start with the character of the derivation" in {
val _ = new ParserWithValidExamples {
val derivedCompletions = Completions(Set(
suggestion("lue")))
suggestion("lue")
))
parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions
}
}
@ -45,7 +47,8 @@ class ParserWithExamplesTest extends UnitSpec {
val _ = new parserWithAllExamples {
val derivedCompletions = Completions(Set(
suggestion("lue"),
suggestion("lock")))
suggestion("lock")
))
parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions
}
}
@ -56,9 +59,11 @@ class ParserWithExamplesTest extends UnitSpec {
class parserWithAllExamples extends ParserExample(removeInvalidExamples = false)
case class ParserExample(examples: Iterable[String] = Set("blue", "yellow", "greeen", "block", "red"),
case class ParserExample(
examples: Iterable[String] = Set("blue", "yellow", "greeen", "block", "red"),
maxNumberOfExamples: Int = 25,
removeInvalidExamples: Boolean) {
removeInvalidExamples: Boolean
) {
import DefaultParsers._
@ -67,7 +72,8 @@ class ParserWithExamplesTest extends UnitSpec {
colorParser,
FixedSetExamples(examples),
maxNumberOfExamples,
removeInvalidExamples)
removeInvalidExamples
)
}
case class GrowableSourceOfExamples() extends Iterable[String] {

View File

@ -103,7 +103,8 @@ object Logic {
checkAcyclic(clauses)
problem.toLeft(
reduce0(clauses, initialFacts, Matched.empty))
reduce0(clauses, initialFacts, Matched.empty)
)
}
/**

View File

@ -20,7 +20,8 @@ object LogicTest extends Properties("Logic") {
case Right(res) => false
case Left(err: Logic.CyclicNegation) => true
case Left(err) => sys.error(s"Expected cyclic error, got: $err")
})
}
)
def expect(result: Either[LogicException, Matched], expected: Set[Atom]) = result match {
case Left(err) => false

View File

@ -1 +1 @@
addSbtPlugin("org.scala-sbt" % "sbt-houserules" % "0.1.0")
addSbtPlugin("org.scala-sbt" % "sbt-houserules" % "0.2.1")