From 62f346b6574a72d236b04ba8744b7a8ea2bcdfe2 Mon Sep 17 00:00:00 2001 From: Stefan Zeiger Date: Wed, 11 Nov 2015 15:38:08 +0100 Subject: Fix JarJar “Keep” processing in sbt build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is not enough to check the return value of `process()` to determine whether a class file should be kept or deleted. The classes that should not be kept are only known after processing everything and files that have already been written to disk may need to be deleted. --- project/JarJar.scala | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'project') diff --git a/project/JarJar.scala b/project/JarJar.scala index 64281f23c1..2eec0e9033 100644 --- a/project/JarJar.scala +++ b/project/JarJar.scala @@ -55,7 +55,7 @@ object JarJar { def apply(in: Iterator[Entry], outdir: File, config: Seq[JarJarConfig], verbose: Boolean = false): Seq[File] = { val patterns = config.map(_.toPatternElement).asJava - val processor: JarProcessor = newMainProcessor(patterns, verbose, false) + val processor = newMainProcessor(patterns, verbose, false) def process(e: Entry): Option[File] = { val struct = new EntryStruct() struct.name = e.name @@ -77,7 +77,16 @@ object JarJar { } else None } - in.flatMap(entry => process(entry)).toList - + val processed = in.flatMap(entry => process(entry)).toSet + val getter = processor.getClass.getDeclaredMethod("getExcludes") + getter.setAccessible(true) + val excludes = getter.invoke(processor).asInstanceOf[java.util.Set[String]].asScala + val excluded = excludes.map { name => + val f: File = outdir / name + if(f.exists && !f.delete()) + throw new IOException("Failed to delete excluded file $f") + f + } + (processed -- excluded).toSeq } } -- cgit v1.2.3