summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-10-29 18:29:53 -0700
committerLi Haoyi <haoyi.sg@gmail.com>2017-10-29 18:29:53 -0700
commitf32fca9c5858c487a83bf461d5b2ecc772025a4a (patch)
tree386b056adf594fe02f2dfd603aabdc1833165b08 /src/test
parent4e2fbfb5ae8fd7d66f78bf7ced3d6cc8cc74ceaf (diff)
downloadmill-f32fca9c5858c487a83bf461d5b2ecc772025a4a.tar.gz
mill-f32fca9c5858c487a83bf461d5b2ecc772025a4a.tar.bz2
mill-f32fca9c5858c487a83bf461d5b2ecc772025a4a.zip
First builds work going through an Ammonite script, currently run using `sbt "~run src/test/examples/javac/build.sc`
Diffstat (limited to 'src/test')
-rw-r--r--src/test/examples/javac/build.sc66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/test/examples/javac/build.sc b/src/test/examples/javac/build.sc
new file mode 100644
index 00000000..dfbe5271
--- /dev/null
+++ b/src/test/examples/javac/build.sc
@@ -0,0 +1,66 @@
+object Foo {
+
+ import java.io.FileOutputStream
+ import java.util.jar.JarEntry
+
+ import ammonite.ops.{ls, pwd, read}
+ import forge.{Discovered, Target}
+ import forge.util.{Args, PathRef}
+
+ val workspacePath = pwd / 'target / 'workspace / 'javac
+ val javacSrcPath = pwd / 'src / 'test / 'examples / 'javac
+ val javacDestPath = workspacePath / 'src
+
+ val sourceRootPath = javacDestPath / 'src
+ val resourceRootPath = javacDestPath / 'resources
+
+ // sourceRoot -> allSources -> classFiles
+ // |
+ // v
+ // resourceRoot ----> jar
+ val sourceRoot = Target.path(sourceRootPath)
+ val resourceRoot = Target.path(resourceRootPath)
+ val allSources = list(sourceRoot)
+ val classFiles = compileAll(allSources)
+ val jar = jarUp(resourceRoot, classFiles)
+
+ def compileAll(sources: Target[Seq[PathRef]]) = {
+ new Target.Subprocess(
+ Seq(sources),
+ args =>
+ Seq("javac") ++
+ args[Seq[PathRef]](0).map(_.path.toString) ++
+ Seq("-d", args.dest.toString)
+ ).map(_.dest)
+ }
+
+ def list(root: Target[PathRef]): Target[Seq[PathRef]] = {
+ root.map(x => ls.rec(x.path).map(PathRef(_)))
+ }
+
+ case class jarUp(roots: Target[PathRef]*) extends Target[PathRef] {
+
+ val inputs = roots
+
+ def evaluate(args: Args): PathRef = {
+
+ val output = new java.util.jar.JarOutputStream(new FileOutputStream(args.dest.toIO))
+ for {
+ root0 <- args.args
+ root = root0.asInstanceOf[PathRef]
+
+ path <- ls.rec(root.path)
+ if path.isFile
+ } {
+ val relative = path.relativeTo(root.path)
+ output.putNextEntry(new JarEntry(relative.toString))
+ output.write(read.bytes(path))
+ }
+ output.close()
+ PathRef(args.dest)
+ }
+ }
+
+}
+
+@main def main(): Any = Foo -> forge.Discovered[Foo.type]