Working on a new template for 0.10.

This commit is contained in:
Paul Phillips 2011-08-14 08:14:25 -07:00
parent 7010cef2a5
commit 5663bbe1e1
4 changed files with 98 additions and 110 deletions

98
project/Build.scala Normal file
View File

@ -0,0 +1,98 @@
import sbt._
import Keys._
import Load.{ BuildStructure, StructureIndex }
import scala.collection.{ mutable, immutable }
object TemplateBuild extends Build {
// BuildStructure contains:
// units: Map[URI, LoadedBuildUnit]
// root: URI
// settings: Seq[Setting[_]]
// data: Settings[Scope]
// index: StructureIndex
// streams: Streams
// delegates: Scope => Seq[Scope]
// scopeLocal: ScopeLocal
private val cachedExtraction = new collection.mutable.HashMap[State, WState]
private implicit def stateWrapper(state: State): WState =
cachedExtraction.getOrElseUpdate(state, new WState(state))
private implicit def revealStructure(state: State): BuildStructure =
stateWrapper(state).structure
private implicit def revealStructureIndex(state: State): StructureIndex =
revealStructure(state).index
private implicit def revealSession(state: State): SessionSettings =
stateWrapper(state).session
private class WState(state: State) {
val extracted = Project extract state
def projectId = extracted.currentProject.id
def structure = extracted.structure
def session = extracted.session
def currentRef = extracted.currentRef
def rootProject = structure.rootProject
def allProjects = structure.allProjects
def index = structure.index
def taskToKey = index.taskToKey
def keyMap = index.keyMap // Map[String, AttributeKey[_]]
def keyIndex = index.keyIndex
def currentKeys = keyIndex keys Some(currentRef) map index.keyMap
def sortedKeys = currentKeys.toSeq sortBy (_.label)
}
private class Tap[T](target: T) {
def show(): Unit = target match {
case xs: TraversableOnce[_] => xs foreach println
case _ => println(target)
}
def tap[U](f: T => U): T = {
f(target)
target
}
}
private implicit def createTapper[T](target: T): Tap[T] = new Tap(target)
def currentBranch = ("git status -sb".lines_! headOption) getOrElse "-" stripPrefix "## "
val buildShellPrompt = {
(state: State) => "%s:%s>".format(
state.projectId,
currentBranch
)
}
lazy val testSettings = Seq(
libraryDependencies ++= Seq(
"org.specs2" %% "specs2" % "1.5",
"org.specs2" %% "specs2-scalaz-core" % "6.0.RC2" % "test"
)
)
lazy val buildSettings = Seq(
resolvers += ScalaToolsSnapshots,
organization := "org.template",
version := "0.1-SNAPSHOT",
scalaVersion := "2.9.0-1",
retrieveManaged := true,
shellPrompt := buildShellPrompt
// logLevel := Level.Debug,
)
lazy val templateConfig = Project(
id = "template",
base = file("."),
aggregate = Nil,
dependencies = Nil,
delegates = Nil,
settings = Defaults.defaultSettings ++ buildSettings ++ Seq(
commands += helpNames
)
)
// A sample command definition.
def helpNames = Command.command("help-names") { (state: State) =>
state tap (_.sortedKeys map (_.label) show)
}
}

View File

@ -1,8 +0,0 @@
#Project properties
#Generated by sbt-setup on Sat Apr 2 18:11:54 PDT 2011
project.organization=improving
project.name=sbt-template
sbt.version=0.7.7
project.version=0.0.1
build.scala.versions=2.8.1
project.initialize=false

View File

