summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-11-25 11:42:46 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-11-25 11:42:46 -0800
commit15351c7239a835c28cff140bead740a0e408b285 (patch)
tree2b9a86f5aca4d3151ec40571c2e919d0f73b967b
parent7f916ad59a7705a76158dfccc75a1918d4d6e850 (diff)
parentf747228b08016723d1289bb09a278ff3cc25ed94 (diff)
downloadmill-15351c7239a835c28cff140bead740a0e408b285.tar.gz
mill-15351c7239a835c28cff140bead740a0e408b285.tar.bz2
mill-15351c7239a835c28cff140bead740a0e408b285.zip
Merge branch 'master' of github.com:lihaoyi/mill
-rwxr-xr-xbuild.sc4
-rw-r--r--core/src/main/scala/mill/modules/Jvm.scala18
-rw-r--r--scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala10
3 files changed, 28 insertions, 4 deletions
diff --git a/build.sc b/build.sc
index 18cb0388..7ccb2d32 100755
--- a/build.sc
+++ b/build.sc
@@ -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)
}