diff options
author | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2016-06-24 19:44:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-24 19:44:45 -0400 |
commit | b1b2195b13300d9b3057b96deebf24d9353a7344 (patch) | |
tree | 5bbb137c3de4cea3267c5fece06f095496b3b0a3 /stage2/Lib.scala | |
parent | fd6c08a1fe03fee7ccb87200bf4ff4b717d42864 (diff) | |
parent | 0ed626b8764dd21085e935f6642343a163e1273e (diff) | |
download | cbt-b1b2195b13300d9b3057b96deebf24d9353a7344.tar.gz cbt-b1b2195b13300d9b3057b96deebf24d9353a7344.tar.bz2 cbt-b1b2195b13300d9b3057b96deebf24d9353a7344.zip |
Merge pull request #159 from rockjam/wip/uber-jar
Uber-jar plugin initial implementation
Diffstat (limited to 'stage2/Lib.scala')
-rw-r--r-- | stage2/Lib.scala | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/stage2/Lib.scala b/stage2/Lib.scala index 8dd6e72..620c009 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -214,15 +214,21 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ } yield file } - def jarFile( jarFile: File, files: Seq[File] ): Option[File] = { + def jarFile( jarFile: File, files: Seq[File], mainClass: Option[String] = None ): Option[File] = { + Files.deleteIfExists(jarFile.toPath) if( files.isEmpty ){ None } else { jarFile.getParentFile.mkdirs logger.lib("Start packaging "++jarFile.string) - val manifest = new Manifest - manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0") - val jar = new JarOutputStream(new FileOutputStream(jarFile.toString), manifest) + val manifest = new Manifest() + manifest.getMainAttributes.put(Attributes.Name.MANIFEST_VERSION, "1.0") + manifest.getMainAttributes.putValue("Created-By", + Option(System.getProperty("java.runtime.version")) getOrElse "1.7.0_06 (Oracle Corporation)") + mainClass foreach { className => + manifest.getMainAttributes.put(Attributes.Name.MAIN_CLASS, className) + } + val jar = new JarOutputStream(new FileOutputStream(jarFile), manifest) try{ val names = for { base <- files.filter(_.exists).map(realpath) @@ -235,7 +241,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ entry.setTime(file.lastModified) jar.putNextEntry(entry) jar.write( readAllBytes( file.toPath ) ) - jar.closeEntry + jar.closeEntry() name } @@ -245,7 +251,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ s"Conflicting file names when trying to create $jarFile: "++duplicateFiles.mkString(", ") ) } finally { - jar.close + jar.close() } logger.lib("Done packaging " ++ jarFile.toString) |