Skip to content

Commit 7b4fccb

Browse files
committed
Don't use namespace level var for the current version
1 parent 93a043e commit 7b4fccb

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ Latest stable release: 1.0
1010
CLI/deps.edn dependency information:
1111

1212
```clojure
13-
org.clojars.jeff_evans/java-case {:mvn/version "1.0"}
13+
org.clojars.jeff_evans/java-case {:mvn/version "1.1"}
1414
```
1515
Leiningen dependency information:
1616

1717
```clojure
18-
[jeff_evans/java-case "1.0"]
18+
[jeff_evans/java-case "1.1"]
1919
```
2020

2121
This library is not yet deployed to Maven central.
@@ -57,7 +57,9 @@ doesn't matter.
5757
"20+" "Java 20 and beyond"))
5858
=>
5959
(clojure.core/case
60-
(clojure.core/or us.jeffevans.java-case/*java-spec-version-override* "11")
60+
(clojure.core/or
61+
us.jeffevans.java-case/*java-spec-version-override*
62+
(us.jeffevans.java-case/current-java-spec-version))
6163
("11" "12" "13" "14" "15" "16")
6264
"Java 11 through 16"
6365
"17"

build.clj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
[org.corfield.build :as bb]))
55

66
(def lib 'org.clojars.jeff_evans/java-case)
7-
(def version "1.0")
8-
#_ ; alternatively, use MAJOR.MINOR.COMMITS:
9-
(def version (format "1.0.%s" (b/git-count-revs nil)))
7+
(def version "1.1")
108

119
(defn test "Run the tests." [opts]
1210
(bb/run-tests opts))

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.clojars.jeff_evans</groupId>
55
<artifactId>java-case</artifactId>
6-
<version>1.0</version>
6+
<version>1.1</version>
77
<name>jeff_evans/java-case</name>
88
<description>A simple Clojure macro for selecting different forms based on the runtime JDK version</description>
99
<url>https://github.com/jeff-evans/java-case</url>

src/us/jeffevans/java_case.clj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
(def ^:dynamic *java-spec-version-override* nil)
55

6-
(def ^:private ^:const java-spec-version (System/getProperty "java.specification.version"))
6+
(defn current-java-spec-version
7+
"Returns the current Java major version, from the java.specification.version JVM property."
8+
[]
9+
(System/getProperty "java.specification.version"))
710

811
(def ^:private ^:const highest-known-spec-version 17)
912

@@ -27,7 +30,7 @@
2730
(java-spec-versions nil))
2831
([range-boundaries]
2932
(let [int-range-boundaries (filter #(re-matches #"\d+" %) (keys range-boundaries))
30-
curr-version (or *java-spec-version-override* java-spec-version)
33+
curr-version (or *java-spec-version-override* (current-java-spec-version))
3134
highest-v (highest-version (conj int-range-boundaries curr-version))]
3235
(if (and highest-v (> highest-v highest-known-spec-version))
3336
(->> (inc highest-v)
@@ -106,5 +109,5 @@
106109
[& definitions]
107110
(let [num-defs (count definitions)
108111
partitions (inputs->version-ranges (map first (partition 2 definitions)))]
109-
`(case (or *java-spec-version-override* ~java-spec-version)
112+
`(case (or *java-spec-version-override* (current-java-spec-version))
110113
~@(map-indexed (partial map-indexed-case-exprs num-defs partitions) definitions))))

0 commit comments

Comments
 (0)