-
Notifications
You must be signed in to change notification settings - Fork 69
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
Remove laziness in Slamhound's "get-available-classes" #184
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -75,18 +75,20 @@ | |
[#^File f #^File loc] | ||
(let [lp (.getPath loc)] | ||
(try | ||
(map class-or-ns-name | ||
(filter class-file? | ||
(map #(.getName #^JarEntry %) | ||
(enumeration-seq (.entries (JarFile. f)))))) | ||
(into () | ||
(comp | ||
(map #(.getName #^JarEntry %)) | ||
(filter class-file?) | ||
(map class-or-ns-name)) | ||
(enumeration-seq (.entries (JarFile. f)))) | ||
(catch Exception e [])))) ; fail gracefully if jar is unreadable | ||
|
||
(defmethod path-class-files :dir | ||
;; Dispatch directories and files (excluding jars) recursively. | ||
[#^File d #^File loc] | ||
(let [fs (.listFiles d (proxy [FilenameFilter] [] | ||
(accept [d n] (not (jar? (file n))))))] | ||
(reduce concat (for [f fs] (path-class-files f loc))))) | ||
(into () (mapcat #(path-class-files % loc)) fs))) | ||
|
||
(defmethod path-class-files :class | ||
;; Build class info using file path relative to parent classpath entry | ||
|
@@ -99,26 +101,28 @@ | |
[(class-or-ns-name fpr)]) | ||
[]))) | ||
|
||
(defn scan-paths | ||
"Takes one or more classpath strings, scans each classpath entry location, and | ||
returns a list of all class file paths found, each relative to its parent | ||
directory or jar on the classpath." | ||
([cp] | ||
(if cp | ||
(let [entries (enumeration-seq | ||
(StringTokenizer. cp File/pathSeparator)) | ||
locs (mapcat expand-wildcard entries)] | ||
(mapcat #(path-class-files % %) locs)) | ||
()))) | ||
|
||
(defn- get-available-classes | ||
[] | ||
(->> (mapcat scan-paths (concat (map #(System/getProperty %) ["sun.boot.class.path" | ||
"java.ext.dirs" | ||
"java.class.path"]) | ||
(map #(.getName %) (cp/classpath-jarfiles)))) | ||
(remove clojure-fn-file?) | ||
(map symbol))) | ||
(defn path-entries-seq | ||
"Split a string on the 'path separator', i.e. ':'. Used for splitting multiple | ||
classpath entries." | ||
[path-str] | ||
(enumeration-seq | ||
(StringTokenizer. path-str File/pathSeparator))) | ||
|
||
(defn all-classpath-entries [] | ||
(into (map #(System/getProperty %) ["sun.boot.class.path" | ||
"java.ext.dirs" | ||
"java.class.path"]) | ||
(map #(.getName %) (cp/classpath-jarfiles)))) | ||
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. I just copied this logic over, although it seems strange to me that this is really the way to get the full classpath. |
||
|
||
(defn- get-available-classes [] | ||
(into () | ||
(comp (mapcat path-entries-seq) | ||
(mapcat expand-wildcard) | ||
(mapcat #(path-class-files % %)) | ||
(remove clojure-fn-file?) | ||
(distinct) | ||
(map symbol)) | ||
(all-classpath-entries))) | ||
|
||
(def available-classes | ||
(get-available-classes)) | ||
|
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 line was actually asking for trouble..
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.
yup.