|
| 1 | +;;;; The following code allows to add the JDK sources without `dynapath` being present. |
| 2 | + |
| 3 | +(require '[clojure.java.io :as io]) |
| 4 | + |
| 5 | +(import '[java.util.zip ZipInputStream] |
| 6 | + '[java.io FileOutputStream]) |
| 7 | + |
| 8 | +(defmacro while-let [[sym expr] & body] |
| 9 | + `(loop [~sym ~expr] |
| 10 | + (when ~sym |
| 11 | + ~@body |
| 12 | + (recur ~expr)))) |
| 13 | + |
| 14 | +(defn jdk-find [f] |
| 15 | + (let [home (io/file (System/getProperty "java.home")) |
| 16 | + parent (.getParentFile home) |
| 17 | + paths [(io/file home f) |
| 18 | + (io/file home "lib" f) |
| 19 | + (io/file parent f) |
| 20 | + (io/file parent "lib" f)]] |
| 21 | + (->> paths (filter #(.canRead ^java.io.File %)) first str))) |
| 22 | + |
| 23 | +(def jdk-sources |
| 24 | + (let [java-path->zip-path (fn [path] |
| 25 | + (some-> (io/resource path) |
| 26 | + ^java.net.JarURLConnection (. openConnection) |
| 27 | + (. getJarFileURL) |
| 28 | + io/as-file |
| 29 | + str))] |
| 30 | + (or (java-path->zip-path "java.base/java/lang/Object.java") ; JDK9+ |
| 31 | + (java-path->zip-path "java/lang/Object.java") ; JDK8- |
| 32 | + (jdk-find "src.zip")))) |
| 33 | + |
| 34 | +(defn uncompress [path target] |
| 35 | + (let [zis (-> target io/input-stream ZipInputStream.)] |
| 36 | + (while-let [entry (-> zis .getNextEntry)] |
| 37 | + (let [size (-> entry .getSize) |
| 38 | + bytes (byte-array 1024) |
| 39 | + dest (->> entry .getName (io/file path)) |
| 40 | + dir (-> entry .getName (clojure.string/split #"/") butlast) |
| 41 | + _ (->> (clojure.string/join "/" dir) (java.io.File. path) .mkdirs) |
| 42 | + output (FileOutputStream. dest)] |
| 43 | + (loop [len (-> zis (.read bytes))] |
| 44 | + (when (pos? len) |
| 45 | + (-> output (.write bytes 0 len)) |
| 46 | + (recur (-> zis (.read bytes))))) |
| 47 | + (-> output .close))))) |
| 48 | + |
| 49 | +(defn unzipped-jdk-source [] |
| 50 | + (let [choice jdk-sources] |
| 51 | + (when-not (-> "unzipped-jdk-source" io/file .exists) |
| 52 | + (-> "unzipped-jdk-source" io/file .mkdirs) |
| 53 | + ;; For some reason simply adding a .zip to the classpath doesn't work, so one has to uncompress the contents: |
| 54 | + (uncompress "./unzipped-jdk-source/" choice)) |
| 55 | + "unzipped-jdk-source")) |
| 56 | + |
| 57 | +(def jdk8? (->> "java.version" System/getProperty (re-find #"^1.8."))) |
| 58 | + |
1 | 59 | (defproject cider/orchard "0.6.5"
|
2 | 60 | :description "A fertile ground for Clojure tooling"
|
3 | 61 | :url "https://github.com/clojure-emacs/orchard"
|
|
23 | 81 | :password :env/clojars_password
|
24 | 82 | :sign-releases false}]]
|
25 | 83 |
|
| 84 | + :jvm-opts ["-Dorchard.use-dynapath=true"] |
| 85 | + |
26 | 86 | :profiles {
|
27 | 87 | ;; Clojure versions matrix
|
28 | 88 | :provided {:dependencies [[org.clojure/clojure "1.10.1"]
|
|
38 | 98 | :dependencies [[org.clojure/clojure "1.11.0-master-SNAPSHOT"]
|
39 | 99 | [org.clojure/clojure "1.11.0-master-SNAPSHOT" :classifier "sources"]]}
|
40 | 100 |
|
41 |
| - :test {:resource-paths ["test-resources"] |
| 101 | + :test {:dependencies [[org.clojure/java.classpath "1.0.0"]] |
| 102 | + :resource-paths ["test-resources"] |
42 | 103 | ;; Initialize the cache verbosely, as usual, so that possible issues can be more easily diagnosed:
|
43 | 104 | :jvm-opts ["-Dorchard.initialize-cache.silent=false"]}
|
44 | 105 |
|
| 106 | + :no-dynapath {:jvm-opts ["-Dorchard.use-dynapath=false"] |
| 107 | + :resource-paths [~(unzipped-jdk-source)] |
| 108 | + :plugins ~(if jdk8? |
| 109 | + '[[lein-jdk-tools "0.1.1"]] |
| 110 | + [])} |
| 111 | + |
45 | 112 | ;; Development tools
|
46 | 113 | :dev {:dependencies [[pjstadig/humane-test-output "0.10.0"]]
|
47 | 114 | :resource-paths ["test-resources"]
|
|
63 | 130 | {:dependencies [[clj-kondo "2021.03.31"]]}]
|
64 | 131 |
|
65 | 132 | :eastwood {:plugins [[jonase/eastwood "0.4.0"]]
|
66 |
| - :eastwood {:exclude-namespaces [~(if (-> "java.version" |
67 |
| - System/getProperty |
68 |
| - (.contains "1.8.")) |
| 133 | + :eastwood {:exclude-namespaces [~(if jdk8? |
69 | 134 | 'orchard.java.parser
|
70 | 135 | 'orchard.java.legacy-parser)]}}})
|
0 commit comments