|
1 | 1 | (ns build-plugin |
2 | 2 | (:require [clojure.tools.build.api :as b] |
3 | 3 | [clojure.string :as str] |
4 | | - [clojure.java.io :as io])) |
| 4 | + [clojure.java.io :as io] |
| 5 | + [shade.core :as shade]) |
| 6 | + (:import java.nio.file.FileSystems |
| 7 | + java.nio.file.Path |
| 8 | + java.nio.file.Paths |
| 9 | + java.nio.file.Files |
| 10 | + java.nio.file.FileVisitOption |
| 11 | + java.nio.file.StandardOpenOption |
| 12 | + java.nio.charset.StandardCharsets |
| 13 | + java.net.URI)) |
5 | 14 |
|
6 | 15 | (def lib 'com.lambdaisland/witchcraft-plugin) |
7 | 16 | (def version (format "0.0.%s" (b/git-count-revs nil))) |
8 | 17 | (def class-dir "target/classes") |
9 | | -(def jar-file ) |
| 18 | + |
| 19 | +(def shadings |
| 20 | + {"org.eclipse.aether" "com.lambdaisland.shaded.org.eclipse.aether" |
| 21 | + "org.apache.maven" "com.lambdaisland.shaded.org.apache.maven" |
| 22 | + "org.codehaus.plexus" "com.lambdaisland.shaded.org.codehaus.plexus"}) |
10 | 23 |
|
11 | 24 | (defn clean [params] |
12 | 25 | (b/delete {:path "target"}) |
|
29 | 42 | :description "Bootstrap Clojure/nREPL/Witchcraft" |
30 | 43 | :api-version api-version}))) |
31 | 44 |
|
| 45 | +(defn shade-jar [in out] |
| 46 | + ;; java |
| 47 | + (shade/shade in out shadings) |
| 48 | + |
| 49 | + ;; clojure |
| 50 | + (with-open [zipfs (FileSystems/newFileSystem ^Path (Paths/get out (into-array String [])))] ;; Requires JDK 12 |
| 51 | + (let [paths (iterator-seq (.iterator (Files/walk (first (.getRootDirectories zipfs)) (make-array FileVisitOption 0))))] |
| 52 | + (doseq [path paths |
| 53 | + :when (re-find #"\.cljc?$" (str path))] |
| 54 | + (let [txt (slurp (.toUri path)) |
| 55 | + shaded (reduce |
| 56 | + (fn [txt [from to]] |
| 57 | + (str/replace txt from to)) |
| 58 | + txt |
| 59 | + shadings)] |
| 60 | + (when (not= shaded txt) |
| 61 | + (Files/write path |
| 62 | + (.getBytes shaded StandardCharsets/UTF_8) |
| 63 | + (into-array StandardOpenOption |
| 64 | + [StandardOpenOption/TRUNCATE_EXISTING])))))))) |
| 65 | + |
32 | 66 | (defn build [{:keys [env api-version server] :as params |
33 | 67 | :or {api-version "1.17" |
34 | 68 | server 'paper}}] |
35 | 69 | (let [basis (b/create-basis {:project "deps.edn" |
36 | | - :aliases [(case server |
37 | | - paper |
38 | | - :mc/paper-api |
39 | | - glowstone |
40 | | - :mc/glowstone)]}) |
| 70 | + :aliases [(keyword "mc" (str server "-" api-version))]}) |
41 | 71 | jar-file (format "target/%s-%s-for-%s-%s.jar" |
42 | 72 | (name lib) |
43 | 73 | version |
|
50 | 80 | :src-dirs ["src"]}) |
51 | 81 | (b/javac {:src-dirs ["java"] |
52 | 82 | :class-dir class-dir |
53 | | - :basis basis}) |
| 83 | + :basis basis |
| 84 | + :javac-opts ["-source" "11" "-target" "11"]}) |
54 | 85 | (b/copy-dir {:src-dirs ["src"] |
55 | 86 | :target-dir class-dir}) |
56 | 87 | (plugin-yml {:target-dir class-dir :api-version api-version}) |
57 | 88 | (b/uber {:class-dir class-dir |
58 | 89 | :uber-file jar-file |
59 | 90 | :basis (b/create-basis {:project "deps.edn" |
60 | | - :aliases [:licp :nrepl]})})) |
| 91 | + :aliases [:licp :nrepl]})}) |
| 92 | + (shade-jar jar-file (str/replace jar-file ".jar" "-shaded.jar"))) |
61 | 93 | params) |
62 | 94 |
|
63 | 95 | (defn build-all [& _] |
64 | 96 | (build '{:server glowstone :api-version 1.12}) |
65 | | - (build '{:server paper :api-version 1.17})) |
| 97 | + (build '{:server paper :api-version 1.17}) |
| 98 | + (build '{:server spigot :api-version 1.17})) |
0 commit comments