summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2011-02-02 16:00:11 -0800
committerDavid Barksdale <amatus.amongus@gmail.com>2011-05-23 22:59:46 -0500
commit134db449360df4b7f5aaa4b78267ee74473d14c3 (patch)
treedc1dde1767c0ebfa5ea523f420de03ecff4573d1
parent1f233ad1ba22cf98dad32c0fbf15915bc9b60bfc (diff)
Created gen-class option :set-context-classloader.
When the class is loaded it will set the current thread's context ClassLoader to the ClassLoader which is currently loading the class. This turns out to be useful for classes which extend java.applet.Applet because the current thread's context ClassLoader is not the JNLPClassLoader when loaded in a browser.
-rw-r--r--src/clj/clojure/genclass.clj8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/clj/clojure/genclass.clj b/src/clj/clojure/genclass.clj
index 93fa438e..114cfe7e 100644
--- a/src/clj/clojure/genclass.clj
+++ b/src/clj/clojure/genclass.clj
@@ -112,7 +112,7 @@
(validate-generate-class-options options-map)
(let [default-options {:prefix "-" :load-impl-ns true :impl-ns (ns-name *ns*)}
{:keys [name extends implements constructors methods main factory state init exposes
- exposes-methods prefix load-impl-ns impl-ns post-init]}
+ exposes-methods prefix load-impl-ns impl-ns post-init set-context-classloader]}
(merge default-options options-map)
name-meta (meta name)
name (str name)
@@ -143,6 +143,7 @@
main-name "main"
var-name (fn [s] (clojure.lang.Compiler/munge (str s "__var")))
class-type (totype Class)
+ thread-type (totype Thread)
rt-type (totype clojure.lang.RT)
var-type ^Type (totype clojure.lang.Var)
ifn-type (totype clojure.lang.IFn)
@@ -267,6 +268,11 @@
(. Method getMethod "void <clinit> ()")
nil nil cv)]
(. gen (visitCode))
+ (when set-context-classloader
+ (. gen (invokeStatic thread-type (. Method (getMethod "java.lang.Thread currentThread()"))))
+ (. gen push ctype)
+ (. gen (invokeVirtual class-type (. Method (getMethod "ClassLoader getClassLoader()"))))
+ (. gen (invokeVirtual thread-type (. Method (getMethod "void setContextClassLoader(ClassLoader)")))))
(doseq [v var-fields]
(. gen push impl-pkg-name)
(. gen push (str prefix v))