build work

This commit is contained in:
Mark Harrah 2011-06-26 12:27:07 -04:00
parent f7068a4cbb
commit c7885ce1ff
7 changed files with 162 additions and 17 deletions

View File

@ -1,10 +1,10 @@
[scala]
version: 2.8.1
version: ${{scala.version}}
[app]
org: org.scala-tools.sbt
org: ${{org}}
name: sbt
version: read(sbt.version)[0.10.1-SNAPSHOT]
version: read(sbt.version)[${{sbt.version}}]
class: ${sbt.main.class-sbt.xMain}
components: xsbti
cross-versioned: true
@ -12,7 +12,7 @@
[repositories]
local
maven-local
typesafe-ivy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
${{repositories}}
maven-central
scala-tools-releases
scala-tools-snapshots

55
project/Release.scala Normal file
View File

@ -0,0 +1,55 @@
import sbt._
import Keys._
import Status.{isSnapshot, publishStatus}
import org.apache.ivy.util.url.CredentialsStore
object Release extends Plugin
{
lazy val publishRelease = TaskKey[Unit]("publish-release")
lazy val publishAllArtifacts = TaskKey[Unit]("publish-all-artifacts")
lazy val launcherRemotePath = SettingKey[String]("launcher-remote-path")
lazy val remoteBase = SettingKey[String]("remote-base")
lazy val remoteID = SettingKey[String]("remote-id")
lazy val publishLauncher = TaskKey[String]("publish-launcher")
def settings(nonRoots: => Seq[ProjectReference], launcher: ScopedTask[File]): Seq[Setting[_]] =
if(CredentialsFile.exists) releaseSettings(nonRoots, launcher) else Nil
def releaseSettings(nonRoots: => Seq[ProjectReference], launcher: ScopedTask[File]): Seq[Setting[_]] = Seq(
publishTo in ThisBuild <<= publishResolver,
remoteID <<= publishStatus("typesafe-ivy-" + _),
credentials in Global += Credentials(CredentialsFile),
remoteBase <<= publishStatus( "https://typesafe.artifactoryonline.com/typesafe/ivy-" + _ ),
publishAllArtifacts <<= Util.inAll(nonRoots, publish.task),
publishLauncher <<= deployLauncher(launcher),
publishRelease <<= Seq(publishLauncher, publishAllArtifacts).dependOn,
launcherRemotePath <<= (organization, version) { (org, v) => List(org, LaunchJarName, v, LaunchJarName + ".jar").mkString("/") }
)
def deployLauncher(launcher: ScopedTask[File]) =
(launcher, launcherRemotePath, credentials, remoteBase, streams) map { (launchJar, remotePath, creds, base, s) =>
val (uname, pwd) = getCredentials(creds, s.log)
val request = dispatch.url(base) / remotePath <<< (launchJar, BinaryType) as (uname, pwd)
val http = new dispatch.Http
try { http(request.as_str) } finally { http.shutdown() }
}
def getCredentials(cs: Seq[Credentials], log: Logger): (String, String) =
{
// 0.10.1
// val creds = Credentials.forHost(cs, "typesafe.artifactoryonline.com")
// (creds.userName, creds.passwd)
Credentials.register(cs, log)
val creds = CredentialsStore.INSTANCE.getCredentials(RemoteRealm, RemoteHost)
(creds.getUserName, creds.getPasswd)
}
def snapshotPattern(version: String) = Resolver.localBasePattern.replaceAll("""\[revision\]""", version)
def publishResolver: Project.Initialize[Option[Resolver]] = (remoteID, remoteBase) { (id, base) =>
Some( Resolver.url(id, url(base))(Resolver.ivyStylePatterns) )
}
final val BinaryType = "binary/octet-stream"
final val RemoteHost = "typesafe.artifactoryonline.com"
final val RemoteRealm = "Artifactory Realm"
final val LaunchJarName = "sbt-launch"
lazy val CredentialsFile: File = Path.userHome / ".ivy2" / ".typesafe-credentials"
}

View File

@ -12,15 +12,14 @@
object Sbt extends Build
{
override lazy val settings = super.settings ++ Seq(
override lazy val settings = super.settings ++ buildSettings ++ Status.settings
def buildSettings = Seq(
organization := "org.scala-tools.sbt",
version := "0.10.1-SNAPSHOT",
publishArtifact in packageDoc := false,
scalaVersion := "2.8.1",
publishMavenStyle := false,
componentID := None,
publishTo := Some( Resolver.url("typesafe-ivy-releases", url("http://repo.typesafe.com/typesafe/ivy-releases/"))(Resolver.ivyStylePatterns) ),
credentials += Credentials(Path.userHome / ".ivy2" / ".typesafe-credentials")
componentID := None
)
lazy val myProvided = config("provided") intransitive;
@ -34,10 +33,6 @@ object Sbt extends Build
lazy val launchInterfaceSub = project(launchPath / "interface", "Launcher Interface") settings(javaOnly : _*)
// the launcher. Retrieves, loads, and runs applications based on a configuration file.
lazy val launchSub = testedBaseProject(launchPath, "Launcher") dependsOn(ioSub % "test->test", interfaceSub % "test", launchInterfaceSub) settings(launchSettings : _*)
def launchSettings = Seq(jline, ivy, crossPaths := false,
compile in Test <<= compile in Test dependsOn(publishLocal in interfaceSub, publishLocal in testSamples, publishLocal in launchInterfaceSub)
// mappings in (Compile, packageBin) <++= (mappings in (launchInterfaceSub, Compile, packageBin) ).identity
)
// used to test the retrieving and loading of an application: sample app is packaged and published to the local repository
lazy val testSamples = noPublish( baseProject(launchPath / "test-sample", "Launch Test") ) dependsOn(interfaceSub, launchInterfaceSub) settings(scalaCompiler, crossPaths := false)
@ -158,8 +153,14 @@ object Sbt extends Build
Defaults.inAllProjects(sxrProjects, scoped, Project.extract(s).structure.data)
}
def launchSettings = inConfig(Compile)(Transform.configSettings) ++ Seq(jline, ivy, crossPaths := false,
compile in Test <<= compile in Test dependsOn(publishLocal in interfaceSub, publishLocal in testSamples, publishLocal in launchInterfaceSub)
// mappings in (Compile, packageBin) <++= (mappings in (launchInterfaceSub, Compile, packageBin) ).identity
)
import Sxr.sxr
def rootSettings = LaunchProguard.settings ++ LaunchProguard.specific(launchSub) ++ Sxr.settings ++ docSetting ++ Seq(
def releaseSettings = Release.settings(nonRoots, proguard in Proguard)
def rootSettings = releaseSettings ++ LaunchProguard.settings ++ LaunchProguard.specific(launchSub) ++ Sxr.settings ++ docSetting ++ Seq(
scriptedScalaVersion := "2.8.1",
scripted <<= scriptedTask,
scriptedSource <<= (sourceDirectory in sbtSub) / "sbt-test",
@ -169,7 +170,7 @@ object Sbt extends Build
compileInputs in (Compile,sxr) <<= (sources in sxr, compileInputs in sbtSub in Compile, fullClasspath in sxr) map { (srcs, in, cp) =>
in.copy(config = in.config.copy(sources = srcs, classpath = cp.files))
},
publishAll <<= state flatMap { s => nop dependsOn( Defaults.inAllProjects(nonRoots, publishLocal.task, Project.extract(s).structure.data) : _*) },
publishAll <<= inAll(nonRoots, publishLocal.task),
TaskKey[Unit]("build-all") <<= (publishAll, proguard in Proguard, sxr, doc) map { (_,_,_,_) => () }
)
def docSetting = inConfig(Compile)(inTask(sxr)(doc in ThisScope.copy(task = Global, config = Global) <<= Defaults.docTask))

37
project/Status.scala Normal file
View File

@ -0,0 +1,37 @@
import sbt._
import Keys._
object Status
{
lazy val isSnapshot = SettingKey[Boolean]("is-snapshot")
lazy val publishStatus = SettingKey[String]("publish-status")
def settings: Seq[Setting[_]] = Seq(
isSnapshot <<= version(_ contains "-"),
publishStatus <<= isSnapshot { snap => if(snap) "snapshots" else "releases" },
commands += stampVersion
)
def stampVersion = Command.command("stamp-version") { state =>
append((version in ThisBuild ~= stamp) :: Nil, state)
}
// TODO: replace with extracted.append from 0.10.1
def append(settings: Seq[Setting[_]], state: State): State =
{
val extracted = Project.extract(state)
import extracted._
val append = Load.transformSettings(Load.projectScope(currentRef), currentRef.build, rootProject, settings)
val newStructure = Load.reapply(session.original ++ append, structure)
Project.setProject(session, newStructure, state)
}
def stamp(v: String): String =
if(v endsWith Snapshot)
(v stripSuffix Snapshot) + "-" + timestampString(System.currentTimeMillis)
else
v
def timestampString(time: Long): String =
{
val format = new java.text.SimpleDateFormat("yyyyMMdd-HHmmss")
format.format(new java.util.Date(time))
}
final val Snapshot = "-SNAPSHOT"
}

48
project/Transform.scala Normal file
View File

@ -0,0 +1,48 @@
import sbt._
import Keys._
object Transform
{
lazy val transformResources = TaskKey[Seq[File]]("transform-resources")
lazy val inputResourceDirectories = SettingKey[Seq[File]]("input-resource-directories")
lazy val inputResourceDirectory = SettingKey[File]("input-resource-directory")
lazy val inputResources = TaskKey[Seq[File]]("input-resources")
lazy val resourceProperties = TaskKey[Map[String,String]]("resource-properties")
// to be replace by 0.10.1's fileMappings
lazy val fileMappings = TaskKey[Seq[(File,File)]]("file-mappings")
def configSettings = Seq(
inputResourceDirectory <<= sourceDirectory / "input_resources",
inputResourceDirectories <<= Seq(inputResourceDirectory).join,
inputResources <<= inputResourceDirectories.map(dirs => (dirs ** (-DirectoryFilter)).get ),
resourceProperties <<= defineProperties,
fileMappings in transformResources <<= transformMappings,
transformResources <<= (fileMappings in transformResources, resourceProperties) map { (rs, props) =>
rs map { case (in, out) => transform(in, out, props) }
},
resourceGenerators <+= transformResources.identity
)
def transformMappings = (inputResources, inputResourceDirectories, resourceManaged) map { (rs, rdirs, rm) =>
(rs --- rdirs) x (rebase(rdirs, rm)|flat(rm)) toSeq
}
def defineProperties =
(organization, version, scalaVersion, Status.isSnapshot) map { (org, v, sv, isSnapshot) =>
Map("org" -> org, "sbt.version" -> v, "scala.version" -> sv, "repositories" -> repositories(isSnapshot).mkString(IO.Newline))
}
def transform(in: File, out: File, map: Map[String, String]): File =
{
def get(key: String): String = map.getOrElse(key, error("No value defined for key '" + key + "'"))
val newString = Property.replaceAllIn(IO.read(in), mtch => get(mtch.group(1)) )
if(newString != IO.read(out))
IO.write(out, newString)
out
}
lazy val Property = """\$\{\{([\w.-]+)\}\}""".r
def repositories(isSnapshot: Boolean) = Releases :: (if(isSnapshot) Snapshots :: Nil else Nil)
lazy val Releases = typesafeRepository("releases")
lazy val Snapshots = typesafeRepository("snapshots")
def typesafeRepository(status: String) =
""" typesafe-ivy-%s: http://repo.typesafe.com/typesafe/ivy-%<s/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]""" format status
}

View File

@ -6,6 +6,9 @@ object Util
{
lazy val componentID = SettingKey[Option[String]]("component-id")
def inAll(projects: => Seq[ProjectReference], key: ScopedSetting[Task[Unit]]) =
state flatMap { s => nop dependsOn( Defaults.inAllProjects(projects, key, Project.extract(s).structure.data) : _*) }
def noPublish(p: Project) = p.copy(settings = noRemotePublish(p.settings))
def noRemotePublish(in: Seq[Setting[_]]) = in filterNot { s => s.key == deliver || s.key == publish }
lazy val noExtra = projectDependencies ~= { _.map(_.copy(extraAttributes = Map.empty)) } // not sure why this is needed
@ -54,14 +57,14 @@ object Util
val content = "version=" + version + "\ntimestamp=" + timestamp
val f = dir / "xsbt.version.properties"
if(!f.exists) { // TODO: properly handle this
s.log.info("Writing version information to " + f + " :\n" + content)
IO.write(f, content) }
s.log.info("Writing version information to " + f + " :\n" + content)
IO.write(f, content)
}
f :: Nil
}
def binID = "compiler-interface-bin"
def srcID = "compiler-interface-src"
}
object Common
{
def lib(m: ModuleID) = libraryDependencies += m

1
project/plugins/p.sbt Normal file
View File

@ -0,0 +1 @@
libraryDependencies += "net.databinder" %% "dispatch-http" % "0.8.3"