Skip to content
Browse files

CLASSPATH-5: extensible protocol to other classloaders

Original patch by Jim Crossley
  • Loading branch information...
1 parent c468d14 commit 0b3401cc97fcd68b7d095312e49ed0952c1a1a04 @stuartsierra stuartsierra committed Jan 7, 2014
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/main/clojure/clojure/java/classpath.clj
View
12 src/main/clojure/clojure/java/classpath.clj
@@ -22,6 +22,15 @@
(java.util.jar JarFile JarEntry)
(java.net URL URLClassLoader)))
+(defprotocol URLClasspath
+ (urls [loader]
+ "Returns a sequence of java.net.URL objects representing locations
+ which this classloader will search for classes and resources."))
+
+(extend-type java.net.URLClassLoader
+ URLClasspath
+ (urls [loader] (seq (.getURLs loader))))
+
(defn jar-file?
"Returns true if file is a normal file with a .jar or .JAR extension."
[f]
@@ -49,8 +58,7 @@
(defn loader-classpath
"Returns a sequence of File paths from a classloader."
[loader]
- (when (instance? java.net.URLClassLoader loader)
- (map io/as-file (.getURLs ^java.net.URLClassLoader loader))))
+ (map io/as-file (urls loader)))
(defn classpath
"Returns a sequence of File objects of the elements on the classpath."

0 comments on commit 0b3401c

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