/
version.clj
46 lines (41 loc) · 1.6 KB
/
version.clj
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
(ns nrepl.version
{:author "Colin Jones"
:added "0.5"}
(:import java.util.Properties))
(defn- map-from-property-filepath [file]
(try
(let [file-reader (.. (Thread/currentThread)
(getContextClassLoader)
(getResourceAsStream file))
props (Properties.)]
(.load props file-reader)
(into {} props))
(catch Exception e nil)))
(defn- get-properties-filename [group artifact]
(str "META-INF/maven/" group "/" artifact "/pom.properties"))
(defn- get-version
"Attempts to get the project version from system properties (set when running
Leiningen), or a properties file based on the group and artifact ids (in jars
built by Leiningen), or a default version passed in. Falls back to an empty
string when no default is present."
([group artifact]
(get-version group artifact ""))
([group artifact default-version]
(or (System/getProperty (str artifact ".version"))
(-> (get-properties-filename group artifact)
map-from-property-filepath
(get "version"))
default-version)))
(def ^{:private true} version-string
"Current version of nREPL as a string.
See also `version`."
(get-version "nrepl" "nrepl"))
(def version
"Current version of nREPL.
Map of :major, :minor, :incremental, :qualifier, and :version-string."
(assoc (->> version-string
(re-find #"(\d+)\.(\d+)\.(\d+)-?(.*)")
rest
(map #(try (Integer/parseInt %) (catch Exception e nil)))
(zipmap [:major :minor :incremental :qualifier]))
:version-string version-string))