-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
classloader.clj
30 lines (28 loc) · 1.19 KB
/
classloader.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(ns orchard.classloader
(:require [orchard.java :as java]
[orchard.misc :refer [boot-fake-classpath boot-project?]]
[clojure.string :as str]))
(defn boot-class-loader
"Creates a class-loader that knows original source files paths in Boot project."
[]
(let [class-path (boot-fake-classpath)
dir-separator (System/getProperty "file.separator")
paths (str/split class-path (re-pattern (System/getProperty "path.separator")))
urls (map
(fn [path]
(let [url (if (re-find #".jar$" path)
(str "file:" path)
(str "file:" path dir-separator))]
(new java.net.URL url)))
paths)
jdk-sources (->> [#_"see '## Classpath' notes at `orchard.java`"
["src.zip"]
["lib" "tools.jar"]]
(map (partial apply java/jdk-resource-url))
(remove nil?))]
(new java.net.URLClassLoader (into-array java.net.URL (concat urls jdk-sources)))))
(defn class-loader
[]
(if (boot-project?)
(boot-class-loader)
(.getContextClassLoader (Thread/currentThread))))