|
13 | 13 | [boot.task-helpers :as helpers]
|
14 | 14 | [boot.from.table.core :as table])
|
15 | 15 | (:import
|
| 16 | + [java.io File] |
| 17 | + [java.util Arrays] |
| 18 | + [javax.tools ToolProvider DiagnosticCollector Diagnostic$Kind] |
16 | 19 | [java.util.concurrent LinkedBlockingQueue TimeUnit]))
|
17 | 20 |
|
18 | 21 | ;; Tasks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
324 | 327 | (util/info "Compiling %s...\n" ns)
|
325 | 328 | (compile ns)))))))
|
326 | 329 |
|
| 330 | +(core/deftask javac |
| 331 | + "Compile java sources." |
| 332 | + [] |
| 333 | + (let [tgt (core/mktgtdir! ::javac-tgt)] |
| 334 | + (core/with-pre-wrap |
| 335 | + (let [throw? (atom nil) |
| 336 | + diag-coll (DiagnosticCollector.) |
| 337 | + compiler (ToolProvider/getSystemJavaCompiler) |
| 338 | + file-mgr (.getStandardFileManager compiler diag-coll nil nil) |
| 339 | + opts (->> ["-d" (.getPath tgt)] (into-array String) Arrays/asList) |
| 340 | + handler {Diagnostic$Kind/ERROR util/fail |
| 341 | + Diagnostic$Kind/WARNING util/warn |
| 342 | + Diagnostic$Kind/MANDATORY_WARNING util/warn} |
| 343 | + srcs (some->> (core/src-files) |
| 344 | + (core/by-ext [".java"]) |
| 345 | + seq |
| 346 | + (into-array File) |
| 347 | + Arrays/asList |
| 348 | + (.getJavaFileObjectsFromFiles file-mgr))] |
| 349 | + (when srcs |
| 350 | + (util/info "Compiling Java classes...\n") |
| 351 | + (-> compiler (.getTask *err* file-mgr diag-coll opts nil srcs) .call) |
| 352 | + (doseq [d (.getDiagnostics diag-coll) :let [k (.getKind d)]] |
| 353 | + (when (= Diagnostic$Kind/ERROR k) (reset! throw? true)) |
| 354 | + ((handler k util/info) |
| 355 | + "%s: %s, line %d: %s\n" |
| 356 | + (.toString k) |
| 357 | + (.. d getSource getName) |
| 358 | + (.getLineNumber d) |
| 359 | + (.getMessage d nil))) |
| 360 | + (.close file-mgr) |
| 361 | + (when @throw? (throw (Exception. "java compiler error")))))))) |
| 362 | + |
327 | 363 | (core/deftask jar
|
328 | 364 | "Build a jar file for the project."
|
329 | 365 |
|
|
0 commit comments