diff options
author | moix <moix@epfl.ch> | 2010-07-29 09:52:28 +0000 |
---|---|---|
committer | moix <moix@epfl.ch> | 2010-07-29 09:52:28 +0000 |
commit | e3ca222e48fa917d631c1ee6ecbc8a594ae76d10 (patch) | |
tree | c5c719ee1b38d5f238ee513279fda4f8cb263283 /project/build/Packer.scala | |
parent | 26bbdbe3a21d17f5b2a94ea528eb4508d2b3b13e (diff) | |
download | scala-e3ca222e48fa917d631c1ee6ecbc8a594ae76d10.tar.gz scala-e3ca222e48fa917d631c1ee6ecbc8a594ae76d10.tar.bz2 scala-e3ca222e48fa917d631c1ee6ecbc8a594ae76d10.zip |
First version of SBT build for Scala compiler/l...
First version of SBT build for Scala compiler/library (see README)
Diffstat (limited to 'project/build/Packer.scala')
-rw-r--r-- | project/build/Packer.scala | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/project/build/Packer.scala b/project/build/Packer.scala new file mode 100644 index 0000000000..8e3be9d9a3 --- /dev/null +++ b/project/build/Packer.scala @@ -0,0 +1,89 @@ +import sbt._ +import java.io.{File,FileInputStream} +import java.util.jar.Manifest +import BasicLayer._ +import FileUtilities._ + +/** + * Create the jars of pack + * @author Grégory Moix + */ +trait Packer { + self: BasicLayer => + + def libraryToCopy:List[Path] = Nil + + protected def jarPattern(path:PathFinder) = path.descendentsExcept(AllPassFilter, defaultExcludes || new ExactFilter("MANIFEST.MF")).get + + def createJar(j:Packaging):Option[String] = { + def pack0(content:Iterable[Path])=jar(content.flatMap(jarPattern(_)),j.jarDestination, j.manifest, false, log) + j.jarsToInclude match { + case Nil => pack0(j.jarContent) + case list => { + withTemporaryDirectory(log) { tmp: File => + val tmpPath = Path.fromFile(tmp) + log.debug("List of jars to be added : " +list) + def unzip0(l:List[Path]):Option[String] = l match { + case x::xs => {unzip(x,tmpPath,log);unzip0(xs)} //TODO properly handle failing of unzip + case Nil => None + } + unzip0(list) + log.debug("Content of temp folder"+ tmpPath.##.**( GlobFilter("*"))) + pack0(j.jarContent ++ Set(tmpPath ##)) + } + } + } + } + + lazy val pack= task { + + def iterate(steps:List[Step]):Option[String]= steps match{ + case x::xs => x match{ + case c:Packaging => { + createJar(c) orElse iterate(xs) + } + case _ => iterate(xs) + } + case Nil => None + } + + def copy0 ={ + copyFile(manifestPath,packingDestination/"META-INF"/"MANIFEST.MF",log) orElse { + copy(libraryToCopy,packingDestination , true,true,log) match { + case Right(_) => None + case Left(e) => Some(e) + } + } + } + iterate(allSteps.topologicalSort) orElse copy0 + }.dependsOn(finishLayer) + + + +} + +trait Packaging extends Step{ + def manifest = new Manifest + def jarDestination:Path = packagingDestination /"lib" / jarName + def packagingDestination:Path + def jarName:String + def jarsToInclude:List[Path] = Nil + def jarContent:Iterable[Path] + +} + +trait WrapperPackaging extends Packaging { + self : WrapperStep => + + def jarContent = { + def getContent(list:List[Step],acc:List[Path]):List[Path]= list match { + case Nil => acc + case x::xs => x match { + case w:WrapperStep => getContent(xs,getContent(w.dependencies.toList,acc)) + case c:CompilationStep => getContent(xs,(c.outputDirectory ##)::acc) + } + } + getContent(dependencies.toList,Nil) + } + +} |