summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-11-25 11:58:05 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-11-25 11:58:05 -0800
commite60bbce22af14088dabf0be5a8fa64c1cf9bdf82 (patch)
tree7c8a4becc57b8c77a786990adf32d0cbdc178488
parent15351c7239a835c28cff140bead740a0e408b285 (diff)
downloadmill-e60bbce22af14088dabf0be5a8fa64c1cf9bdf82.tar.gz
mill-e60bbce22af14088dabf0be5a8fa64c1cf9bdf82.tar.bz2
mill-e60bbce22af14088dabf0be5a8fa64c1cf9bdf82.zip
Swap over to using `java.nio` APIs to make self-executable jars, instead of shelling out to `chmod`
-rwxr-xr-xbuild.sc28
-rw-r--r--core/src/main/scala/mill/modules/Jvm.scala14
-rw-r--r--scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala2
3 files changed, 24 insertions, 20 deletions
diff --git a/build.sc b/build.sc
index 7ccb2d32..034a0685 100755
--- a/build.sc
+++ b/build.sc
@@ -21,20 +21,20 @@ object Core extends ScalaModule {
def basePath = pwd / 'core
override def sources = pwd/'core/'src/'main/'scala
- val cross =
- for(jarLabel <- mill.define.Cross("jarA", "jarB", "jarC"))
- yield new mill.Module{
- def printIt() = T.command{
- println("PRINTING IT: " + jarLabel)
- }
- def jar = T{
- val dest = T.ctx().dest
- ammonite.ops.mkdir(dest/ammonite.ops.up)
- ammonite.ops.cp(Core.jar().path, dest)
-
- PathRef(dest)
- }
- }
+// val cross =
+// for(jarLabel <- mill.define.Cross("jarA", "jarB", "jarC"))
+// yield new mill.Module{
+// def printIt() = T.command{
+// println("PRINTING IT: " + jarLabel)
+// }
+// def jar = T{
+// val dest = T.ctx().dest
+// ammonite.ops.mkdir(dest/ammonite.ops.up)
+// ammonite.ops.cp(Core.jar().path, dest)
+//
+// PathRef(dest)
+// }
+// }
object test extends this.Tests{
def basePath = pwd / 'core
diff --git a/core/src/main/scala/mill/modules/Jvm.scala b/core/src/main/scala/mill/modules/Jvm.scala
index bccdfece..d2833a33 100644
--- a/core/src/main/scala/mill/modules/Jvm.scala
+++ b/core/src/main/scala/mill/modules/Jvm.scala
@@ -1,6 +1,7 @@
package mill.modules
import java.io.FileOutputStream
+import java.nio.file.attribute.PosixFilePermission
import java.util.jar.{JarEntry, JarFile, JarOutputStream}
import ammonite.ops._
@@ -66,7 +67,7 @@ object Jvm {
def createAssembly(outputPath: Path,
inputPaths: Seq[Path],
mainClass: Option[String] = None,
- prependShellScript: String = "\n"): Option[Path] = {
+ prependShellScript: String = ""): Option[Path] = {
rm(outputPath)
if(inputPaths.isEmpty) None
@@ -75,11 +76,14 @@ object Jvm {
val output = new FileOutputStream(outputPath.toIO)
- // Prepend shell script
- output.write((prependShellScript + "\n").getBytes)
+ // Prepend shell script and make it executable
if (prependShellScript.nonEmpty) {
- import ammonite.ops.ImplicitWd._
- %%("chmod", "+x", outputPath)
+ output.write((prependShellScript + "\n").getBytes)
+ val perms = java.nio.file.Files.getPosixFilePermissions(outputPath.toNIO)
+ perms.add(PosixFilePermission.GROUP_EXECUTE)
+ perms.add(PosixFilePermission.OWNER_EXECUTE)
+ perms.add(PosixFilePermission.OTHERS_EXECUTE)
+ java.nio.file.Files.setPosixFilePermissions(outputPath.toNIO, perms)
}
val jar = new JarOutputStream(
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala b/scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala
index 7bfe14e1..fc4db19e 100644
--- a/scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala
+++ b/scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala
@@ -26,7 +26,7 @@ object GenIdea {
val modules = Mirror
.traverse(obj, discovered.mirror){ (h, p) =>
- h.node(obj, p.map{case Mirror.Segment.Cross(vs) => vs case _ => Nil}.toList) match {
+ h.node(obj, p.map{case Mirror.Segment.Cross(vs) => vs.toList case _ => Nil}.toList) match {
case m: ScalaModule => Seq(p -> m)
case _ => Nil
}