|
26 | 26 | (let [[group artifact] ((juxt namespace name) sym)]
|
27 | 27 | [(or group artifact) artifact]))
|
28 | 28 |
|
| 29 | +(defn extend-addable-classloader |
| 30 | + "Opens up the class loader used to create the shim for |
| 31 | + modification. Once seal-app-classloader is called, this will be the |
| 32 | + highest class loader user code can modify. |
| 33 | +
|
| 34 | + This function is called during Boot's bootstrapping phase, and shouldn't |
| 35 | + be needed in client code under normal circumstances." |
| 36 | + [] |
| 37 | + (extend boot.AddableClassLoader |
| 38 | + cp/DynamicClasspath |
| 39 | + (assoc dynapath.dynamic-classpath/base-readable-addable-classpath |
| 40 | + :classpath-urls #(seq (.getURLs %)) |
| 41 | + :add-classpath-url #(.addURL %1 %2)))) |
| 42 | + |
| 43 | +(def sealed-classloader-fns |
| 44 | + (assoc cp/base-readable-addable-classpath |
| 45 | + :classpath-urls #(seq (.getURLs %)) |
| 46 | + :can-add? (constantly false))) |
| 47 | + |
29 | 48 | (defn seal-app-classloader
|
30 |
| - "Implements the DynamicClasspath protocol to the AppClassLoader class such |
31 |
| - that instances of this class will refuse attempts at runtime modification |
32 |
| - by libraries that do so via dynapath[1]. The system class loader is of the |
33 |
| - type AppClassLoader. |
| 49 | + "Implements the DynamicClasspath protocol to the AppClassLoader and |
| 50 | + boot's ParentClassLoader classes such that instances of those |
| 51 | + classes will refuse attempts at runtime modification by libraries |
| 52 | + that do so via dynapath[1]. The system class loader is of the type |
| 53 | + AppClassLoader under Java < 9, and the top-level class loader used |
| 54 | + by boot is a ParentClassLoader. |
34 | 55 |
|
35 | 56 | The purpose of this is to ensure that Clojure libraries do not pollute the
|
36 | 57 | higher-level class loaders with classes and interfaces created dynamically
|
|
42 | 63 | [1]: https://github.com/tobias/dynapath
|
43 | 64 | [2]: https://github.com/clojure-emacs/cider-nrepl/blob/36333cae25fd510747321f86e2f0369fcb7b4afd/README.md#with-jboss-asjboss-eapwildfly"
|
44 | 65 | []
|
45 |
| - (extend sun.misc.Launcher$AppClassLoader |
46 |
| - cp/DynamicClasspath |
47 |
| - (assoc cp/base-readable-addable-classpath |
48 |
| - :classpath-urls #(seq (.getURLs %)) |
49 |
| - :can-add? (constantly false)))) |
| 66 | + (try |
| 67 | + ;; this import will fail if the user doesn't have a new enough boot.sh |
| 68 | + (import boot.bin.ParentClassLoader) |
| 69 | + (eval '(extend boot.bin.ParentClassLoader |
| 70 | + dynapath.dynamic-classpath/DynamicClasspath |
| 71 | + boot.pod/sealed-classloader-fns)) |
| 72 | + (catch Exception _)) |
| 73 | + |
| 74 | + (try |
| 75 | + ;; this import will fail if the user is using Java 9 |
| 76 | + (import sun.misc.Launcher$AppClassLoader) |
| 77 | + (eval '(extend sun.misc.Launcher$AppClassLoader |
| 78 | + dynapath.dynamic-classpath/DynamicClasspath |
| 79 | + boot.pod/sealed-classloader-fns)) |
| 80 | + (catch Exception _))) |
50 | 81 |
|
51 | 82 | (defn ^{:boot/from :cemerick/pomegranate} classloader-hierarchy
|
52 | 83 | "Returns a seq of classloaders, with the tip of the hierarchy first.
|
|
0 commit comments