Skip to content

Commit

Permalink
Merge pull request #77 from pmonks/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
pmonks committed Nov 18, 2023
2 parents 0cb2a5b + 35390df commit 786eb16
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
java-version: 21
- uses: DeLaGuardo/setup-clojure@12.1
with:
cli: latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
java-version: 21
- uses: DeLaGuardo/setup-clojure@12.1
with:
cli: latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
java-version: 21
- uses: DeLaGuardo/setup-clojure@12.1
with:
cli: latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vulnerabilities.yml
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
java-version: 21
- uses: DeLaGuardo/setup-clojure@12.1
with:
cli: latest
Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Expand Up @@ -25,7 +25,7 @@
io.github.clojure/tools.build {:mvn/version "0.9.6" :exclusions [org.slf4j/slf4j-nop]}
com.github.pmonks/tools-convenience {:mvn/version "1.0.142"}
com.github.pmonks/tools-pom {:mvn/version "1.0.127"}
com.github.pmonks/tools-licenses {:mvn/version "2.0.167"}
com.github.pmonks/tools-licenses {:mvn/version "2.0.172"}
clj-kondo/clj-kondo {:mvn/version "2023.10.20"}

; Dynamic dependencies - any time any of these changes it MUST ALSO BE CHANGED IN pbr.tasks!!
Expand All @@ -36,7 +36,7 @@
org.apache.logging.log4j/log4j-slf4j2-impl {:mvn/version "2.21.1"} ; SLF4J clogging bridge
org.apache.logging.log4j/log4j-1.2-api {:mvn/version "2.21.1"} ; log4j1 clogging bridge
; org.slf4j/slf4j-nop {:mvn/version "2.0.9"} ; Note: used for some commands invoked as sub-processes, but can't be used here or it will shadow log4j2
jonase/eastwood {:mvn/version "1.4.0"}
jonase/eastwood {:mvn/version "1.4.0"} ; Note: 1.4.2 uses a version of org.ow2.asm/asm that's incompatible with clj-kondo's dependent version
codox/codox {:mvn/version "0.10.8"}
com.github.athos/clj-check {:git/sha "518d5a1cbfcd7c952f548e6dbfcb9a4a5faf9062"}
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}
Expand Down
109 changes: 58 additions & 51 deletions src/pbr/build.clj
Expand Up @@ -31,7 +31,6 @@ clojure -A:deps -T:build help/doc"
[clojure.java.shell :as sh]
[clojure.tools.build.api :as b]
[tools-convenience.api :as tc]
[tools-licenses.tasks :as lic]
[pbr.tasks :as pbr]))

(defn- set-opts [_] (throw (ex-info "Default set-opts fn called. Did you forget to redefine it in your pbr.clj script?" {})))
Expand All @@ -41,64 +40,64 @@ clojure -A:deps -T:build help/doc"
"Clean up the project."
[opts]
(-> opts
(set-opts)
(pbr/clean)))
set-opts
pbr/clean))

(defn check
"Check the code by AOT compiling it (and throwing away the result)."
[opts]
(-> opts
(set-opts)
(pbr/check)))
set-opts
pbr/check))

(defn outdated
"Check for outdated dependencies (using antq)."
[opts]
(-> opts
(set-opts)
(pbr/antq-outdated)))
set-opts
pbr/antq-outdated))

(defn upgrade
"Upgrade any outdated dependencies (using antq). NOTE: does not prompt for confirmation!"
[opts]
(-> opts
(set-opts)
(pbr/antq-upgrade)))
set-opts
pbr/antq-upgrade))

(defn test
"Run the tests."
[opts]
(-> opts
(set-opts)
(pbr/run-tests)))
set-opts
pbr/run-tests))

(defn nvd
"Run an NVD vulnerability check"
[opts]
(-> opts
(set-opts)
(pbr/nvd)))
set-opts
pbr/nvd))

(defn kondo
"Run the clj-kondo linter."
[opts]
(-> opts
(set-opts)
(pbr/kondo)))
set-opts
pbr/kondo))

(defn eastwood
"Run the eastwood linter."
[opts]
(-> opts
(set-opts)
(pbr/eastwood)))
set-opts
pbr/eastwood))

(defn lint
"Run all linters."
[opts]
(-> opts
(kondo)
(eastwood)))
kondo
eastwood))

(defn ci
"Run the CI pipeline."
Expand All @@ -110,81 +109,89 @@ clojure -A:deps -T:build help/doc"
; (try (nvd opts) (catch Exception _)) ; This is exceptionally slow, and therefore inappropriate for every CI build
(lint opts)))

