[#528] Allow reading resources from jar files

This commit is contained in:
Michiel Borkent 2020-08-12 09:34:38 +02:00 committed by GitHub
parent 4729fb1d8b
commit f091eeddd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View file

@ -46,7 +46,7 @@ args=( "-jar" "$BABASHKA_JAR"
"--initialize-at-run-time=java.lang.Math\$RandomNumberGeneratorHolder"
"--initialize-at-build-time"
"-H:Log=registerResource:"
"-H:EnableURLProtocols=http,https"
"-H:EnableURLProtocols=http,https,jar"
"--enable-all-security-services"
"-H:+JNI"
"--verbose"

View file

@ -497,9 +497,8 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
(assoc-in ['clojure.java.io 'resource]
(fn [path]
(when-let [{:keys [:loader]} @cp-state]
(try (cp/getResource loader [path] {:url? true})
;; non-relative paths don't work
(catch Exception _e nil)))))
(if (str/starts-with? path "/") nil ;; non-relative paths always return nil
(cp/getResource loader [path] {:url? true})))))
(assoc-in ['user (with-meta '*input*
(when-not stream?
{:sci.impl/deref! true}))] input-var)

View file

@ -57,4 +57,9 @@
(is (= (.length (io/file "logo" "icon.png"))
(.length tmp-file))))
(testing "No exception on absolute path"
(is (nil? (bb nil "(io/resource \"/tmp\")")))))
(is (nil? (bb nil "(io/resource \"/tmp\")"))))
(testing "Reading a resource from a .jar file"
(is (= "true"
(str/trim
(tu/bb nil "--classpath" "test-resources/babashka/src_for_classpath_test/foo.jar"
"(pos? (count (slurp (io/resource \"foo.clj\")))) "))))))