-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmojo.clj
More file actions
67 lines (54 loc) · 2.37 KB
/
Copy pathmojo.clj
File metadata and controls
67 lines (54 loc) · 2.37 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
(ns buildversion-plugin.mojo
"Buildversion Maven Plugin"
(:use clojure.maven.mojo.defmojo)
(:require [clojure.maven.mojo.log :as log]
[buildversion-plugin.git :as git]))
(defn- eval-custom-script [properties snippet-str]
(let [props-as-bindings (vec (mapcat
(fn [[k v]] [(symbol (name k)) v])
properties))
snippet (read-string snippet-str)]
(eval `(let ~props-as-bindings ~snippet))))
(defmojo BuildVersionMojo
{:goal "set-properties" :phase "initialize" }
;; Mojo parameters
[project {:expression "${project}"
:required true
:readonly true}
base-dir {:expression "${basedir}"
:required true
:readonly true}
tstamp-format {:alias "tstampFormat"
:default "yyyyMMddHHmmss"
:typename "java.lang.String"}
custom-script {:alias "customProperties"
:typename "java.lang.String"}
git-cmd {:alias "gitCmd"
:default "git"
:typename "java.lang.String"}
fail-on-error {:alias "failOnError"
:default true
:typename "java.lang.Boolean"} ]
;; Goal execution
(try
(let [log-fn #(.debug log/*plexus-log* (str "[buildversion-plugin] " %))
inferred-props (git/infer-project-version base-dir
{:tstamp-format tstamp-format
:git-cmd (or git-cmd "git")
:debug-fn log-fn} )
final-props (if custom-script
(merge inferred-props
(eval-custom-script inferred-props custom-script))
inferred-props)
maven-project-props (.getProperties project)]
(log-fn "Setting properties: ")
(doseq [[prop value] final-props]
(log-fn (str (name prop) ": " value))
(.put maven-project-props (name prop) value)))
(catch Throwable e
(if (false? fail-on-error)
(println "[WARNING]" (.getMessage e) ": failOnError parameter false : exit plugin without error")
(throw e)))))
;; injecting project version does not work well :-(
; (if-let [ver (:build-tag final-props)]
; (.setVersion project))