summaryrefslogtreecommitdiff
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
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`
-rw-r--r--build.sbt9
-rw-r--r--project/build.sbt1
-rw-r--r--src/main/scala/forge/Main.scala18
-rw-r--r--src/test/examples/javac/build.sc66
4 files changed, 94 insertions, 0 deletions
diff --git a/build.sbt b/build.sbt
index 962eda45..469308c7 100644
--- a/build.sbt
+++ b/build.sbt
@@ -48,3 +48,12 @@ sourceGenerators in Compile += Def.task {
IO.write(file, output)
Seq(file)
}
+
+test in assembly := {}
+
+assemblyOption in assembly := (assemblyOption in assembly).value.copy(
+ prependShellScript = Some(
+ // G1 Garbage Collector is awesome https://github.com/lihaoyi/Ammonite/issues/216
+ Seq("#!/usr/bin/env sh", """exec java -jar -Xmx500m -XX:+UseG1GC $JAVA_OPTS "$0" "$@"""")
+ )
+) \ No newline at end of file
diff --git a/project/build.sbt b/project/build.sbt
new file mode 100644
index 00000000..1741de9d
--- /dev/null
+++ b/project/build.sbt
@@ -0,0 +1 @@
+addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3") \ No newline at end of file
diff --git a/src/main/scala/forge/Main.scala b/src/main/scala/forge/Main.scala
index 07905ac9..d919d0e2 100644
--- a/src/main/scala/forge/Main.scala
+++ b/src/main/scala/forge/Main.scala
@@ -1,7 +1,25 @@
package forge
+import ammonite.ops._
+import ammonite.util.{Name, Res}
+import forge.util.OSet
+
+
object Main {
def main(args: Array[String]): Unit = {
+ ammonite.Main().instantiateInterpreter() match{
+ case Right(interp) =>
+ val result = ammonite.main.Scripts.runScript(pwd, Path(args(0), pwd), interp, Nil)
+
+ val (obj, discovered) = result.asInstanceOf[Res.Success[(Any, forge.Discovered[Any])]].s
+ val mapping = Discovered.mapping(obj)(discovered)
+ val workspacePath = pwd / 'target / 'javac
+ val evaluator = new Evaluator(workspacePath, mapping)
+ val evaluated = evaluator.evaluate(OSet.from(mapping.keys)).evaluated.filter(mapping.contains)
+ (result, interp.watchedFiles)
+ case Left(problems) => problems
+ }
}
+
}
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]