[#310] add java.nio.file.FileSystem(s) (#311)

This commit is contained in:
Michiel Borkent 2020-03-28 00:27:32 +01:00 committed by GitHub
parent 492a26813f
commit 1105c4676e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 3 deletions

View file

@ -61,6 +61,9 @@ $ BABASHKA_XMX="-J-Xmx4g" script/compile
Keep notes here about how adding libraries and classes to Babashka affects the binary size.
2020/03/28 Added java.nio.file.FileSystem(s) to support extracting zip files
42562284 - 42021244 = 541kb added.
2020/03/22 Added java.io.FileReader
42025276 - 42008876 = 16kb added.

View file

@ -56,6 +56,8 @@
java.net.URLDecoder
java.nio.file.CopyOption
java.nio.file.FileAlreadyExistsException
java.nio.file.FileSystem
java.nio.file.FileSystems
java.nio.file.Files
java.nio.file.LinkOption
java.nio.file.NoSuchFileException
@ -201,7 +203,9 @@
(instance? java.security.MessageDigest v)
java.security.MessageDigest
(instance? java.io.InputStream v)
java.io.InputStream)))))
java.io.InputStream
(instance? java.nio.file.FileSystem v)
java.nio.file.FileSystem)))))
(def class-map (gen-class-map))

View file

@ -1,8 +1,8 @@
(ns babashka.file-var-test
(:require
[babashka.test-utils :as tu]
[clojure.test :as t :refer [deftest is]]
[clojure.string :as str]))
[clojure.string :as str]
[clojure.test :as t :refer [deftest is]]))
(defn bb [input & args]
(apply tu/bb (when (some? input) (str input)) (map str args)))

View file

@ -375,6 +375,9 @@
(prn "output:" v)
(is v))))
(deftest download-and-extract-test
(is (= 6 (bb nil (io/file "test" "babashka" "scripts" "download_and_extract_zip.bb")))))
;;;; Scratch
(comment

View file

@ -0,0 +1,31 @@
(require '[clojure.java.io :as io] '[clojure.java.shell :refer [sh]] '[clojure.string :as str])
(import '[java.net URL HttpURLConnection])
(set! *warn-on-reflection* true)
(let [os-name (System/getProperty "os.name")
os-name (str/lower-case os-name)
os (cond (str/includes? os-name "linux") "linux"
(str/includes? os-name "mac") "macos"
(str/includes? os-name "win") "windows")
tmp-dir (System/getProperty "java.io.tmpdir")
zip-file (io/file tmp-dir "bb-0.0.78.zip")
source (URL. (format "https://github.com/borkdude/babashka/releases/download/v0.0.78/babashka-0.0.78-%s-amd64.zip" os))
conn ^HttpURLConnection (.openConnection ^URL source)]
(.connect conn)
(with-open [is (.getInputStream conn)]
(io/copy is zip-file))
(let [bb-file (io/file tmp-dir "bb-extracted")
fs (java.nio.file.FileSystems/newFileSystem (.toPath zip-file) nil)
to-extract (.getPath fs "bb" (into-array String []))]
(java.nio.file.Files/copy to-extract (.toPath bb-file)
^"[Ljava.nio.file.CopyOption;"
(into-array java.nio.file.CopyOption []))
(.setExecutable bb-file true)
(let [out (:out (sh (.getPath bb-file) "(+ 1 2 3)"))]
(.delete bb-file)
(.delete zip-file)
(println out))))