summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-11-14 23:52:49 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-11-14 23:52:49 -0800
commit1045ed4589e602a2727c7ba014b820e134100e1f (patch)
tree2c185420b4da1eb6a2e8e74d8fd0eb8d513585c0 /core/src
parentd2598aa69c866236c9b5eddac2e03161b2456848 (diff)
downloadmill-1045ed4589e602a2727c7ba014b820e134100e1f.tar.gz
mill-1045ed4589e602a2727c7ba014b820e134100e1f.tar.bz2
mill-1045ed4589e602a2727c7ba014b820e134100e1f.zip
First pass at an `assembly` task now works, rudimentary but enough to be used metacircularly
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/scala/mill/Main.scala2
-rw-r--r--core/src/main/scala/mill/modules/Jvm.scala59
2 files changed, 57 insertions, 4 deletions
diff --git a/core/src/main/scala/mill/Main.scala b/core/src/main/scala/mill/Main.scala
index 9e7a9d11..9a3ade04 100644
--- a/core/src/main/scala/mill/Main.scala
+++ b/core/src/main/scala/mill/Main.scala
@@ -38,7 +38,7 @@ object Main {
case _ => // do nothing
}
- case None => println("Unknown selector: " + selector)
+ case None => println("Unknown selector: " + selector.mkString("."))
}
}
}
diff --git a/core/src/main/scala/mill/modules/Jvm.scala b/core/src/main/scala/mill/modules/Jvm.scala
index f18e2d96..63f335f5 100644
--- a/core/src/main/scala/mill/modules/Jvm.scala
+++ b/core/src/main/scala/mill/modules/Jvm.scala
@@ -1,13 +1,15 @@
package mill.modules
import java.io.FileOutputStream
-import java.util.jar.{JarEntry, JarOutputStream}
+import java.util.jar.{JarEntry, JarFile, JarInputStream, JarOutputStream}
import ammonite.ops._
import mill.define.Task
import mill.eval.PathRef
import mill.util.Args
+import scala.collection.mutable
+
object Jvm {
@@ -43,8 +45,8 @@ object Jvm {
for{
p <- inputPaths
(file, mapping) <-
- if (p.isFile) Iterator(p -> empty/p.last)
- else ls.rec(p).filter(_.isFile).map(sub => sub -> sub.relativeTo(p))
+ if (p.isFile) Iterator(p -> empty/p.last)
+ else ls.rec(p).filter(_.isFile).map(sub => sub -> sub.relativeTo(p))
} {
val entry = new JarEntry(mapping.toString)
entry.setTime(file.mtime.toMillis)
@@ -59,6 +61,57 @@ object Jvm {
Some(outputPath)
}
}
+
+
+ def createAssembly(outputPath: Path,
+ inputPaths: Seq[Path],
+ mainClass: Option[String] = None): Option[Path] = {
+ rm(outputPath)
+
+ if(inputPaths.isEmpty) None
+ else {
+ mkdir(outputPath/up)
+
+ val jar = new JarOutputStream(
+ new FileOutputStream(outputPath.toIO),
+ createManifest(mainClass)
+ )
+
+ val seen = mutable.Set("META-INF/MANIFEST.MF")
+ try{
+ assert(inputPaths.forall(exists(_)))
+ for{
+ p <- inputPaths
+
+ (file, mapping) <-
+ if (p.isFile) {
+ val jf = new JarFile(p.toIO)
+ import collection.JavaConverters._
+ for(entry <- jf.entries().asScala if !entry.isDirectory) yield {
+ read.bytes(jf.getInputStream(entry)) -> entry.getName
+ }
+ }
+ else {
+ ls.rec(p).iterator
+ .filter(_.isFile)
+ .map(sub => read.bytes(sub) -> sub.relativeTo(p).toString)
+ }
+ if !seen(mapping)
+ } {
+ seen.add(mapping)
+ val entry = new JarEntry(mapping.toString)
+ jar.putNextEntry(entry)
+ jar.write(file)
+ jar.closeEntry()
+ }
+ } finally {
+ jar.close()
+ }
+
+ Some(outputPath)
+ }
+ }
+
def jarUp(roots: Task[PathRef]*) = new Task[PathRef]{
val inputs = roots