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-02-02 16:00:11 -0800
commita158c0da1d43ddad9923e27e1fdd03e3bbbe5b37 (patch)
treeb5265bcd596b50f86b88487114f926014a46119b
parentf128af9d36dfcb268b6e9ea63676cf254c0f1c40 (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 e998d996..d04127ca 100644
--- a/src/clj/clojure/genclass.clj
+++ b/src/clj/clojure/genclass.clj
@@ -104,7 +104,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)
@@ -135,6 +135,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)
@@ -259,6 +260,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))