Permalink
Browse files

Merge pull request #48 from LonoCloud/add-find-resources4

Add fns classloader-resources and resources, closes gh-45, closes gh-47
  • Loading branch information...
2 parents 84561ad + a307fa1 commit 2ae9213588f26e444571c45746f0a1af69a70c79 @cemerick committed Feb 20, 2013
Showing with 24 additions and 1 deletion.
  1. +24 −1 src/main/clojure/cemerick/pomegranate.clj
@@ -86,9 +86,32 @@
(get-classpath (drop 2 (classloader-hierarchy)))"
([classloaders]
- []
(->> (reverse classloaders)
(mapcat #(dp/classpath-urls %))
(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 clojure.java.io/resource 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 clojure.java.io/resource returns."
+ ([classloaders resource-name]
+ (distinct (map second (classloader-resources classloaders resource-name))))
+ ([resource-name] (resources (classloader-hierarchy) resource-name)))

0 comments on commit 2ae9213

Please sign in to comment.