-
Notifications
You must be signed in to change notification settings - Fork 21
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
eed3si9n
merged 1 commit into
eed3si9n:develop
from
shanielh:feature/keep-processor-process-whole-files
Dec 16, 2022
+25
−25
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,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) { | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.