Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit a2aaf17b695c86c5b49df6fe7e07dc6e79566dbe 1 parent b2d01fd
@hugoduncan hugoduncan authored
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)))
Please sign in to comment.
Something went wrong with that request. Please try again.