diff options
-rw-r--r-- | build.sbt | 9 | ||||
-rw-r--r-- | project/build.sbt | 1 | ||||
-rw-r--r-- | src/main/scala/forge/Main.scala | 18 | ||||
-rw-r--r-- | src/test/examples/javac/build.sc | 66 |
4 files changed, 94 insertions, 0 deletions
@@ -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] |