Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

KeepProcessor: Process files that are not in wildcard #28

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions jarjar/src/main/java/com/eed3si9n/jarjar/KeepProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -41,50 +40,51 @@ public boolean isEnabled() {

public Set<String> getExcludes() {
Set<String> closure = new HashSet<String>();
closureHelper(closure, roots);
recursiveProcessDependencies(closure, roots);

Set<String> removable = new HashSet<String>(depend.keySet());
removable.removeAll(closure);
return removable;
}

private void closureHelper(Set<String> closure, Collection<String> process) {
if (process == null)
private void recursiveProcessDependencies(Set<String> result, Collection<String> roots) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method was just renamed to be more readable, let me know if you want me to undo this.

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<String> curSet;
private byte[] buf = new byte[0x2000];
private Set<String> currentDependenciesSet;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also renamed for better readability


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<String>());
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<String>());
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;
}

public String map(String key) {
if (key.startsWith("java/") || key.startsWith("javax/"))
return null;
curSet.add(key);
currentDependenciesSet.add(key);
return null;
}

Expand Down