[#670] Expose get-classpath

This commit is contained in:
Michiel Borkent 2020-12-06 11:01:37 +01:00
parent b269b37ecf
commit a04a09c018
3 changed files with 8 additions and 8 deletions

View file

@ -13,7 +13,7 @@
(deftype DirectoryResolver [path] (deftype DirectoryResolver [path]
IResourceResolver IResourceResolver
(getResource [this resource-paths {:keys [:url?]}] (getResource [_ resource-paths {:keys [:url?]}]
(some (some
(fn [resource-path] (fn [resource-path]
(let [f (io/file path resource-path)] (let [f (io/file path resource-path)]
@ -40,7 +40,7 @@
(deftype JarFileResolver [jar-file] (deftype JarFileResolver [jar-file]
IResourceResolver IResourceResolver
(getResource [this resource-paths opts] (getResource [_ resource-paths opts]
(path-from-jar jar-file resource-paths opts))) (path-from-jar jar-file resource-paths opts)))
(defn part->entry [part] (defn part->entry [part]
@ -50,9 +50,9 @@
(deftype Loader [entries] (deftype Loader [entries]
IResourceResolver IResourceResolver
(getResource [this resource-paths opts] (getResource [_ resource-paths opts]
(some #(getResource % resource-paths opts) entries)) (some #(getResource % resource-paths opts) entries))
(getResources [this resource-paths opts] (getResources [_ resource-paths opts]
(keep #(getResource % resource-paths opts) entries))) (keep #(getResource % resource-paths opts) entries)))
(defn loader [^String classpath] (defn loader [^String classpath]

View file

@ -365,7 +365,7 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
:cp new-cp}))) :cp new-cp})))
nil) nil)
(defn classpath [] (defn get-classpath []
(:cp @cp-state)) (:cp @cp-state))
;;(def ^:private server-ns-obj (sci/create-ns 'clojure.core.server nil)) ;;(def ^:private server-ns-obj (sci/create-ns 'clojure.core.server nil))
@ -398,7 +398,7 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
(repl/start-repl! @common/ctx opts)))} (repl/start-repl! @common/ctx opts)))}
'clojure.test t/clojure-test-namespace 'clojure.test t/clojure-test-namespace
'babashka.classpath {'add-classpath add-classpath* 'babashka.classpath {'add-classpath add-classpath*
'classpath classpath} 'get-classpath get-classpath}
'clojure.pprint pprint-namespace 'clojure.pprint pprint-namespace
'babashka.curl curl-namespace 'babashka.curl curl-namespace
'babashka.pods pods/pods-namespace 'babashka.pods pods/pods-namespace

View file

@ -23,10 +23,10 @@
(deftest babashka-classpath-test (deftest babashka-classpath-test
(is (= "test-resources" (is (= "test-resources"
(bb nil "--classpath" "test-resources" (bb nil "--classpath" "test-resources"
"(require '[babashka.classpath :as cp]) (cp/classpath)"))) "(require '[babashka.classpath :as cp]) (cp/get-classpath)")))
(is (= "test-resources:foobar" (is (= "test-resources:foobar"
(bb nil "--classpath" "test-resources" (bb nil "--classpath" "test-resources"
"(require '[babashka.classpath :as cp]) (cp/add-classpath \"foobar\") (cp/classpath)")))) "(require '[babashka.classpath :as cp]) (cp/add-classpath \"foobar\") (cp/get-classpath)"))))
(deftest classpath-env-test (deftest classpath-env-test
;; for this test you have to set `BABASHKA_CLASSPATH` to test-resources/babashka/src_for_classpath_test/env ;; for this test you have to set `BABASHKA_CLASSPATH` to test-resources/babashka/src_for_classpath_test/env