Permalink
Browse files

Add 0 arity all-classpath-urls that assumes RT/baseLoader.

  • Loading branch information...
1 parent 7be890e commit 613eccc293629ff0f71ed622006025480ae92e33 @tobias committed Nov 24, 2012
Showing with 15 additions and 7 deletions.
  1. +11 −7 src/dynapath/util.clj
  2. +4 −0 test/dynapath/util_test.clj
View
@@ -21,13 +21,17 @@
(if (readable-classpath? cl)
(dc/classpath-urls cl)))
-(defn all-classpath-urls [cl]
- "Walks up the parentage chain for a ClassLoader, concatenating any URLs it retrieves."
- (->> (iterate #(.getParent %) cl)
- (take-while identity)
- reverse
- (mapcat classpath-urls)
- distinct))
+(defn all-classpath-urls
+ "Walks up the parentage chain for a ClassLoader, concatenating any URLs it retrieves.
+If no ClassLoader is provided, RT/baseLoader is assumed."
+ ([]
+ (all-classpath-urls (clojure.lang.RT/baseLoader)))
+ ([cl]
+ (->> (iterate #(.getParent %) cl)
+ (take-while identity)
+ reverse
+ (mapcat classpath-urls)
+ distinct)))
(defn add-classpath-url
"Attempts to add a url to the given ClassLoader, returning true on success.
@@ -22,6 +22,10 @@
(fact "all-classpath-urls should order urls properly"
(all-classpath-urls (URLClassLoader. (into-array [(last all-urls)]) url-cl)) => all-urls)
+
+ (fact "all-classpath-urls should use the baseLoader when called with a zero arity"
+ (add-classpath-url (clojure.lang.RT/baseLoader) (first urls))
+ (last (all-classpath-urls)) => (first urls))
(fact "add-classpath-url should work for an addable classpath"
(add-classpath-url url-cl (last all-urls)) => true

0 comments on commit 613eccc

Please sign in to comment.