|
4 | 4 | (:require [clojure.maven.mojo.log :as log] |
5 | 5 | [buildversion-plugin.git :as git])) |
6 | 6 |
|
| 7 | + |
| 8 | +(defn- eval-custom-script [properties snippet-str] |
| 9 | + (let [props-as-bindings (vec (mapcat |
| 10 | + (fn [[k v]] [(symbol (name k)) v]) |
| 11 | + properties)) |
| 12 | + snippet (read-string snippet-str)] |
| 13 | + |
| 14 | + (eval `(let ~props-as-bindings ~snippet)))) |
| 15 | + |
| 16 | + |
7 | 17 | (defmojo BuildVersionMojo |
8 | 18 |
|
9 | 19 | {:goal "set-properties" :phase "initialize" } |
10 | 20 |
|
11 | 21 | ;; Mojo parameters |
| 22 | + |
12 | 23 | [project {:expression "${project}" :required true :readonly true} |
| 24 | + |
13 | 25 | tstamp-format {:alias "tstampFormat" :default "yyyyMMddHHmmss" |
14 | | - :typename "java.lang.String"} ] |
| 26 | + :typename "java.lang.String"} |
15 | 27 |
|
| 28 | + custom-script {:alias "customProperties" :typename "java.lang.String"} ] |
16 | 29 |
|
17 | | - ;; Goal execution |
18 | | - (let [versions-map (git/infer-project-version "." {"tstamp-format" tstamp-format}) |
19 | | - props (.getProperties project)] |
20 | 30 |
|
21 | | - (log/debug (str "buildnumber-plugin - Setting properties: ")) |
| 31 | + ;; Goal execution |
| 32 | + (let [git-versions (git/infer-project-version "." {:tstamp-format tstamp-format} ) |
| 33 | + custom-versions (if custom-script |
| 34 | + (eval-custom-script git-versions custom-script) |
| 35 | + {}) |
| 36 | + versions-map (merge git-versions custom-versions) |
| 37 | + props (.getProperties project) |
| 38 | + ] |
| 39 | + |
| 40 | + (log/warn (str "buildversion-plugin **** custom-versions map: " (pr-str custom-versions ))) |
| 41 | + (log/warn (str "buildversion-plugin **** versions-map : " (pr-str versions-map ))) |
| 42 | + (log/debug (str "buildversion-plugin - Setting properties: ")) |
22 | 43 | (doseq [[prop value] versions-map] |
23 | | - (log/debug (str (name prop) "=" value)) |
| 44 | + (log/debug (str (name prop) ": " value)) |
24 | 45 | (.put props (name prop) value)))) |
25 | 46 |
|
26 | 47 |
|
27 | 48 |
|
28 | 49 |
|
29 | 50 | ;; injecting project version does not working well :-( |
30 | 51 | ;; (.setVersion project (:maven-artifact-version versions-map)) |
31 | | - |
|
0 commit comments