From f747228b08016723d1289bb09a278ff3cc25ed94 Mon Sep 17 00:00:00 2001 From: André Duarte Date: Sat, 25 Nov 2017 19:42:22 +0000 Subject: Allow the definition of a prependShellScript in a ScalaModule (#13) --- core/src/main/scala/mill/modules/Jvm.scala | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/src/main/scala/mill/modules/Jvm.scala b/core/src/main/scala/mill/modules/Jvm.scala index 84ae5c42..bccdfece 100644 --- a/core/src/main/scala/mill/modules/Jvm.scala +++ b/core/src/main/scala/mill/modules/Jvm.scala @@ -1,7 +1,7 @@ package mill.modules import java.io.FileOutputStream -import java.util.jar.{JarEntry, JarFile, JarInputStream, JarOutputStream} +import java.util.jar.{JarEntry, JarFile, JarOutputStream} import ammonite.ops._ import mill.define.Task @@ -65,21 +65,32 @@ object Jvm { def createAssembly(outputPath: Path, inputPaths: Seq[Path], - mainClass: Option[String] = None): Option[Path] = { + mainClass: Option[String] = None, + prependShellScript: String = "\n"): Option[Path] = { rm(outputPath) if(inputPaths.isEmpty) None else { mkdir(outputPath/up) + val output = new FileOutputStream(outputPath.toIO) + + // Prepend shell script + output.write((prependShellScript + "\n").getBytes) + if (prependShellScript.nonEmpty) { + import ammonite.ops.ImplicitWd._ + %%("chmod", "+x", outputPath) + } + val jar = new JarOutputStream( - new FileOutputStream(outputPath.toIO), + output, createManifest(mainClass) ) val seen = mutable.Set("META-INF/MANIFEST.MF") try{ assert(inputPaths.forall(exists(_))) + for{ p <- inputPaths @@ -106,6 +117,7 @@ object Jvm { } } finally { jar.close() + output.close() } Some(outputPath) -- cgit v1.2.3