[#528] Allow reading resources from jar files
This commit is contained in:
parent
4729fb1d8b
commit
f091eeddd9
3 changed files with 9 additions and 5 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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\")))) "))))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue