-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created a routine to search for .class files in directories in the cl… #380
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,8 +75,7 @@ private ClassList() throws JepException { | |
} | ||
|
||
/** | ||
* load jar files from class path | ||
* | ||
* load .jar files and .class files from class path | ||
*/ | ||
private void loadClassPath() { | ||
StringTokenizer tok = new StringTokenizer( | ||
|
@@ -95,16 +94,23 @@ private void loadClassPath() { | |
while (!queue.isEmpty()) { | ||
String el = queue.remove(); | ||
|
||
if (!el.toLowerCase().endsWith(".jar")) { | ||
// ignore filesystem classpath | ||
// make sure it exists | ||
File file = new File(el); | ||
|
||
// A directory is a special case. | ||
if (file.isDirectory()) { | ||
// search for all .class files recursively starting with no prefix. | ||
addClassFilesInTree(file, ""); | ||
continue; | ||
} | ||
|
||
// make sure it exists | ||
File file = new File(el); | ||
if (!file.exists() || !file.canRead()) | ||
continue; | ||
|
||
// The .jar file is the normal case. | ||
if (!el.toLowerCase().endsWith(".jar")) | ||
continue; | ||
|
||
try (JarFile jfile = new JarFile(el, false)) { | ||
|
||
// add entries from manifest to check later | ||
|
@@ -159,6 +165,31 @@ private void loadClassPath() { | |
} | ||
} | ||
|
||
/** | ||
* Recursively go through a folder and all subdirectories looking for .class | ||
* files. Add them all. | ||
*/ | ||
private void addClassFilesInTree(File folder, String prefix) { | ||
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. Can you add javadoc |
||
if (!folder.isDirectory()) { | ||
throw new IllegalArgumentException("folder is not a Directory"); | ||
} | ||
for (File file : folder.listFiles()) { | ||
String entry = file.getName(); | ||
if (file.isDirectory()) { | ||
if (prefix!=null && !prefix.isEmpty()) { | ||
// Include a . between directories only if there was a prefix. | ||
addClassFilesInTree(file, prefix+"."+entry); | ||
} else { | ||
// Don't include a prefix--we only care about subdirectories. | ||
addClassFilesInTree(file, entry); | ||
} | ||
} else if (file.exists() && file.canRead() && entry.toLowerCase().endsWith(".class")) { | ||
// We've found a .class file on the file system. Add it. | ||
addClass(prefix, entry.replaceAll(".class$", "")); | ||
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. Do you need the $ here? I don't understand why that's there. 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. That is the regex end of line character. I don't think there is a legal java filename with .class in the middle but it is pretty standard for ensuring you only modify the extension. 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. Thanks. |
||
} | ||
} | ||
} | ||
|
||
/* | ||
* the jre will tell us about what jar files it has open. use that facility | ||
* to get a list of packages. then read the files ourselves since java won't | ||
|
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.
I think this check for file existence and readability should continue to be right after the File object is newed, and therefore before the file.isDirectory() check.