Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add fns classloader-resources and resources

  • Loading branch information...
commit a307fa14778992b3b845aa3b1c21353d4a721315 1 parent 7ffee5b
Chris Houser authored December 04, 2012
25  src/main/clojure/cemerick/pomegranate.clj
@@ -114,9 +114,32 @@ unless you are extending a type to this protocol."
114 114
 
115 115
    (get-classpath (drop 2 (classloader-hierarchy)))"
116 116
   ([classloaders]
117  
-    []
118 117
     (->> (reverse classloaders)
119 118
       (mapcat #(when (instance? URLClassLoader %) (.getURLs %)))
120 119
       (map str)))
121 120
   ([] (get-classpath (classloader-hierarchy))))
122 121
 
  122
+(defn classloader-resources
  123
+  "Returns a sequence of [classloader url-seq] pairs representing all
  124
+   of the resources of the specified name on the classpath of each
  125
+   classloader. If no classloaders are given, uses the
  126
+   classloader-heirarchy, in which case the order of pairs will be
  127
+   such that the first url mentioned will in most circumstances match
  128
+   what clojure.java.io/resource returns."
  129
+  ([classloaders resource-name]
  130
+     (for [classloader (reverse classloaders)]
  131
+       [classloader
  132
+        (map str
  133
+             (enumeration-seq
  134
+              (.getResources ^ClassLoader classloader resource-name)))]))
  135
+  ([resource-name] (classloader-resources (classloader-hierarchy) resource-name)))
  136
+
  137
+(defn resources
  138
+  "Returns a sequence of URLs representing all of the resources of the
  139
+   specified name on the effective classpath. This can be useful for
  140
+   finding name collisions among items on the classpath. In most
  141
+   circumstances, the first of the returned sequence will be the same
  142
+   as what clojure.java.io/resource returns."
  143
+  ([classloaders resource-name]
  144
+     (distinct (map second (classloader-resources classloaders resource-name))))
  145
+  ([resource-name] (resources (classloader-hierarchy) resource-name)))

0 notes on commit a307fa1

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