From 7b4fccb69cea4950887046fc64485982d9406d5c Mon Sep 17 00:00:00 2001 From: Jeff Evans Date: Fri, 24 Sep 2021 18:01:01 -0500 Subject: [PATCH] Don't use namespace level var for the current version --- README.md | 8 +++++--- build.clj | 4 +--- pom.xml | 2 +- src/us/jeffevans/java_case.clj | 9 ++++++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 28fa17f..854a9b6 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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" diff --git a/build.clj b/build.clj index 8083df0..e003483 100644 --- a/build.clj +++ b/build.clj @@ -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)) diff --git a/pom.xml b/pom.xml index c76ccea..5ca5dbc 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.clojars.jeff_evans java-case - 1.0 + 1.1 jeff_evans/java-case A simple Clojure macro for selecting different forms based on the runtime JDK version https://github.com/jeff-evans/java-case diff --git a/src/us/jeffevans/java_case.clj b/src/us/jeffevans/java_case.clj index 5f6219d..6d27426 100644 --- a/src/us/jeffevans/java_case.clj +++ b/src/us/jeffevans/java_case.clj @@ -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) @@ -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) @@ -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))))