diff options
author | André Duarte <atduarte@users.noreply.github.com> | 2017-11-25 19:42:22 +0000 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-25 11:42:22 -0800 |
commit | f747228b08016723d1289bb09a278ff3cc25ed94 (patch) | |
tree | c59916f72931d0bb179f631c41f531017398f10d | |
parent | ff852a7a7602030b57af6f7fa499742b5c76d771 (diff) | |
download | mill-f747228b08016723d1289bb09a278ff3cc25ed94.tar.gz mill-f747228b08016723d1289bb09a278ff3cc25ed94.tar.bz2 mill-f747228b08016723d1289bb09a278ff3cc25ed94.zip |
Allow the definition of a prependShellScript in a ScalaModule (#13)
-rwxr-xr-x | build.sc | 4 | ||||
-rw-r--r-- | core/src/main/scala/mill/modules/Jvm.scala | 18 | ||||
-rw-r--r-- | scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala | 10 |
3 files changed, 28 insertions, 4 deletions
@@ -50,4 +50,8 @@ object ScalaPlugin extends ScalaModule { override def projectDeps = Seq(Core) def basePath = pwd / 'scalaplugin override def sources = pwd/'scalaplugin/'src/'main/'scala + + override def prependShellScript = + "#!/usr/bin/env sh\n" + + "exec java -cp \"$0\" mill.scalaplugin.Main \"$@\"" }
\ No newline at end of file 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) diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala index 5a1f261a..2e842a6e 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala @@ -159,6 +159,11 @@ object ScalaModule{ def scalaRuntimeIvyDeps(scalaVersion: String) = Seq[Dep]( Dep.Java("org.scala-lang", "scala-library", scalaVersion) ) + + val DefaultShellScript: Seq[String] = Seq( + "#!/usr/bin/env sh", + "exec java -jar \"$0\" \"$@\"" + ) } import ScalaModule._ trait TestScalaModule extends ScalaModule with TaskModule{ @@ -247,6 +252,8 @@ trait ScalaModule extends Module{ outer => ) } + def prependShellScript: T[String] = T{ "" } + def sources = T.source{ basePath / 'src } def resources = T.source{ basePath / 'resources } def compile = T.persistent{ @@ -256,7 +263,8 @@ trait ScalaModule extends Module{ outer => val dest = T.ctx().dest createAssembly( dest, - (runDepClasspath().filter(_.path.ext != "pom") ++ Seq(resources(), compile())).map(_.path).filter(exists) + (runDepClasspath().filter(_.path.ext != "pom") ++ Seq(resources(), compile())).map(_.path).filter(exists), + prependShellScript = prependShellScript() ) PathRef(dest) } |