Skip to content
Browse files

Add fns classloader-resources and resources

  • Loading branch information...
1 parent 7ffee5b commit a307fa14778992b3b845aa3b1c21353d4a721315 @Chouser Chouser committed Dec 4, 2012
Showing with 24 additions and 1 deletion.
  1. +24 −1 src/main/clojure/cemerick/pomegranate.clj
25 src/main/clojure/cemerick/pomegranate.clj
@@ -114,9 +114,32 @@ unless you are extending a type to this protocol."
(get-classpath (drop 2 (classloader-hierarchy)))"
- []
(->> (reverse classloaders)
(mapcat #(when (instance? URLClassLoader %) (.getURLs %)))
(map str)))
([] (get-classpath (classloader-hierarchy))))
+(defn classloader-resources
+ "Returns a sequence of [classloader url-seq] pairs representing all
+ of the resources of the specified name on the classpath of each
+ classloader. If no classloaders are given, uses the
+ classloader-heirarchy, in which case the order of pairs will be
+ such that the first url mentioned will in most circumstances match
+ what returns."
+ ([classloaders resource-name]
+ (for [classloader (reverse classloaders)]
+ [classloader
+ (map str
+ (enumeration-seq
+ (.getResources ^ClassLoader classloader resource-name)))]))
+ ([resource-name] (classloader-resources (classloader-hierarchy) resource-name)))
+(defn resources
+ "Returns a sequence of URLs representing all of the resources of the
+ specified name on the effective classpath. This can be useful for
+ finding name collisions among items on the classpath. In most
+ circumstances, the first of the returned sequence will be the same
+ as what returns."
+ ([classloaders resource-name]
+ (distinct (map second (classloader-resources classloaders resource-name))))
+ ([resource-name] (resources (classloader-hierarchy) resource-name)))

0 comments on commit a307fa1

Please sign in to comment.
Something went wrong with that request. Please try again.