@ -1,95 +0,0 @@
import sbt._
class SbtTemplateProject(info: ProjectInfo) extends DefaultProject(info) with ProjectSupport {
}
trait ProjectSupport extends ModuleIdDynamifactory {
self: DefaultProject =>
/** Default "dynamic revision" to use with ivy.
* See [[http://www.jaya.free.fr/ivy/doc/ivyfile/dependency.html]].
* Likely alternatives: latest.milestone, latest.release
*/
def dynamicRevision = "latest.integration"
/** Repositories. Comment in or out to taste.
*/
val localMaven = "Local Maven" at "file://"+Path.userHome+"/.m2/repository"
val localIvy = "Local Ivy" at "file://"+Path.userHome+"/.ivy2/local"
val sonatype = "Sonatype" at "https://oss.sonatype.org/content/groups/public"
val scalaToolsSnapshots = "Scala Tools Snapshots" at "http://scala-tools.org/repo-snapshots/"
val jboss = "JBoss Repo" at "http://repository.jboss.org/maven2"
protected implicit lazy val implicitTransform: ArtifactTransform =
ArtifactTransform(inScope("test"), withSources)
/*** Libraries ***/
val specs: ModuleID = "org.scala-tools.testing" %% "specs"
val scalacheck: ModuleID = "org.scala-tools.testing" %% "scalacheck"
// val ant: ModuleID = "org.apache.ant" % "ant"
// val asmAll: ModuleID = "asm" % "asm-all" withSources()
// val commonsVFS: ModuleID = "org.apache.commons" % "commons-vfs-project"
// val easymock: ModuleID = "org.easymock" % "easymock"
// val guava: ModuleID = "com.google.guava" % "guava"
// val ivy: ModuleID = "org.apache.ivy" % "ivy"
// val jdt: ModuleID = "org.eclipse.jdt" % "core" notTransitive()
// val jetty: ModuleID = "org.mortbay.jetty" % "jetty"
// val jmock: ModuleID = "org.jmock" % "jmock"
// val jodaTime: ModuleID = "joda-time" % "joda-time"
// val liftJson: ModuleID = "net.liftweb" %% "lift-json"
// val maven: ModuleID = "org.apache.maven" % "maven-ant-tasks"
// val scalaARM: ModuleID = "com.github.jsuereth.scala-arm" %% "scala-arm" withSources()
// val scalaImproving: ModuleID = "org.improving" %% "scala-improving"
// val scalaSTM: ModuleID = "org.scala-tools" %% "scala-stm"
// val scalariform: ModuleID = "org.scalariform" %% "scalariform"
// val scalazCore: ModuleID = "org.scalaz" %% "scalaz-core" withSources()
// val scalazHttp: ModuleID = "org.scalaz" %% "scalaz-http" withSources()
// val slf4s: ModuleID = "com.weiglewilczek.slf4s" %% "slf4s" withSources()
}
trait ModuleIdDynamifactory extends Dynamifactory {
self: DefaultProject =>
protected type DepId = GroupArtifactID
protected type DepOut = ModuleID
protected def finishDependency(in: GroupArtifactID, revision: String): ModuleID = in % revision
protected implicit lazy val implicitRevision: ArtifactRevision =
ArtifactRevision(_ => dynamicRevision)
protected def inScope(scope: String): DepFn = _ % scope
protected def withSources: DepFn = _.withSources()
protected def intransitive: DepFn = _.intransitive()
protected def withJavadoc: DepFn = _.withJavadoc
protected def withRevision(newRevision: String): DepFn = (m: ModuleID) => {
ModuleID(m.organization, m.name, newRevision, m.configurations, m.isChanging, m.isTransitive, m.explicitArtifacts, m.extraAttributes)
}
}
trait Dynamifactory {
protected type DepId
protected type DepOut
protected type DepFn = DepOut => DepOut
protected def dynamicRevision: String
protected def finishDependency(in: DepId, revision: String): DepOut
case class ArtifactRevision(revisionFn: DepId => String) {
}
case class ArtifactTransform(fns: DepFn*) {
def apply(x: DepOut): DepOut = if (fns.isEmpty) x else fns.reduceLeft(_ andThen _)(x)
}
case class ArtifactConfig(rev: ArtifactRevision, transform: ArtifactTransform) { }
protected implicit def autoassembleConfig(implicit rev: ArtifactRevision, transform: ArtifactTransform): ArtifactConfig =
ArtifactConfig(rev, transform)
protected implicit def autoconfigureDependencies(in: DepId)(implicit config: ArtifactConfig): DepOut = {
val ArtifactConfig(ArtifactRevision(revisionFn), transform) = config
transform(finishDependency(in, revisionFn(in)))
}
}

View File

@ -1,7 +0,0 @@
import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
// def aquteRepo = "aQute Maven Repository" at "http://www.aqute.biz/repo"
// lazy val aquteModuleConfig = ModuleConfiguration("biz.aQute", aquteRepo)
// val bnd4sbt = "com.weiglewilczek.bnd4sbt" % "bnd4sbt" % "latest.release"
}