diff options
author | Zhi Dou <zhidou@google.com> | 2024-02-28 21:43:06 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2024-02-28 21:43:06 +0000 |
commit | 7b924baddfa25e2689efa6c7d0c5cc70f6446b0b (patch) | |
tree | d79fd260420ca7f26993cadb057551a2bdd75fcf | |
parent | f5d0558baf5576c66a387f003cbb321835e01fe4 (diff) | |
parent | a02a943a3bcb57a1aa7ec12cd5951ac139a595fb (diff) | |
download | jarjar-main.tar.gz |
Original change: https://android-review.googlesource.com/c/platform/external/jarjar/+/2982311
Change-Id: Ia06021992185f83de2b5145dc4da88338d7c0b29
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | src/main/com/tonicsystems/jarjar/util/EntryStruct.java | 24 | ||||
-rw-r--r-- | src/main/com/tonicsystems/jarjar/util/StandaloneJarProcessor.java | 11 |
2 files changed, 30 insertions, 5 deletions
diff --git a/src/main/com/tonicsystems/jarjar/util/EntryStruct.java b/src/main/com/tonicsystems/jarjar/util/EntryStruct.java index 9478ac8..36f9b76 100644 --- a/src/main/com/tonicsystems/jarjar/util/EntryStruct.java +++ b/src/main/com/tonicsystems/jarjar/util/EntryStruct.java @@ -16,6 +16,9 @@ package com.tonicsystems.jarjar.util; +import java.util.Arrays; +import java.util.Objects; + public class EntryStruct { public byte[] data; public String name; @@ -32,4 +35,25 @@ public class EntryStruct { } return true; } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + + if (!(other instanceof EntryStruct)) { + return false; + } + + EntryStruct that = (EntryStruct) other; + return this.name.equals(that.name) && + Arrays.equals(this.data, that.data) && + this.time == that.time; + } + + @Override + public int hashCode() { + return Objects.hash(Arrays.hashCode(data), name, time); + } } diff --git a/src/main/com/tonicsystems/jarjar/util/StandaloneJarProcessor.java b/src/main/com/tonicsystems/jarjar/util/StandaloneJarProcessor.java index b91b6f9..2e87104 100644 --- a/src/main/com/tonicsystems/jarjar/util/StandaloneJarProcessor.java +++ b/src/main/com/tonicsystems/jarjar/util/StandaloneJarProcessor.java @@ -21,8 +21,8 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Enumeration; -import java.util.HashSet; -import java.util.Set; +import java.util.HashMap; +import java.util.Map; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.jar.JarOutputStream; @@ -34,7 +34,7 @@ public final class StandaloneJarProcessor { JarFile in = new JarFile(from); final File tmpTo = File.createTempFile("jarjar", ".jar"); JarOutputStream out = new JarOutputStream(new FileOutputStream(tmpTo)); - Set<String> entries = new HashSet<>(); + Map<String, EntryStruct> entries = new HashMap<>(); try { EntryStruct struct = new EntryStruct(); Enumeration<JarEntry> e = in.entries(); @@ -46,7 +46,8 @@ public final class StandaloneJarProcessor { IoUtil.pipe(in.getInputStream(entry), baos, buf); struct.data = baos.toByteArray(); if (proc.process(struct)) { - if (entries.add(struct.name)) { + EntryStruct existEntry = entries.putIfAbsent(struct.name, struct); + if (existEntry == null) { entry = new JarEntry(struct.name); entry.setTime(struct.time); entry.setCompressedSize(-1); @@ -54,7 +55,7 @@ public final class StandaloneJarProcessor { out.write(struct.data); } else if (struct.name.endsWith("/")) { // TODO(chrisn): log - } else { + } else if (!existEntry.equals(struct)) { throw new IllegalArgumentException("Duplicate jar entries: " + struct.name); } } |