diff --git a/core/src/main/scala/com/eed3si9n/jarjarabrams/Main.scala b/core/src/main/scala/com/eed3si9n/jarjarabrams/Main.scala index 2070bda..b12f792 100644 --- a/core/src/main/scala/com/eed3si9n/jarjarabrams/Main.scala +++ b/core/src/main/scala/com/eed3si9n/jarjarabrams/Main.scala @@ -16,13 +16,15 @@ class Main { case Some(_) => java.lang.Boolean.getBoolean("resetTimestamp") case None => true } + val warnOnDuplicateClass = java.lang.Boolean.getBoolean("duplicateClassToWarn") Shader.shadeFile( Shader.parseRulesFile(rulesFile), inJar, outJar, verbose, skipManifest, - resetTimestamp + resetTimestamp, + warnOnDuplicateClass ) } } diff --git a/core/src/main/scala/com/eed3si9n/jarjarabrams/Shader.scala b/core/src/main/scala/com/eed3si9n/jarjarabrams/Shader.scala index 981cd87..f6cccaf 100644 --- a/core/src/main/scala/com/eed3si9n/jarjarabrams/Shader.scala +++ b/core/src/main/scala/com/eed3si9n/jarjarabrams/Shader.scala @@ -13,10 +13,11 @@ object Shader { outputJar: Path, verbose: Boolean, skipManifest: Boolean, - resetTimestamp: Boolean + resetTimestamp: Boolean, + warnOnDuplicateClass: Boolean ): Unit = { val shader = bytecodeShader(rules, verbose, skipManifest) - Zip.transformJarFile(inputJar, outputJar, resetTimestamp) { struct0 => + Zip.transformJarFile(inputJar, outputJar, resetTimestamp, warnOnDuplicateClass) { struct0 => shader(struct0.data, struct0.name).map { case (shadedBytes, shadedName) => Zip.entryStruct(shadedName, struct0.time, shadedBytes, struct0.skipTransform) diff --git a/core/src/main/scala/com/eed3si9n/jarjarabrams/Zip.scala b/core/src/main/scala/com/eed3si9n/jarjarabrams/Zip.scala index 672d0a9..1bc3df5 100644 --- a/core/src/main/scala/com/eed3si9n/jarjarabrams/Zip.scala +++ b/core/src/main/scala/com/eed3si9n/jarjarabrams/Zip.scala @@ -1,6 +1,6 @@ package com.eed3si9n.jarjarabrams -import com.eed3si9n.jarjar.util.EntryStruct +import com.eed3si9n.jarjar.util.{ DuplicateJarEntryException, EntryStruct } import java.nio.file.{ Files, NoSuchFileException, Path, StandardCopyOption } import java.nio.file.attribute.FileTime import java.io.{ ByteArrayOutputStream, FileNotFoundException, InputStream, OutputStream } @@ -46,7 +46,8 @@ object Zip { def transformJarFile( inputJar: Path, outputJar: Path, - resetTimestamp: Boolean + resetTimestamp: Boolean, + warnOnDuplicateClass: Boolean )(f: EntryStruct => Option[EntryStruct]): Path = Using.jarFile(inputJar) { in => val tempJar = Files.createTempFile("jarjar", ".jar") @@ -72,8 +73,11 @@ object Zip { out.write(struct.data) } else if (struct.name.endsWith("/")) () else { - // duplicate entry - // throw? + if (warnOnDuplicateClass) + Console.err.println( + s"in ${inputJar}, found duplicate files with name: ${struct.name}, ignoring due to specified option" + ) + else throw new DuplicateJarEntryException(inputJar.toString, struct.name) } case None => () } diff --git a/core/src/test/scala/testpkg/ShaderTest.scala b/core/src/test/scala/testpkg/ShaderTest.scala index f20d04d..9247516 100644 --- a/core/src/test/scala/testpkg/ShaderTest.scala +++ b/core/src/test/scala/testpkg/ShaderTest.scala @@ -60,7 +60,8 @@ object ShaderTest extends BasicTestSuite { tempJar, verbose = false, skipManifest = false, - resetTimestamp + resetTimestamp, + warnOnDuplicateClass = false ) val entries = Zip.list(tempJar).map(_._1) assert(entries.contains(expectedClass))