Finalized SBT packaging task, now Akka is fully ported to SBT

This commit is contained in:
Jonas Bonér 2010-03-10 17:16:10 +01:00
parent 5e7f928cb0
commit bde7563bd8
2 changed files with 79 additions and 97 deletions

View file

View file

@ -38,12 +38,28 @@ import sbt._
import java.util.jar.Attributes import java.util.jar.Attributes
class AkkaParent(info: ProjectInfo) extends DefaultProject(info) { class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
// ------------------------------------------------------------
// project versions // project versions
val JERSEY_VERSION = "1.1.5" val JERSEY_VERSION = "1.1.5"
val ATMO_VERSION = "0.6-SNAPSHOT" val ATMO_VERSION = "0.6-SNAPSHOT"
val CASSANDRA_VERSION = "0.5.0" val CASSANDRA_VERSION = "0.5.0"
// repos // ------------------------------------------------------------
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"))
lazy val dist = zipTask(allArtifacts, "dist", distName) dependsOn (`package`) describedAs("Zips up the distribution.")
def distName = "%s_%s-%s.zip".format(name, defScalaVersion.value, version)
// ------------------------------------------------------------
// repositories
val sunjdmk = "sunjdmk" at "http://wp5.e-taxonomy.eu/cdmlib/mavenrepo" val sunjdmk = "sunjdmk" at "http://wp5.e-taxonomy.eu/cdmlib/mavenrepo"
val databinder = "DataBinder" at "http://databinder.net/repo" val databinder = "DataBinder" at "http://databinder.net/repo"
val configgy = "Configgy" at "http://www.lag.net/repo" val configgy = "Configgy" at "http://www.lag.net/repo"
@ -55,6 +71,7 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
val google = "google" at "http://google-maven-repository.googlecode.com/svn/repository" val google = "google" at "http://google-maven-repository.googlecode.com/svn/repository"
val m2 = "m2" at "http://download.java.net/maven/2" val m2 = "m2" at "http://download.java.net/maven/2"
// ------------------------------------------------------------
// project defintions // project defintions
lazy val akka_java_util = project("akka-util-java", "akka-util-java", 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_util = project("akka-util", "akka-util", new AkkaUtilProject(_))
@ -66,29 +83,24 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
lazy val akka_security = project("akka-security", "akka-security", new AkkaSecurityProject(_), akka_core) 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_persistence = project("akka-persistence", "akka-persistence", new AkkaPersistenceParentProject(_))
lazy val akka_cluster = project("akka-cluster", "akka-cluster", new AkkaClusterParentProject(_)) 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, akka_patterns) 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)
// functional tests in java
lazy val akka_fun_test = project("akka-fun-test-java", "akka-fun-test-java", new AkkaFunTestProject(_), akka_kernel)
// examples // 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(_)) lazy val akka_samples = project("akka-samples", "akka-samples", new AkkaSamplesParentProject(_))
def distName = "%s-%s.zip".format(name, version) // ------------------------------------------------------------
// create executable jar
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 mainClass = Some("se.scalablesolutions.akka.Main")
override def packageOptions = override def packageOptions =
manifestClassPath.map(cp => ManifestAttributes((Attributes.Name.CLASS_PATH, cp))).toList ::: manifestClassPath.map(cp => ManifestAttributes((Attributes.Name.CLASS_PATH, cp))).toList :::
getMainClass(false).map(MainClass(_)).toList getMainClass(false).map(MainClass(_)).toList
// create a manifest with all akka jars and dependency jars on classpath
override def manifestClassPath = Some(allArtifacts.getFiles override def manifestClassPath = Some(allArtifacts.getFiles
.filter(_.getName.endsWith(".jar")) .filter(_.getName.endsWith(".jar"))
.map("lib_managed/scala_%s/compile/".format(defScalaVersion.value) + _.getName) .map("lib_managed/scala_%s/compile/".format(defScalaVersion.value) + _.getName)
@ -96,62 +108,21 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
" dist/akka-util_%s-%s.jar".format(defScalaVersion.value, version) + " dist/akka-util_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-util-java_%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-core_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-cluster-shoal_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-cluster-jgroups_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-rest_%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-comet_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-security_%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-amqp_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-patterns_%s-%s.jar".format(defScalaVersion.value, version) + " dist/akka-patterns_%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-mongo_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-persistence-cassandra_%s-%s.jar".format(defScalaVersion.value, version) +
" dist/akka-kernel_%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 // subprojects
class AkkaCoreProject(info: ProjectInfo) extends DefaultProject(info) { class AkkaCoreProject(info: ProjectInfo) extends DefaultProject(info) {
val netty = "org.jboss.netty" % "netty" % "3.2.0.BETA1" % "compile" val netty = "org.jboss.netty" % "netty" % "3.2.0.BETA1" % "compile"
@ -333,29 +304,40 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
lazy val akka_sample_rest_scala = project("akka-sample-rest-scala", "akka-sample-rest-scala", new AkkaSampleRestScalaProject(_), 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) lazy val akka_sample_security = project("akka-sample-security", "akka-sample-security", new AkkaSampleSecurityProject(_), akka_kernel)
} }
// ------------------------------------------------------------
// helper functions
def removeDupEntries(paths: PathFinder) =
Path.lazyPathFinder {
val mapped = paths.get map { p => (p.relativePath, p) }
(Map() ++ mapped).values.toList
} }
trait AssemblyProject extends BasicScalaProject { def allArtifacts = {
//def assemblyExclude(base: PathFinder) = base / "META-INF" ** "*" (removeDupEntries(runClasspath filter ClasspathUtilities.isArchive) +++
def assemblyExclude(base: PathFinder) = Path.emptyPathFinder ((outputPath ##) / defaultJarName) +++
def assemblyOutputPath = outputPath / assemblyJarName mainResources +++
def assemblyJarName = artifactID + "-assembly-" + version + ".jar" mainDependencies.scalaJars +++
def assemblyTemporaryPath = outputPath / "assembly-libs" descendents(info.projectPath, "*.conf") +++
def assemblyClasspath = runClasspath descendents(info.projectPath / "dist", "*.jar") +++
def assemblyExtraJars = mainDependencies.scalaJars descendents(info.projectPath / "deploy", "*.jar") +++
descendents(path("lib") ##, "*.jar") +++
def assemblyPaths(tempDir: Path, classpath: PathFinder, extraJars: PathFinder, exclude: PathFinder => PathFinder) = { descendents(configurationPath(Configurations.Compile) ##, "*.jar"))
val (libs, directories) = classpath.get.toList.partition(ClasspathUtilities.isArchive) .filter(jar =>
val filter = new NameFilter { !jar.toString.endsWith("scala-library-2.7.5.jar") && // remove redundant scala libs
def accept(name: String) = !name.endsWith("LICENSE") && !name.endsWith("MANIFEST.MF") !jar.toString.endsWith("scala-library-2.7.6.jar"))
}
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 ") 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
def assemblyTask(tempDir: Path, classpath: PathFinder, extraJars: PathFinder, exclude: PathFinder => PathFinder) = val from = Path.fromFile(new java.io.File(JAR_FILE_PATH))
packageTask(Path.lazyPathFinder(assemblyPaths(tempDir, classpath, extraJars, exclude)), assemblyOutputPath, packageOptions) val to = Path.fromFile(new java.io.File(toDir + "/" + JAR_FILE_NAME))
log.info("Deploying " + to)
FileUtilities.copyFile(from, to, log)
}
} }