summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-10-28 07:52:26 -0700
committerLi Haoyi <haoyi.sg@gmail.com>2017-10-28 07:52:26 -0700
commitfe0579918b9a9d5530f27a0a1bea466d3f487c3c (patch)
treebeffb8b5c2ac37da556cb18fb65ddd68b38b0a97
parentb1a682a400922506a2bb7e42e0597625a8cbca16 (diff)
downloadmill-fe0579918b9a9d5530f27a0a1bea466d3f487c3c.tar.gz
mill-fe0579918b9a9d5530f27a0a1bea466d3f487c3c.tar.bz2
mill-fe0579918b9a9d5530f27a0a1bea466d3f487c3c.zip
Move java-compile example supporting code into test suite
-rw-r--r--src/main/scala/forge/ReadWrite.scala20
-rw-r--r--src/main/scala/forge/Util.scala42
-rw-r--r--src/test/scala/forge/EvaluationTests.scala11
-rw-r--r--src/test/scala/forge/Main.scala58
4 files changed, 59 insertions, 72 deletions
diff --git a/src/main/scala/forge/ReadWrite.scala b/src/main/scala/forge/ReadWrite.scala
deleted file mode 100644
index ee74f35f..00000000
--- a/src/main/scala/forge/ReadWrite.scala
+++ /dev/null
@@ -1,20 +0,0 @@
-package forge
-import java.nio.{file => jnio}
-
-trait ReadWrite[T] {
- def write(t: T, p: jnio.Path): Unit
- def read(p: jnio.Path): T
-}
-
-object ReadWrite{
- implicit object String extends ReadWrite[java.lang.String]{
- def write(t: String, p: jnio.Path) = {
- jnio.Files.createDirectories(p.getParent)
- jnio.Files.deleteIfExists(p)
- jnio.Files.write(p, t.getBytes)
- }
- def read(p: jnio.Path) = {
- new String(jnio.Files.readAllBytes(p))
- }
- }
-}
diff --git a/src/main/scala/forge/Util.scala b/src/main/scala/forge/Util.scala
index e558e975..57e738bc 100644
--- a/src/main/scala/forge/Util.scala
+++ b/src/main/scala/forge/Util.scala
@@ -109,46 +109,4 @@ class MutableOSet[V](dedup: Boolean = false) extends OSet[V]{
case _ => super.equals(other)
}
override def toString = items.mkString("OSet(", ", ", ")")
-}
-object Util{
- def compileAll(sources: Target[Seq[jnio.Path]])
- (implicit defCtx: DefCtx) = {
- new Target.Subprocess(
- Seq(sources),
- args =>
- Seq("javac") ++
- args[Seq[jnio.Path]](0).map(_.toAbsolutePath.toString) ++
- Seq("-d", args.dest.toAbsolutePath.toString),
- defCtx
- ).map(_.dest)
- }
-
- def list(root: Target[jnio.Path])(implicit defCtx: DefCtx): Target[Seq[jnio.Path]] = {
- root.map(jnio.Files.list(_).iterator().asScala.toArray[jnio.Path])
- }
- case class jarUp(roots: Target[jnio.Path]*)(implicit val defCtx: DefCtx) extends Target[jnio.Path]{
-
- val inputs = roots
- def evaluate(args: Args): jnio.Path = {
-
- val output = new java.util.jar.JarOutputStream(new FileOutputStream(args.dest.toFile))
- for{
- root0 <- args.args
- root = root0.asInstanceOf[jnio.Path]
-
- path <- jnio.Files.walk(root).iterator().asScala
- if jnio.Files.isRegularFile(path)
- }{
- val relative = root.relativize(path)
- output.putNextEntry(new JarEntry(relative.toString))
- output.write(jnio.Files.readAllBytes(path))
- }
- output.close()
- args.dest
- }
-
-
- }
-
-
} \ No newline at end of file
diff --git a/src/test/scala/forge/EvaluationTests.scala b/src/test/scala/forge/EvaluationTests.scala
index 0ae5f62a..97d85660 100644
--- a/src/test/scala/forge/EvaluationTests.scala
+++ b/src/test/scala/forge/EvaluationTests.scala
@@ -110,13 +110,8 @@ object EvaluationTests extends TestSuite{
}
-// 'full - {
-// val sourceRoot = Target.path(jnio.Paths.get("src/test/resources/example/src"))
-// val resourceRoot = Target.path(jnio.Paths.get("src/test/resources/example/resources"))
-// val allSources = list(sourceRoot)
-// val classFiles = compileAll(allSources)
-// val jar = jarUp(resourceRoot, classFiles)
-// Evaluator.apply(jar, jnio.Paths.get("target/workspace"))
-// }
+ 'full - {
+
+ }
}
}
diff --git a/src/test/scala/forge/Main.scala b/src/test/scala/forge/Main.scala
index 745a9029..d9262627 100644
--- a/src/test/scala/forge/Main.scala
+++ b/src/test/scala/forge/Main.scala
@@ -1,7 +1,61 @@
package forge
-
+import java.io.FileOutputStream
+import java.nio.{file => jnio}
+import java.util.jar.JarEntry
+import collection.JavaConverters._
object Main{
+
def main(args: Array[String]): Unit = {
+ val sourceRoot = T{ Target.path(jnio.Paths.get("src/test/resources/example/src")) }
+ val resourceRoot = T{ Target.path(jnio.Paths.get("src/test/resources/example/resources")) }
+ val allSources = T{ list(sourceRoot) }
+ val classFiles = T{ compileAll(allSources) }
+ val jar = T{ jarUp(resourceRoot, classFiles) }
+
+ val evaluator = new Evaluator(
+ jnio.Paths.get("target/workspace"),
+ DefCtx("forge.Main ", None)
+ )
+ evaluator.evaluate(OSet(jar))
+ }
+ def compileAll(sources: Target[Seq[jnio.Path]])
+ (implicit defCtx: DefCtx) = {
+ new Target.Subprocess(
+ Seq(sources),
+ args =>
+ Seq("javac") ++
+ args[Seq[jnio.Path]](0).map(_.toAbsolutePath.toString) ++
+ Seq("-d", args.dest.toAbsolutePath.toString),
+ defCtx
+ ).map(_.dest)
}
-} \ No newline at end of file
+
+ def list(root: Target[jnio.Path])(implicit defCtx: DefCtx): Target[Seq[jnio.Path]] = {
+ root.map(jnio.Files.list(_).iterator().asScala.toArray[jnio.Path])
+ }
+ case class jarUp(roots: Target[jnio.Path]*)(implicit val defCtx: DefCtx) extends Target[jnio.Path]{
+
+ val inputs = roots
+ def evaluate(args: Args): jnio.Path = {
+
+ val output = new java.util.jar.JarOutputStream(new FileOutputStream(args.dest.toFile))
+ for{
+ root0 <- args.args
+ root = root0.asInstanceOf[jnio.Path]
+
+ path <- jnio.Files.walk(root).iterator().asScala
+ if jnio.Files.isRegularFile(path)
+ }{
+ val relative = root.relativize(path)
+ output.putNextEntry(new JarEntry(relative.toString))
+ output.write(jnio.Files.readAllBytes(path))
+ }
+ output.close()
+ args.dest
+ }
+
+
+ }
+
+}