Skip to content
Snippets Groups Projects
Unverified Commit c9a844ba authored by dpsutton's avatar dpsutton Committed by GitHub
Browse files

Correct static interop (#16804)

on java 16 there's a handy (newFilesystem path) but i don't think we
want to require java 16 yet. On previous versions we can use
(newFileSystem Path ClassLoader) which is what it was before. Really
just need to typehint the nil, but nils don't carry
metadata (sensibly) so would have to introduce a local binding

```clojure
(let [^ClassLoader cl nil]
  (FileSystems/newFileSystem jar-path cl))
```

feels a bit weird, so just send the proper classloader through.
parent 8671f6db
No related branches found
No related tags found
No related merge requests found
......@@ -137,11 +137,12 @@
"Returns a tuple of [jar-filename {:coords :license [:error]}. Error is optional. License will be a string of license
text, coords a map with group and artifact."
[^String jar-filename backfill]
(let [jar-path (Paths/get jar-filename path-options)]
(let [jar-path ^Path (Paths/get jar-filename path-options)
classloader ^ClassLoader (ClassLoader/getSystemClassLoader)]
(if-not (Files/exists jar-path link-options)
[jar-filename {:error "Jar does not exist"}]
(try
(with-open [jar-fs (FileSystems/newFileSystem jar-path nil)]
(with-open [jar-fs (FileSystems/newFileSystem jar-path classloader)]
(let [pom-path (determine-pom jar-filename jar-fs)
license-path (license-from-jar jar-fs)
[coords pom-license] (do-with-path-is pom-path
......
......@@ -7,7 +7,7 @@
[clojure.test :refer [deftest is run-tests testing]]
[metabuild-common.core :as u])
(:import (java.io StringReader StringWriter)
(java.nio.file Files FileSystems LinkOption Paths)))
(java.nio.file Files FileSystems LinkOption Path Paths)))
(def classpath-urls (str/split (System/getProperty "java.class.path")
(re-pattern lic/classpath-separator)))
......@@ -104,9 +104,12 @@
(deftest license-from-jar-test
(letfn [(license-path [j f]
(with-open [jar-fs (FileSystems/newFileSystem (jar j) nil)]
(some-> (lic/license-from-jar jar-fs)
f)))
(let [cl ^ClassLoader (ClassLoader/getSystemClassLoader)]
;; java 16 has a single arity that just takes a path, but older versions need a classloader. It can be
;; nil but felt weird typehinting the nil in a binding
(with-open [jar-fs (FileSystems/newFileSystem ^Path (jar j) cl)]
(some-> (lic/license-from-jar jar-fs)
f))))
(first-line [path]
(lic/do-with-path-is path (fn [is]
(->> (slurp is)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment