From 3270d521d3d3eb5671cd48286f003eda82b40998 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sun, 22 Dec 2019 20:09:52 +0100 Subject: [PATCH] Support for clj-http-lite --- reflection.json | 20 +++---- sci | 2 +- src/babashka/impl/classes.clj | 4 +- src/babashka/main.clj | 101 +++++++++++++++++----------------- test/babashka/main_test.clj | 3 + 5 files changed, 68 insertions(+), 62 deletions(-) diff --git a/reflection.json b/reflection.json index 3038d896..c2e35bed 100644 --- a/reflection.json +++ b/reflection.json @@ -188,6 +188,11 @@ "allPublicMethods" : true, "allPublicFields" : true, "allPublicConstructors" : true +}, { + "name" : "java.nio.file.Paths", + "allPublicMethods" : true, + "allPublicFields" : true, + "allPublicConstructors" : true }, { "name" : "java.nio.file.StandardCopyOption", "allPublicMethods" : true, @@ -353,21 +358,16 @@ "allPublicMethods" : true, "allPublicFields" : true, "allPublicConstructors" : true -}, { - "name" : "javax.xml.bind.DatatypeConverter", - "allPublicMethods" : true, - "allPublicFields" : true, - "allPublicConstructors" : true -}, { - "name" : "sun.net.www.protocol.http.HttpURLConnection", - "allPublicMethods" : true, - "allPublicFields" : true, - "allPublicConstructors" : true }, { "name" : "sun.net.www.protocol.http.HttpURLConnection$HttpInputStream", "allPublicMethods" : true, "allPublicFields" : true, "allPublicConstructors" : true +}, { + "name" : "sun.net.www.protocol.https.HttpsURLConnectionImpl", + "allPublicMethods" : true, + "allPublicFields" : true, + "allPublicConstructors" : true }, { "name" : "sun.nio.fs.UnixPath", "allPublicMethods" : true, diff --git a/sci b/sci index 577351c5..6b75e107 160000 --- a/sci +++ b/sci @@ -1 +1 @@ -Subproject commit 577351c5514edb7492314048aef99d3c4319a667 +Subproject commit 6b75e1071ee425c6f468c73b2cef3ceae9c24af5 diff --git a/src/babashka/impl/classes.clj b/src/babashka/impl/classes.clj index b8de9995..20e27ee6 100644 --- a/src/babashka/impl/classes.clj +++ b/src/babashka/impl/classes.clj @@ -43,6 +43,7 @@ java.nio.file.Files java.nio.file.NoSuchFileException java.nio.file.Path + java.nio.file.Paths java.nio.file.StandardCopyOption java.nio.file.attribute.FileAttribute java.nio.file.attribute.PosixFilePermission @@ -75,9 +76,8 @@ java.util.zip.DeflaterInputStream java.util.zip.GZIPInputStream java.util.zip.GZIPOutputStream - javax.xml.bind.DatatypeConverter sun.nio.fs.UnixPath ;; included because of permission check - sun.net.www.protocol.http.HttpURLConnection ;; needed for clj-http.lite + sun.net.www.protocol.https.HttpsURLConnectionImpl ;; needed fo clj-http.lite sun.net.www.protocol.http.HttpURLConnection$HttpInputStream ;; needed for clj-http.lite ] :custom-classes {'java.lang.Thread diff --git a/src/babashka/main.clj b/src/babashka/main.clj index be146a88..1f62b057 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -21,8 +21,7 @@ [clojure.string :as str] [sci.addons :as addons] [sci.core :as sci] - [sci.impl.vars :as vars] - [sci.impl.namespaces :as sci-namespaces]) + [sci.impl.vars :as vars]) (:gen-class)) (set! *warn-on-reflection* true) @@ -169,6 +168,8 @@ Everything after that is bound to *command-line-args*.")) (edn/read {;;:readers *data-readers* :eof ::EOF} *in*)) +(def reflection-var (sci/new-dynamic-var '*warn-on-reflection* false)) + (defn load-file* [ctx f] (let [f (io/file f) s (slurp f)] @@ -247,7 +248,8 @@ Everything after that is bound to *command-line-args*.")) :namespaces {'clojure.core (assoc core-extras '*command-line-args* (sci/new-dynamic-var '*command-line-args* command-line-args) - '*file* vars/file-var) + '*file* vars/file-var + '*warn-on-reflection* reflection-var) 'clojure.tools.cli tools-cli-namespace 'clojure.edn {'read edn/read 'read-string edn/read-string} @@ -288,52 +290,53 @@ Everything after that is bound to *command-line-args*.")) main) expression) exit-code - (or - #_(binding [*out* *err*] - (prn ">>" _opts)) - (second - (cond version - [(print-version) 0] - help? - [(print-help) 0] - repl [(start-repl! ctx #(read-next *in*)) 0] - socket-repl [(start-socket-repl! socket-repl ctx #(read-next *in*)) 0] - :else - (try - (let [expr (if file (read-file file) expression)] - (if expr - (loop [in (read-next *in*)] - (let [ctx (update-in ctx [:namespaces 'user] assoc (with-meta '*input* - (when-not stream? - {:sci.impl/deref! true})) - (sci/new-dynamic-var '*input* in))] - (if (identical? ::EOF in) - [nil 0] ;; done streaming - (let [res [(let [res (eval-string expr ctx)] - (when (some? res) - (if-let [pr-f (cond shell-out println - edn-out prn)] - (if (coll? res) - (doseq [l res - :while (not (pipe-signal-received?))] - (pr-f l)) - (pr-f res)) - (prn res)))) 0]] - (if stream? - (recur (read-next *in*)) - res))))) - [(start-repl! ctx #(read-next *in*)) 0])) - (catch Throwable e - (binding [*out* *err*] - (let [d (ex-data e) - exit-code (:bb/exit-code d)] - (if exit-code [nil exit-code] - (do (if verbose? - (print-stack-trace e) - (println (.getMessage e))) - (flush) - [nil 1])))))))) - 1) + (sci/with-bindings {reflection-var false} + (or + #_(binding [*out* *err*] + (prn ">>" _opts)) + (second + (cond version + [(print-version) 0] + help? + [(print-help) 0] + repl [(start-repl! ctx #(read-next *in*)) 0] + socket-repl [(start-socket-repl! socket-repl ctx #(read-next *in*)) 0] + :else + (try + (let [expr (if file (read-file file) expression)] + (if expr + (loop [in (read-next *in*)] + (let [ctx (update-in ctx [:namespaces 'user] assoc (with-meta '*input* + (when-not stream? + {:sci.impl/deref! true})) + (sci/new-dynamic-var '*input* in))] + (if (identical? ::EOF in) + [nil 0] ;; done streaming + (let [res [(let [res (eval-string expr ctx)] + (when (some? res) + (if-let [pr-f (cond shell-out println + edn-out prn)] + (if (coll? res) + (doseq [l res + :while (not (pipe-signal-received?))] + (pr-f l)) + (pr-f res)) + (prn res)))) 0]] + (if stream? + (recur (read-next *in*)) + res))))) + [(start-repl! ctx #(read-next *in*)) 0])) + (catch Throwable e + (binding [*out* *err*] + (let [d (ex-data e) + exit-code (:bb/exit-code d)] + (if exit-code [nil exit-code] + (do (if verbose? + (print-stack-trace e) + (println (.getMessage e))) + (flush) + [nil 1])))))))) + 1)) t1 (System/currentTimeMillis)] (when time? (binding [*out* *err*] (println "bb took" (str (- t1 t0) "ms.")))) diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 7a63b3ce..da304cbb 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -319,6 +319,9 @@ (is (thrown-with-msg? Exception #"error.bb" (bb nil (.getPath (io/file "test" "babashka" "scripts" "error.bb")))))) +(deftest compatibility-test + (is (true? (bb nil "(set! *warn-on-reflection* true)")))) + ;;;; Scratch (comment