diff --git a/jarjar/src/main/java/com/eed3si9n/jarjar/KeepProcessor.java b/jarjar/src/main/java/com/eed3si9n/jarjar/KeepProcessor.java index 153622c2..2be03648 100644 --- a/jarjar/src/main/java/com/eed3si9n/jarjar/KeepProcessor.java +++ b/jarjar/src/main/java/com/eed3si9n/jarjar/KeepProcessor.java @@ -20,7 +20,6 @@ import java.io.*; import java.util.*; import org.objectweb.asm.*; -import org.objectweb.asm.Type; import org.objectweb.asm.commons.*; // TODO: this can probably be refactored into JarClassVisitor, etc. @@ -41,42 +40,43 @@ public boolean isEnabled() { public Set getExcludes() { Set closure = new HashSet(); - closureHelper(closure, roots); + recursiveProcessDependencies(closure, roots); + Set removable = new HashSet(depend.keySet()); removable.removeAll(closure); return removable; } - private void closureHelper(Set closure, Collection process) { - if (process == null) + private void recursiveProcessDependencies(Set result, Collection roots) { + if (roots == null) return; - for (String name : process) { - if (closure.add(name)) - closureHelper(closure, depend.get(name)); + for (String name : roots) { + if (result.add(name)) + recursiveProcessDependencies(result, depend.get(name)); } } - private Set curSet; - private byte[] buf = new byte[0x2000]; + private Set currentDependenciesSet; public boolean process(EntryStruct struct) throws IOException { - try { - if (struct.name.endsWith(".class")) { - String name = struct.name.substring(0, struct.name.length() - 6); - for (Wildcard wildcard : wildcards) { - if (wildcard.matches(name)) { - roots.add(name); - depend.put(name, curSet = new HashSet()); - new ClassReader(new ByteArrayInputStream(struct.data)).accept(cv, - ClassReader.EXPAND_FRAMES); - curSet.remove(name); - return true; - } + if (struct.name.endsWith(".class")) { + String name = struct.name.substring(0, struct.name.length() - 6); + depend.put(name, currentDependenciesSet = new HashSet()); + try { + new ClassReader(new ByteArrayInputStream(struct.data)).accept(cv, + ClassReader.EXPAND_FRAMES); + currentDependenciesSet.remove(name); + } catch (Exception e) { + System.err.println("Error reading " + struct.name + ": " + e.getMessage()); + } + + for (Wildcard wildcard : wildcards) { + if (wildcard.matches(name)) { + roots.add(name); + return true; } - return false; } - } catch (Exception e) { - System.err.println("Error reading " + struct.name + ": " + e.getMessage()); + return false; } return true; } @@ -84,7 +84,7 @@ public boolean process(EntryStruct struct) throws IOException { public String map(String key) { if (key.startsWith("java/") || key.startsWith("javax/")) return null; - curSet.add(key); + currentDependenciesSet.add(key); return null; }