(defn licenses
"Attempts to list all licenses for the transitive set of dependencies of the project, as SPDX license identifiers."
[opts]
(-> opts
(set-opts)
(lic/licenses)))

(defn check-asf-policy
"Checks this project's dependencies' licenses against the ASF's 3rd party license policy (https://www.apache.org/legal/resolved.html)."
[opts]
(-> opts
(set-opts)
(lic/check-asf-policy)))
; We do these cursed shenanigans because tools-licenses requires JDK 11+, but we want PBR to work on JDK 8+
(if (>= (pbr/jvm-version) 11)
(do
(require 'tools-licenses.tasks)

(eval ; I have no clue why this is necessary, unless tools.build is AOT compiling this ns or something weird...
'(defn licenses
"Attempts to list all licenses for the transitive set of dependencies of the project, as SPDX license identifiers."
[opts]
(-> opts
set-opts
tools-licenses.tasks/licenses)))

(eval ; I have no clue why this is necessary, unless tools.build is AOT compiling this ns or something weird...
'(defn check-asf-policy
"Checks this project's dependencies' licenses against the ASF's 3rd party license policy (https://www.apache.org/legal/resolved.html)."
[opts]
(-> opts
set-opts
tools-licenses.tasks/check-asf-policy))))
(println "⚠️ Running on an old JVM (< v11) - some functionality is unavailable."))

(defn check-release
"Check that a release can be done from the current directory."
[opts]
(-> opts
(set-opts)
(ci)
(pbr/check-release)))
set-opts
ci
pbr/check-release))

(defn release
"Release a new version of the library."
[opts]
(check-release opts)
(-> opts
(set-opts)
(pbr/release)))
set-opts
pbr/release))

(defn pom
"Generates a comprehensive pom.xml for the project."
[opts]
(-> opts
(set-opts)
(pbr/pom)))
set-opts
pbr/pom))

(defn jar
"Generates a library JAR for the project."
[opts]
(-> opts
(set-opts)
(pbr/jar)))
set-opts
pbr/jar))

(defn uber
"Create an uber jar."
[opts]
(-> opts
(set-opts)
(pbr/uber)))
set-opts
pbr/uber))

(defn uberexec
"Creates an executable uber jar. NOTE: does not bundle a JRE, though one is still required."
[opts]
(-> opts
(set-opts)
(pbr/uberexec)))
set-opts
pbr/uberexec))

(defn install
"Install the library locally e.g. so it can be tested by downstream dependencies"
[opts]
(-> opts
(set-opts)
(pbr/install)))
set-opts
pbr/install))

(defn deploy
"Deploys the library JAR to Clojars."
[opts]
(-> opts
(set-opts)
(pbr/deploy)))
set-opts
pbr/deploy))

(defn docs
"Generates documentation (using codox)."
[opts]
(-> opts
(set-opts)
(pbr/codox)))
set-opts
pbr/codox))
16 changes: 16 additions & 0 deletions src/pbr/tasks.clj
Expand Up @@ -126,6 +126,22 @@
(when s
(s/lower-case s)))

(defn jvm-version
"Returns the version of the running JVM as an Integer. Older versions (e.g.
1.6, 1.7, 1.8) have their minor version returned (i.e. 1.6 -> 6, 1.7 -> 7,
etc.)
Adapted from http-kit (Apache-2.0 licensed): https://github.com/http-kit/http-kit/blob/e00279f6d921efd3aad3b513ebfa42604d3cf3bd/src/org/httpkit/utils.clj#L6-L16"
[]
(let [s (System/getProperty "java.version")
dot-idx (.indexOf s ".") ; e.g. "1.6.0_23"
dash-idx (.indexOf s "-")] ; e.g. "16-ea"
(cond
;; e.g. "1.6.0_23"
(.startsWith s "1.") (Integer/parseInt (.substring s 2 3))
(pos? dot-idx) (Integer/parseInt (.substring s 0 dot-idx))
(pos? dash-idx) (Integer/parseInt (.substring s 0 dash-idx))
:else (Integer/parseInt s))))

(defn calculate-version
"Returns a calculated version number, using the provided major.minor components. Returns nil if one cannot be determined. Notes: this is a utility fn, not a task fn. This logic is specific to the author's tagging and branch naming scheme and may not work as intended in other setups."
([major minor] (calculate-version major minor nil))
Expand Down

0 comments on commit 786eb16

Please sign in to comment.