Skip to content

Commit

Permalink
Don't use namespace level var for the current version
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff303 committed Sep 24, 2021
1 parent 93a043e commit 7b4fccb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Latest stable release: 1.0
CLI/deps.edn dependency information:

```clojure
org.clojars.jeff_evans/java-case {:mvn/version "1.0"}
org.clojars.jeff_evans/java-case {:mvn/version "1.1"}
```
Leiningen dependency information:

```clojure
[jeff_evans/java-case "1.0"]
[jeff_evans/java-case "1.1"]
```

This library is not yet deployed to Maven central.
Expand Down Expand Up @@ -57,7 +57,9 @@ doesn't matter.
"20+" "Java 20 and beyond"))
=>
(clojure.core/case
(clojure.core/or us.jeffevans.java-case/*java-spec-version-override* "11")
(clojure.core/or
us.jeffevans.java-case/*java-spec-version-override*
(us.jeffevans.java-case/current-java-spec-version))
("11" "12" "13" "14" "15" "16")
"Java 11 through 16"
"17"
Expand Down
4 changes: 1 addition & 3 deletions build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
[org.corfield.build :as bb]))

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

(defn test "Run the tests." [opts]
(bb/run-tests opts))
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.clojars.jeff_evans</groupId>
<artifactId>java-case</artifactId>
<version>1.0</version>
<version>1.1</version>
<name>jeff_evans/java-case</name>
<description>A simple Clojure macro for selecting different forms based on the runtime JDK version</description>
<url>https://github.com/jeff-evans/java-case</url>
Expand Down
9 changes: 6 additions & 3 deletions src/us/jeffevans/java_case.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

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

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

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

Expand All @@ -27,7 +30,7 @@
(java-spec-versions nil))
([range-boundaries]
(let [int-range-boundaries (filter #(re-matches #"\d+" %) (keys range-boundaries))
curr-version (or *java-spec-version-override* java-spec-version)
curr-version (or *java-spec-version-override* (current-java-spec-version))
highest-v (highest-version (conj int-range-boundaries curr-version))]
(if (and highest-v (> highest-v highest-known-spec-version))
(->> (inc highest-v)
Expand Down Expand Up @@ -106,5 +109,5 @@
[& definitions]
(let [num-defs (count definitions)
partitions (inputs->version-ranges (map first (partition 2 definitions)))]
`(case (or *java-spec-version-override* ~java-spec-version)
`(case (or *java-spec-version-override* (current-java-spec-version))
~@(map-indexed (partial map-indexed-case-exprs num-defs partitions) definitions))))

0 comments on commit 7b4fccb

Please sign in to comment.