-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathbuild.clj
More file actions
132 lines (117 loc) · 4.52 KB
/
build.clj
File metadata and controls
132 lines (117 loc) · 4.52 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
(ns build
(:require [clojure.java.io :as io]
[clojure.tools.build.api :as b]
[clojure.tools.build.util.file :as file]))
(def build-folder "target")
(def jar-content (str build-folder "/classes"))
(def javadoc-dir "target/javadoc")
(def basis (b/create-basis {:project "deps.edn"}))
(def version (-> basis :aliases :stencil/version (doto assert)))
(def lib 'io.github.erdos/stencil-core)
(def jar-file-name (format "%s/%s-%s.jar" build-folder (name lib) version))
(def uber-file-name (format "%s/%s-%s-standalone.jar" build-folder (name lib) version))
(defn clean [opts]
(b/delete {:path build-folder})
(println (format "Build folder \"%s\" removed" build-folder))
opts)
(defn compile-java [opts]
(clean opts)
(println :should-compile-java-here)
(b/javac {:src-dirs ["java-src"]
:basis basis
:class-dir jar-content
:javac-opts ["-source" "8" "-target" "8"]})
(b/copy-file {:src "java-src/io/github/erdos/stencil/standalone/help.txt"
:target "target/classes/io/github/erdos/stencil/standalone/help.txt"})
;; generate service provider config for function providers
(let [services (io/file "target/classes/META-INF/services/io.github.erdos.stencil.functions.FunctionsProvider")]
(io/make-parents services)
(doseq [f (file-seq (clojure.java.io/file jar-content))
[_ a] (re-seq #"^target/classes/(.*\$Provider).class$" (str f))
:let [clazz (str (.replace a "/" ".") "\n")]]
(spit services, clazz :append true)))
(spit (str jar-content "/stencil-version") version)
opts)
(defn javadoc [opts]
(file/ensure-dir javadoc-dir)
(let [src-dirs ["java-src"]
args ["-d" javadoc-dir]
java-files (mapcat #(file/collect-files (b/resolve-path %) :collect (file/suffixes ".java")) src-dirs)
args (into args (map str) java-files)
tool (javax.tools.ToolProvider/getSystemDocumentationTool)
exit (.run tool nil nil nil (into-array String args))]
(if (zero? exit)
opts
(throw (ex-info "Javadoc command error" {:exit exit})))))
(defn pom [opts]
(println "Generating pom.xml file")
(b/write-pom
{:class-dir jar-content
:basis basis
:version version
:lib lib
:pom-data
[[:description "Templating engine for OOXML DOCX and PPTX files"]
[:url "https://github.com/erdos/stencil"]
[:licenses
[:license
[:name "Eclipse Public License - v 2.0"]
[:url "https://www.eclipse.org/legal/epl-2.0/"]
[:distribution "repo"]]]
[:scm
[:url "https://github.com/erdos/stencil"]
[:connection "scm:git:https://github.com/erdos/stencil.git"]
[:developerConnection "scm:git:ssh:git@github.com:erdos/stencil.git"]
[:tag (str "v" version)]]]})
opts)
(defn jar [opts]
(clean opts)
(compile-java opts)
(pom opts)
(b/copy-dir {:src-dirs ["src"] :target-dir jar-content})
(b/jar {:class-dir jar-content
:jar-file jar-file-name})
(println "Built JAR file")
opts)
(defn java-test [_]
#_{:clj-kondo/ignore [:inline-def]} ; TODO: extract to delayed top level form
(def basis (b/create-basis {:project "deps.edn" :aliases [:junit]}))
(println "Running Java test cases")
(println "- compiling java sources")
(b/javac {:src-dirs ["java-src" "java-test"]
:basis basis
:class-dir jar-content
:javac-opts ["-source" "8" "-target" "8"]})
(println "- compiling clj sources")
(b/compile-clj {:basis basis
:src-dirs ["src"]
:class-dir jar-content
:bindings {#'*warn-on-reflection* true}})
(-> {:basis basis
:main "org.junit.platform.console.ConsoleLauncher"
:main-args ["-p" "io.github.erdos.stencil"
"--fail-if-no-tests"
"--reports-dir=target/surefire-reports"]}
(b/java-command)
(b/process)
(#(when-not (zero? (:exit %)) (throw (ex-info "junit error" %)))))
(println "Done"))
(defn uber [opts]
(jar opts)
(b/compile-clj {:basis basis
:ns-compile '[stencil.process stencil.api]
:class-dir jar-content})
(b/uber {:class-dir jar-content
:uber-file uber-file-name
:basis basis
:main 'io.github.erdos.stencil.Main})
(println (format "Uber file created: \"%s\"" uber-file-name))
opts)
(defn install [opts]
(jar opts)
(b/install {:basis basis
:lib lib
:version version
:class-dir jar-content
:jar-file jar-file-name})
opts)