Skip to content

Commit

Permalink
Merge pull request #40 from eed3si9n/wip/duplicate
Browse files Browse the repository at this point in the history
Throw on duplicates like jarjar
  • Loading branch information
eed3si9n authored Oct 19, 2023
2 parents b0dbf0f + d8a70b3 commit 8629ce2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 3 additions & 1 deletion core/src/main/scala/com/eed3si9n/jarjarabrams/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/scala/com/eed3si9n/jarjarabrams/Shader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions core/src/main/scala/com/eed3si9n/jarjarabrams/Zip.scala
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down Expand Up @@ -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")
Expand All @@ -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 => ()
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/scala/testpkg/ShaderTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 8629ce2

Please sign in to comment.