diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-03 23:44:39 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-03 23:44:39 -0700 |
commit | 13270145903b457c906a9fa77bd152afb6448ef5 (patch) | |
tree | e85b7ed530e0c8e3c3041cbf17641857c448b602 /core/src/test/examples | |
parent | 66f1c5c2438aeb8f2496575f52c25b09cf5793a6 (diff) | |
download | mill-13270145903b457c906a9fa77bd152afb6448ef5.tar.gz mill-13270145903b457c906a9fa77bd152afb6448ef5.tar.bz2 mill-13270145903b457c906a9fa77bd152afb6448ef5.zip |
Split up forge into `scalaplugin` an `core` subprojects, to allow us to use the `T#apply` macro in the implementation of `scalaplugin.Subproject`
Also needed to implement inter-`Subproject` dependencies so the `MetacircularTests` can continue to support the new layout
Diffstat (limited to 'core/src/test/examples')
-rw-r--r-- | core/src/test/examples/javac/build.sc | 66 | ||||
-rw-r--r-- | core/src/test/examples/javac/resources/hello.txt | 1 | ||||
-rw-r--r-- | core/src/test/examples/javac/src/Bar.java | 4 | ||||
-rw-r--r-- | core/src/test/examples/javac/src/Foo.java | 7 |
4 files changed, 78 insertions, 0 deletions
diff --git a/core/src/test/examples/javac/build.sc b/core/src/test/examples/javac/build.sc new file mode 100644 index 00000000..dfbe5271 --- /dev/null +++ b/core/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] diff --git a/core/src/test/examples/javac/resources/hello.txt b/core/src/test/examples/javac/resources/hello.txt new file mode 100644 index 00000000..5e1c309d --- /dev/null +++ b/core/src/test/examples/javac/resources/hello.txt @@ -0,0 +1 @@ +Hello World
\ No newline at end of file diff --git a/core/src/test/examples/javac/src/Bar.java b/core/src/test/examples/javac/src/Bar.java new file mode 100644 index 00000000..4e30c89b --- /dev/null +++ b/core/src/test/examples/javac/src/Bar.java @@ -0,0 +1,4 @@ +package test; +public class Bar{ + static int value = 271828; +}
\ No newline at end of file diff --git a/core/src/test/examples/javac/src/Foo.java b/core/src/test/examples/javac/src/Foo.java new file mode 100644 index 00000000..e694f9fa --- /dev/null +++ b/core/src/test/examples/javac/src/Foo.java @@ -0,0 +1,7 @@ +package test; +public class Foo{ + static int value = 31337; + public static void main(String[] args){ + System.out.println(value + Bar.value); + } +}
\ No newline at end of file |