Skip to content
Browse files

Fix loading of providers to work with custom classloaders

Custom classloaders as used by cake, tomcat, etc, would break the loading
of the pallet compute providers.

Fixes #57
  • Loading branch information...
1 parent b2d01fd commit a2aaf17b695c86c5b49df6fe7e07dc6e79566dbe @hugoduncan hugoduncan committed
Showing with 33 additions and 10 deletions.
  1. +7 −5 src/pallet/blobstore/implementation.clj
  2. +7 −5 src/pallet/compute/implementation.clj
  3. +19 −0 src/pallet/utils.clj
View
12 src/pallet/blobstore/implementation.clj
@@ -1,6 +1,7 @@
(ns pallet.blobstore.implementation
"Implementation details"
(:require
+ [pallet.utils :as utils]
[clojure.contrib.find-namespaces :as find-namespaces]))
(defmulti service
@@ -18,11 +19,12 @@
"Find the available providers."
[]
(try
- (->> (find-namespaces/find-namespaces-on-classpath)
- (filter #(re-find blobstore-regex (name %)))
- (remove #(re-find exclude-regex (name %)))
- (remove exclude-blobstore-ns)
- (set))
+ (binding [clojure.contrib.classpath/classpath utils/classpath]
+ (->> (find-namespaces/find-namespaces-on-classpath)
+ (filter #(re-find blobstore-regex (name %)))
+ (remove #(re-find exclude-regex (name %)))
+ (remove exclude-blobstore-ns)
+ (set)))
(catch java.io.FileNotFoundException _)))
(defn load-providers
View
12 src/pallet/compute/implementation.clj
@@ -1,6 +1,7 @@
(ns pallet.compute.implementation
"Implementation details"
(:require
+ [pallet.utils :as utils]
[clojure.contrib.find-namespaces :as find-namespaces]))
(defmulti service
@@ -20,11 +21,12 @@
"Find the available providers."
[]
(try
- (->> (find-namespaces/find-namespaces-on-classpath)
- (filter #(re-find compute-regex (name %)))
- (remove #(re-find exclude-regex (name %)))
- (remove exclude-compute-ns)
- (set))
+ (binding [clojure.contrib.classpath/classpath utils/classpath]
+ (->> (find-namespaces/find-namespaces-on-classpath)
+ (filter #(re-find compute-regex (name %)))
+ (remove #(re-find exclude-regex (name %)))
+ (remove exclude-compute-ns)
+ (set)))
(catch java.io.FileNotFoundException _)))
(defn load-providers
View
19 src/pallet/utils.clj
@@ -253,3 +253,22 @@
(if (seq middlewares)
`(-> ~handler ~@middlewares)
handler)))
+
+;; see http://weblogs.java.net/blog/kohsuke/archive/2007/04/how_to_convert.html
+(defn file-for-url
+ "Convert a URL to a File. "
+ [^java.net.URL url]
+ (try
+ (java.io.File. (.toURI url))
+ (catch java.net.URISyntaxException _
+ (java.io.File. (.getPath url)))))
+
+(defn classpath-urls
+ "Return the classpath URL's for the current clojure classloader."
+ []
+ (.getURLs (.getClassLoader clojure.lang.RT)))
+
+(defn classpath
+ "Return the classpath File's for the current clojure classloader."
+ []
+ (map file-for-url (classpath-urls)))

0 comments on commit a2aaf17

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