From f3ec25bccab8ee94ad30d86b56d7cc3c3ca610a4 Mon Sep 17 00:00:00 2001 From: Jim Lawson Date: Tue, 9 Oct 2018 10:16:59 -0700 Subject: Add a filter parameter (default true for all files) to createJar(). Add createJar() filter test. --- main/test/src/mill/eval/JavaCompileJarTests.scala | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'main/test') diff --git a/main/test/src/mill/eval/JavaCompileJarTests.scala b/main/test/src/mill/eval/JavaCompileJarTests.scala index 37e4c119..e6d1c10a 100644 --- a/main/test/src/mill/eval/JavaCompileJarTests.scala +++ b/main/test/src/mill/eval/JavaCompileJarTests.scala @@ -39,6 +39,8 @@ object JavaCompileJarTests extends TestSuite{ def allSources = T{ sourceRoot().flatMap(p => ls.rec(p.path)).map(PathRef(_)) } def classFiles = T{ compileAll(allSources()) } def jar = T{ Jvm.createJar(Loose.Agg(classFiles().path) ++ resourceRoot().map(_.path)) } + // Test createJar() with optional file filter. + def filterJar(fileFilter: (Path, RelPath) => Boolean) = T{ Jvm.createJar(Loose.Agg(classFiles().path) ++ resourceRoot().map(_.path), None, fileFilter) } def run(mainClsName: String) = T.command{ %%('java, "-Duser.language=en", "-cp", classFiles().path, mainClsName) @@ -116,6 +118,13 @@ object JavaCompileJarTests extends TestSuite{ |""".stripMargin assert(jarContents.lines.toSeq == expectedJarContents.lines.toSeq) + // Create the Jar again, but this time, filter out the Foo files. + def noFoos(s: String) = !s.contains("Foo") + val filterFunc = (p: Path, r: RelPath) => noFoos(r.last) + filterJar(filterFunc) + val filteredJarContents = %%('jar, "-tf", evaluator.outPath/'filterJar/'dest/"out.jar")(evaluator.outPath).out.string + assert(filteredJarContents.lines.toSeq == expectedJarContents.lines.filter(noFoos(_)).toSeq) + val executed = %%('java, "-cp", evaluator.outPath/'jar/'dest/"out.jar", "test.Foo")(evaluator.outPath).out.string assert(executed == (31337 + 271828) + System.lineSeparator) -- cgit v1.2.3