[#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-run-time=java.lang.Math\$RandomNumberGeneratorHolder"
|
||||||
"--initialize-at-build-time"
|
"--initialize-at-build-time"
|
||||||
"-H:Log=registerResource:"
|
"-H:Log=registerResource:"
|
||||||
"-H:EnableURLProtocols=http,https"
|
"-H:EnableURLProtocols=http,https,jar"
|
||||||
"--enable-all-security-services"
|
"--enable-all-security-services"
|
||||||
"-H:+JNI"
|
"-H:+JNI"
|
||||||
"--verbose"
|
"--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]
|
(assoc-in ['clojure.java.io 'resource]
|
||||||
(fn [path]
|
(fn [path]
|
||||||
(when-let [{:keys [:loader]} @cp-state]
|
(when-let [{:keys [:loader]} @cp-state]
|
||||||
(try (cp/getResource loader [path] {:url? true})
|
(if (str/starts-with? path "/") nil ;; non-relative paths always return nil
|
||||||
;; non-relative paths don't work
|
(cp/getResource loader [path] {:url? true})))))
|
||||||
(catch Exception _e nil)))))
|
|
||||||
(assoc-in ['user (with-meta '*input*
|
(assoc-in ['user (with-meta '*input*
|
||||||
(when-not stream?
|
(when-not stream?
|
||||||
{:sci.impl/deref! true}))] input-var)
|
{:sci.impl/deref! true}))] input-var)
|
||||||
|
|
|
||||||
|
|
@ -57,4 +57,9 @@
|
||||||
(is (= (.length (io/file "logo" "icon.png"))
|
(is (= (.length (io/file "logo" "icon.png"))
|
||||||
(.length tmp-file))))
|
(.length tmp-file))))
|
||||||
(testing "No exception on absolute path"
|
(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