added final tasks (package up distribution and executable JAR) to SBT build

This commit is contained in:
Jonas Bonér 2010-03-09 22:07:14 +01:00
parent 7873a7a9e0
commit 5e7f928cb0
6 changed files with 134 additions and 353 deletions

View file

@ -35,8 +35,14 @@
-------------------------------------------------------------------------------*/
import sbt._
import java.util.jar.Attributes
class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
// project versions
val JERSEY_VERSION = "1.1.5"
val ATMO_VERSION = "0.6-SNAPSHOT"
val CASSANDRA_VERSION = "0.5.0"
class AkkaParent(info: ProjectInfo) extends ParentProject(info) {
// repos
val sunjdmk = "sunjdmk" at "http://wp5.e-taxonomy.eu/cdmlib/mavenrepo"
val databinder = "DataBinder" at "http://databinder.net/repo"
@ -49,13 +55,8 @@ class AkkaParent(info: ProjectInfo) extends ParentProject(info) {
val google = "google" at "http://google-maven-repository.googlecode.com/svn/repository"
val m2 = "m2" at "http://download.java.net/maven/2"
// project versions
val JERSEY_VERSION = "1.1.5"
val ATMO_VERSION = "0.6-SNAPSHOT"
val CASSANDRA_VERSION = "0.5.0"
// project defintions
lazy val akka_java_util = project("akka-util-java", "akka-java-util", new AkkaJavaUtilProject(_))
lazy val akka_java_util = project("akka-util-java", "akka-util-java", new AkkaJavaUtilProject(_))
lazy val akka_util = project("akka-util", "akka-util", new AkkaUtilProject(_))
lazy val akka_core = project("akka-core", "akka-core", new AkkaCoreProject(_), akka_util, akka_java_util)
lazy val akka_amqp = project("akka-amqp", "akka-amqp", new AkkaAMQPProject(_), akka_core)
@ -65,74 +66,153 @@ class AkkaParent(info: ProjectInfo) extends ParentProject(info) {
lazy val akka_security = project("akka-security", "akka-security", new AkkaSecurityProject(_), akka_core)
lazy val akka_persistence = project("akka-persistence", "akka-persistence", new AkkaPersistenceParentProject(_))
lazy val akka_cluster = project("akka-cluster", "akka-cluster", new AkkaClusterParentProject(_))
lazy val akka_kernel = project("akka-kernel", "akka-kernel", new AkkaKernelProject(_), akka_core, akka_rest, akka_persistence, akka_cluster, akka_amqp, akka_security, akka_comet)
lazy val akka_kernel = project("akka-kernel", "akka-kernel", new AkkaKernelProject(_), akka_core, akka_rest, akka_persistence, akka_cluster, akka_amqp, akka_security, akka_comet, akka_patterns)
// examples
lazy val akka_fun_test = project("akka-fun-test-java", "akka-fun-test-java", new AkkaFunTestProject(_), akka_kernel)
lazy val akka_samples = project("akka-samples", "akka-samples", new AkkaSamplesParentProject(_))
def akkaHome = {
def distName = "%s-%s.zip".format(name, version)
lazy val akkaHome = {
val home = System.getenv("AKKA_HOME")
if (home == null) throw new Error("You need to set the $AKKA_HOME environment variable to the root of the Akka distribution")
home
}
lazy val deployPath = Path.fromFile(new java.io.File(akkaHome + "/deploy"))
lazy val distPath = Path.fromFile(new java.io.File(akkaHome + "/dist"))
override def mainClass = Some("se.scalablesolutions.akka.Main")
override def packageOptions =
manifestClassPath.map(cp => ManifestAttributes((Attributes.Name.CLASS_PATH, cp))).toList :::
getMainClass(false).map(MainClass(_)).toList
override def manifestClassPath = Some(allArtifacts.getFiles
.filter(_.getName.endsWith(".jar"))
.map("lib_managed/scala_%s/compile/".format(defScalaVersion.value) + _.getName)
.mkString(" ") +
" dist/akka-util_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-util-java_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-core_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-rest_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-comet_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-security_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-persistence-common_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-persistence-redis_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-persistence-cassandra_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-persistence-mongo_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-cluster-jgroups_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-cluster-shoal_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-amqp_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-patterns_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-kernel_%s-%s.jar".format(defScalaVersion.value, version)
)
/*
override def manifestClassPath = Some(allArtifacts.getFiles
.filter(_.getName.endsWith(".jar"))
.map { jar =>
println("------- " + jar)
if (jar.getName.contains("akka")) "dist/" + jar.getName
else "lib_managed/scala_2.7.7/compile/" + jar.getName
}.mkString(" "))
*/
def removeDupEntries(paths: PathFinder) =
Path.lazyPathFinder {
val mapped = paths.get map { p => (p.relativePath, p) }
(Map() ++ mapped).values.toList
}
def allArtifacts = {
removeDupEntries(runClasspath filter ClasspathUtilities.isArchive) +++
((outputPath ##) / defaultJarName) +++
mainResources +++
mainDependencies.scalaJars +++
descendents(info.projectPath, "*.conf") +++
descendents(info.projectPath / "dist", "*.jar") +++
descendents(path("lib") ##, "*.jar") +++
descendents(configurationPath(Configurations.Compile) ##, "*.jar")
}
def deployTask(info: ProjectInfo, toDir: Path) = task {
val projectPath = info.projectPath.toString
val moduleName = projectPath.substring(projectPath.lastIndexOf('/') + 1, projectPath.length)
// FIXME need to find out a way to grab these paths from the sbt system
val JAR_FILE_NAME = moduleName + "_%s-%s.jar".format(defScalaVersion.value, version)
val JAR_FILE_PATH = projectPath + "/target/scala_%s/".format(defScalaVersion.value) + JAR_FILE_NAME
val from = Path.fromFile(new java.io.File(JAR_FILE_PATH))
val to = Path.fromFile(new java.io.File(toDir + "/" + JAR_FILE_NAME))
log.info("Deploying " + to)
FileUtilities.copyFile(from, to, log)
}
lazy val dist = zipTask(allArtifacts, "dist", distName) dependsOn (`package`) describedAs("Zips up the distribution.")
// subprojects
class AkkaCoreProject(info: ProjectInfo) extends DefaultProject(info) {
val sjson = "sjson.json" % "sjson" % "0.4" % "compile"
val werkz = "org.codehaus.aspectwerkz" % "aspectwerkz-nodeps-jdk5" % "2.1" % "compile"
val werkz_core = "org.codehaus.aspectwerkz" % "aspectwerkz-jdk5" % "2.1" % "compile"
val netty = "org.jboss.netty" % "netty" % "3.2.0.BETA1" % "compile"
val commons_io = "commons-io" % "commons-io" % "1.4" % "compile"
val dispatch_json = "net.databinder" % "dispatch-json_2.7.7" % "0.6.4" % "compile"
val dispatch_http = "net.databinder" % "dispatch-http_2.7.7" % "0.6.4" % "compile"
val dispatch_htdisttp = "net.databinder" % "dispatch-http_2.7.7" % "0.6.4" % "compile"
val sjson = "sjson.json" % "sjson" % "0.4" % "compile"
val sbinary = "sbinary" % "sbinary" % "0.3" % "compile"
val jackson = "org.codehaus.jackson" % "jackson-mapper-asl" % "1.2.1" % "compile"
val jackson_core = "org.codehaus.jackson" % "jackson-core-asl" % "1.2.1" % "compile"
val voldemort = "voldemort.store.compress" % "h2-lzf" % "1.0" % "compile"
val javautils = "org.scala-tools" % "javautils" % "2.7.4-0.1" % "compile"
val netty = "org.jboss.netty" % "netty" % "3.2.0.BETA1" % "compile"
// testing
val scalatest = "org.scalatest" % "scalatest" % "1.0" % "test"
val junit = "junit" % "junit" % "4.5" % "test"
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaUtilProject(info: ProjectInfo) extends DefaultProject(info) {
val werkz = "org.codehaus.aspectwerkz" % "aspectwerkz-nodeps-jdk5" % "2.1" % "compile"
val werkz_core = "org.codehaus.aspectwerkz" % "aspectwerkz-jdk5" % "2.1" % "compile"
val configgy = "net.lag" % "configgy" % "1.4.7" % "compile"
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaJavaUtilProject(info: ProjectInfo) extends DefaultProject(info) {
val guicey = "org.guiceyfruit" % "guice-core" % "2.0-beta-4" % "compile"
val protobuf = "com.google.protobuf" % "protobuf-java" % "2.2.0" % "compile"
val multiverse = "org.multiverse" % "multiverse-alpha" % "0.4-SNAPSHOT" % "compile"
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaAMQPProject(info: ProjectInfo) extends DefaultProject(info) {
val rabbit = "com.rabbitmq" % "amqp-client" % "1.7.2"
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaRestProject(info: ProjectInfo) extends DefaultProject(info) {
val servlet = "javax.servlet" % "servlet-api" % "2.5" % "provided"
val servlet = "javax.servlet" % "servlet-api" % "2.5" % "compile"
val jersey = "com.sun.jersey" % "jersey-core" % JERSEY_VERSION % "compile"
val jersey_server = "com.sun.jersey" % "jersey-server" % JERSEY_VERSION % "compile"
val jersey_json = "com.sun.jersey" % "jersey-json" % JERSEY_VERSION % "compile"
val jersey_contrib = "com.sun.jersey.contribs" % "jersey-scala" % JERSEY_VERSION % "compile"
val jsr311 = "javax.ws.rs" % "jsr311-api" % "1.1" % "compile"
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaCometProject(info: ProjectInfo) extends DefaultProject(info) {
val grizzly = "com.sun.grizzly" % "grizzly-comet-webserver" % "1.9.18-i" % "compile"
val servlet = "javax.servlet" % "servlet-api" % "2.5" % "provided"
val servlet = "javax.servlet" % "servlet-api" % "2.5" % "compile"
val atmo = "org.atmosphere" % "atmosphere-annotations" % ATMO_VERSION % "compile"
val atmo_jersey = "org.atmosphere" % "atmosphere-jersey" % ATMO_VERSION % "compile"
val atmo_runtime = "org.atmosphere" % "atmosphere-runtime" % ATMO_VERSION % "compile"
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaPatternsProject(info: ProjectInfo) extends DefaultProject(info) {
// testing
val scalatest = "org.scalatest" % "scalatest" % "1.0" % "test"
val junit = "junit" % "junit" % "4.5" % "test"
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaSecurityProject(info: ProjectInfo) extends DefaultProject(info) {
@ -144,21 +224,25 @@ class AkkaParent(info: ProjectInfo) extends ParentProject(info) {
val scalatest = "org.scalatest" % "scalatest" % "1.0" % "test"
val junit = "junit" % "junit" % "4.5" % "test"
val mockito = "org.mockito" % "mockito-all" % "1.8.1" % "test"
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaPersistenceCommonProject(info: ProjectInfo) extends DefaultProject(info) {
val thrift = "com.facebook" % "thrift" % "1.0" % "compile"
val commons_pool = "commons-pool" % "commons-pool" % "1.5.1" % "compile"
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaRedisProject(info: ProjectInfo) extends DefaultProject(info) {
val redis = "com.redis" % "redisclient" % "1.1" % "compile"
override def testOptions = TestFilter((name: String) => name.endsWith("Test")) :: Nil
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaMongoProject(info: ProjectInfo) extends DefaultProject(info) {
val mongo = "org.mongodb" % "mongo-java-driver" % "1.1" % "compile"
override def testOptions = TestFilter((name: String) => name.endsWith("Test")) :: Nil
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaCassandraProject(info: ProjectInfo) extends DefaultProject(info) {
@ -171,6 +255,7 @@ class AkkaParent(info: ProjectInfo) extends ParentProject(info) {
val slf4j_log4j = "org.slf4j" % "slf4j-log4j12" % "1.5.8" % "test"
val log4j = "log4j" % "log4j" % "1.2.15" % "test"
override def testOptions = TestFilter((name: String) => name.endsWith("Test")) :: Nil
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaPersistenceParentProject(info: ProjectInfo) extends ParentProject(info) {
@ -182,11 +267,13 @@ class AkkaParent(info: ProjectInfo) extends ParentProject(info) {
class AkkaJgroupsProject(info: ProjectInfo) extends DefaultProject(info) {
val jgroups = "jgroups" % "jgroups" % "2.8.0.CR7" % "compile"
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaShoalProject(info: ProjectInfo) extends DefaultProject(info) {
val shoal = "shoal-jxta" % "shoal" % "1.1-20090818" % "compile"
val shoal_extra = "shoal-jxta" % "jxta" % "1.1-20090818" % "compile"
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaClusterParentProject(info: ProjectInfo) extends ParentProject(info) {
@ -194,15 +281,8 @@ class AkkaParent(info: ProjectInfo) extends ParentProject(info) {
lazy val akka_cluster_shoal = project("akka-cluster-shoal", "akka-cluster-shoal", new AkkaShoalProject(_), akka_core)
}
class AkkaKernelProject(info: ProjectInfo) extends DefaultProject(info) with AssemblyProject {
val jersey_server = "com.sun.jersey" % "jersey-server" % JERSEY_VERSION % "compile"
val atmo = "org.atmosphere" % "atmosphere-annotations" % ATMO_VERSION % "compile"
val atmo_jersey = "org.atmosphere" % "atmosphere-jersey" % ATMO_VERSION % "compile"
val atmo_runtime = "org.atmosphere" % "atmosphere-runtime" % ATMO_VERSION % "compile"
val assemblyDistPath = Path.fromFile(new java.io.File(akkaHome + "/dist/akka-" + version.toString + ".jar"))
def mainMethod = Some("se.scalablesolutions.akka.Main")
override def packageOptions: Seq[PackageOption] = MainClass("se.scalablesolutions.akka.Main") :: Nil
class AkkaKernelProject(info: ProjectInfo) extends DefaultProject(info) {
lazy val dist = deployTask(info, distPath) dependsOn(`package`) describedAs("Deploying")
}
// examples
@ -217,27 +297,33 @@ class AkkaParent(info: ProjectInfo) extends ParentProject(info) {
val jmock = "org.jmock" % "jmock" % "2.4.0" % "test"
}
class AkkaSampleChatProject(info: ProjectInfo) extends DefaultProject(info)
class AkkaSampleChatProject(info: ProjectInfo) extends DefaultProject(info) {
lazy val dist = deployTask(info, deployPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaSampleLiftProject(info: ProjectInfo) extends DefaultProject(info) {
val lift = "net.liftweb" % "lift-webkit" % "1.1-M6" % "compile"
val lift_util = "net.liftweb" % "lift-util" % "1.1-M6" % "compile"
val servlet = "javax.servlet" % "servlet-api" % "2.5" % "provided"
val servlet = "javax.servlet" % "servlet-api" % "2.5" % "compile"
// testing
val jetty = "org.mortbay.jetty" % "jetty" % "6.1.6" % "test"
val junit = "junit" % "junit" % "4.5" % "test"
lazy val dist = deployTask(info, deployPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaSampleRestJavaProject(info: ProjectInfo) extends DefaultProject(info)
class AkkaSampleRestJavaProject(info: ProjectInfo) extends DefaultProject(info) {
lazy val dist = deployTask(info, deployPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaSampleRestScalaProject(info: ProjectInfo) extends DefaultProject(info) {
val jsr311 = "javax.ws.rs" % "jsr311-api" % "1.1" % "compile"
lazy val dist = deployTask(info, deployPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaSampleSecurityProject(info: ProjectInfo) extends DefaultProject(info) {
val jsr311 = "javax.ws.rs" % "jsr311-api" % "1.1" % "compile"
val jsr250 = "javax.annotation" % "jsr250-api" % "1.0"
lazy val dist = deployTask(info, deployPath) dependsOn(`package`) describedAs("Deploying")
}
class AkkaSamplesParentProject(info: ProjectInfo) extends ParentProject(info) {
@ -246,15 +332,12 @@ class AkkaParent(info: ProjectInfo) extends ParentProject(info) {
lazy val akka_sample_rest_java = project("akka-sample-rest-java", "akka-sample-rest-java", new AkkaSampleRestJavaProject(_), akka_kernel)
lazy val akka_sample_rest_scala = project("akka-sample-rest-scala", "akka-sample-rest-scala", new AkkaSampleRestScalaProject(_), akka_kernel)
lazy val akka_sample_security = project("akka-sample-security", "akka-sample-security", new AkkaSampleSecurityProject(_), akka_kernel)
//FileUtilities.copyFile(assemblyOutputPath, assemblyDistPath, log)
}
}
trait AssemblyProject extends BasicScalaProject {
val assemblyDistPath: Path
def assemblyExclude(base: PathFinder) = base / "META-INF" ** "*"
//def assemblyExclude(base: PathFinder) = base / "META-INF" ** "*"
def assemblyExclude(base: PathFinder) = Path.emptyPathFinder
def assemblyOutputPath = outputPath / assemblyJarName
def assemblyJarName = artifactID + "-assembly-" + version + ".jar"
def assemblyTemporaryPath = outputPath / "assembly-libs"
@ -263,16 +346,16 @@ trait AssemblyProject extends BasicScalaProject {
def assemblyPaths(tempDir: Path, classpath: PathFinder, extraJars: PathFinder, exclude: PathFinder => PathFinder) = {
val (libs, directories) = classpath.get.toList.partition(ClasspathUtilities.isArchive)
for(jar <- extraJars.get ++ libs) FileUtilities.unzip(jar, tempDir, log)
val filter = new NameFilter {
def accept(name: String) = !name.endsWith("LICENSE") && !name.endsWith("MANIFEST.MF")
}
for(jar <- extraJars.get ++ libs) FileUtilities.unzip(jar, tempDir, filter, log).left.foreach(error)
val base = (Path.lazyPathFinder(tempDir :: directories) ##)
(descendents(base, "*") --- exclude(base)).get
}
lazy val assembly = assemblyTask(assemblyTemporaryPath, assemblyClasspath, assemblyExtraJars, assemblyExclude) dependsOn(compile) describedAs("Packaging assembly")
lazy val dist = task({ log.info("Creating distribution " + assemblyDistPath); FileUtilities.copyFile(assemblyOutputPath, assemblyDistPath, log) }) dependsOn(assembly) describedAs("Creating distribution")
lazy val assembly = assemblyTask(assemblyTemporaryPath, assemblyClasspath, assemblyExtraJars, assemblyExclude) dependsOn(compile) describedAs("Packaging assembly ")
def assemblyTask(tempDir: Path, classpath: PathFinder, extraJars: PathFinder, exclude: PathFinder => PathFinder) = {
def assemblyTask(tempDir: Path, classpath: PathFinder, extraJars: PathFinder, exclude: PathFinder => PathFinder) =
packageTask(Path.lazyPathFinder(assemblyPaths(tempDir, classpath, extraJars, exclude)), assemblyOutputPath, packageOptions)
}
}