Remove Unix-specific classes (#227)

This commit is contained in:
Michiel Borkent 2020-01-08 11:48:40 +01:00 committed by GitHub
parent 6633d8b674
commit 2b0cb6fb1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 174 additions and 172 deletions

View file

@ -52,7 +52,7 @@ jobs:
mkdir -p /tmp/release
lein do clean, uberjar
VERSION=$(cat resources/BABASHKA_VERSION)
cp target/babashka-$VERSION-standalone.jar /tmp/release/babashka-$VERSION-linux-standalone.jar
cp target/babashka-$VERSION-standalone.jar /tmp/release/babashka-$VERSION-standalone.jar
- store_artifacts:
path: /tmp/release
destination: release

2
sci

@ -1 +1 @@
Subproject commit d9e6d7396374631731a9cc7b11dedb41281e867d
Subproject commit 1374d2a37b64e3d2216349345ff930b1154e39b3

View file

@ -2,172 +2,166 @@
{:no-doc true}
(:require
[cheshire.core :as json]
[clojure.string :as str]))
#_[clojure.string :as str]))
(def os-name (str/lower-case (System/getProperty "os.name")))
(def os (cond (str/includes? os-name "mac") :mac
(or (str/includes? os-name "nix")
(str/includes? os-name "nux")) :linux
(str/includes? os-name "win") :windows))
(def unix-like? (or (identical? os :linux)
(identical? os :mac)))
;; (def os-name (str/lower-case (System/getProperty "os.name")))
;; (def os (cond (str/includes? os-name "mac") :mac
;; (or (str/includes? os-name "nix")
;; (str/includes? os-name "nux")) :linux
;; (str/includes? os-name "win") :windows))
;; (def unix-like? (or (identical? os :linux)
;; (identical? os :mac)))
(def classes
(cond->
'{:all [java.io.BufferedReader
java.io.BufferedWriter
java.io.ByteArrayInputStream
java.io.ByteArrayOutputStream
java.io.File
java.io.InputStream
java.io.IOException
java.io.OutputStream
java.io.StringReader
java.io.StringWriter
java.lang.ArithmeticException
java.lang.AssertionError
java.lang.Boolean
java.lang.Class
java.lang.Double
java.lang.Exception
java.lang.Integer
java.lang.Math
java.util.concurrent.LinkedBlockingQueue
java.lang.Object
java.lang.String
java.lang.System
java.lang.Throwable
java.lang.Process
java.lang.ProcessBuilder
java.lang.ProcessBuilder$Redirect
java.net.URI
java.net.HttpURLConnection
java.net.ServerSocket
java.net.Socket
java.net.UnknownHostException
java.net.URLEncoder
java.net.URLDecoder
java.nio.file.CopyOption
java.nio.file.FileAlreadyExistsException
java.nio.file.Files
java.nio.file.LinkOption
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.FileTime
java.nio.file.attribute.PosixFilePermission
java.nio.file.attribute.PosixFilePermissions
java.time.format.DateTimeFormatter
java.time.Clock
java.time.DateTimeException
java.time.DayOfWeek
java.time.Duration
java.time.Instant
java.time.LocalDate
java.time.LocalDateTime
java.time.LocalTime
java.time.Month
java.time.MonthDay
java.time.OffsetDateTime
java.time.OffsetTime
java.time.Period
java.time.Year
java.time.YearMonth
java.time.ZonedDateTime
java.time.ZoneId
java.time.ZoneOffset
java.time.temporal.TemporalAccessor
java.util.regex.Pattern
java.util.Base64
java.util.Base64$Decoder
java.util.Base64$Encoder
java.util.Date
java.util.UUID
java.util.concurrent.TimeUnit
java.util.zip.InflaterInputStream
java.util.zip.DeflaterInputStream
java.util.zip.GZIPInputStream
java.util.zip.GZIPOutputStream]
:constructors [clojure.lang.Delay
clojure.lang.MapEntry
clojure.lang.LineNumberingPushbackReader]
:methods [borkdude.graal.LockFix ;; support for locking
]
:fields [clojure.lang.PersistentQueue]
:instance-checks [clojure.lang.ExceptionInfo
clojure.lang.IObj
clojure.lang.IEditableCollection]
:custom {clojure.lang.LineNumberingPushbackReader {:allPublicConstructors true
:allPublicMethods true}
java.lang.Thread
{:allPublicConstructors true
;; generated with `public-declared-method-names`, see in
;; `comment` below
:methods [{:name "activeCount"}
{:name "checkAccess"}
{:name "currentThread"}
{:name "dumpStack"}
{:name "enumerate"}
{:name "getAllStackTraces"}
{:name "getContextClassLoader"}
{:name "getDefaultUncaughtExceptionHandler"}
{:name "getId"}
{:name "getName"}
{:name "getPriority"}
{:name "getStackTrace"}
{:name "getState"}
{:name "getThreadGroup"}
{:name "getUncaughtExceptionHandler"}
{:name "holdsLock"}
{:name "interrupt"}
{:name "interrupted"}
{:name "isAlive"}
{:name "isDaemon"}
{:name "isInterrupted"}
{:name "join"}
{:name "run"}
{:name "setContextClassLoader"}
{:name "setDaemon"}
{:name "setDefaultUncaughtExceptionHandler"}
{:name "setName"}
{:name "setPriority"}
{:name "setUncaughtExceptionHandler"}
{:name "sleep"}
{:name "start"}
{:name "toString"}
{:name "yield"}]}
java.net.URL
{:allPublicConstructors true
:allPublicFields true
;; generated with `public-declared-method-names`, see in
;; `comment` below
:methods [{:name "equals"}
{:name "getAuthority"}
{:name "getContent"}
{:name "getDefaultPort"}
{:name "getFile"}
{:name "getHost"}
{:name "getPath"}
{:name "getPort"}
{:name "getProtocol"}
{:name "getQuery"}
{:name "getRef"}
{:name "getUserInfo"}
{:name "hashCode"}
{:name "openConnection"}
{:name "openStream"}
{:name "sameFile"}
;; not supported: {:name "setURLStreamHandlerFactory"}
{:name "toExternalForm"}
{:name "toString"}
{:name "toURI"}]}}}
unix-like? (->
(update :methods conj 'sun.nio.fs.UnixPath)
(update :all conj
'java.lang.UNIXProcess
'java.lang.UNIXProcess$ProcessPipeOutputStream))))
'{:all [java.io.BufferedReader
java.io.BufferedWriter
java.io.ByteArrayInputStream
java.io.ByteArrayOutputStream
java.io.File
java.io.InputStream
java.io.IOException
java.io.OutputStream
java.io.StringReader
java.io.StringWriter
java.lang.ArithmeticException
java.lang.AssertionError
java.lang.Boolean
java.lang.Class
java.lang.Double
java.lang.Exception
java.lang.Integer
java.lang.Math
java.util.concurrent.LinkedBlockingQueue
java.lang.Object
java.lang.String
java.lang.System
java.lang.Throwable
java.lang.Process
java.lang.ProcessBuilder
java.lang.ProcessBuilder$Redirect
java.net.URI
java.net.HttpURLConnection
java.net.ServerSocket
java.net.Socket
java.net.UnknownHostException
java.net.URLEncoder
java.net.URLDecoder
java.nio.file.CopyOption
java.nio.file.FileAlreadyExistsException
java.nio.file.Files
java.nio.file.LinkOption
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.FileTime
java.nio.file.attribute.PosixFilePermission
java.nio.file.attribute.PosixFilePermissions
java.time.format.DateTimeFormatter
java.time.Clock
java.time.DateTimeException
java.time.DayOfWeek
java.time.Duration
java.time.Instant
java.time.LocalDate
java.time.LocalDateTime
java.time.LocalTime
java.time.Month
java.time.MonthDay
java.time.OffsetDateTime
java.time.OffsetTime
java.time.Period
java.time.Year
java.time.YearMonth
java.time.ZonedDateTime
java.time.ZoneId
java.time.ZoneOffset
java.time.temporal.TemporalAccessor
java.util.regex.Pattern
java.util.Base64
java.util.Base64$Decoder
java.util.Base64$Encoder
java.util.Date
java.util.UUID
java.util.concurrent.TimeUnit
java.util.zip.InflaterInputStream
java.util.zip.DeflaterInputStream
java.util.zip.GZIPInputStream
java.util.zip.GZIPOutputStream]
:constructors [clojure.lang.Delay
clojure.lang.MapEntry
clojure.lang.LineNumberingPushbackReader]
:methods [borkdude.graal.LockFix ;; support for locking
]
:fields [clojure.lang.PersistentQueue]
:instance-checks [clojure.lang.ExceptionInfo
clojure.lang.IObj
clojure.lang.IEditableCollection]
:custom {clojure.lang.LineNumberingPushbackReader {:allPublicConstructors true
:allPublicMethods true}
java.lang.Thread
{:allPublicConstructors true
;; generated with `public-declared-method-names`, see in
;; `comment` below
:methods [{:name "activeCount"}
{:name "checkAccess"}
{:name "currentThread"}
{:name "dumpStack"}
{:name "enumerate"}
{:name "getAllStackTraces"}
{:name "getContextClassLoader"}
{:name "getDefaultUncaughtExceptionHandler"}
{:name "getId"}
{:name "getName"}
{:name "getPriority"}
{:name "getStackTrace"}
{:name "getState"}
{:name "getThreadGroup"}
{:name "getUncaughtExceptionHandler"}
{:name "holdsLock"}
{:name "interrupt"}
{:name "interrupted"}
{:name "isAlive"}
{:name "isDaemon"}
{:name "isInterrupted"}
{:name "join"}
{:name "run"}
{:name "setContextClassLoader"}
{:name "setDaemon"}
{:name "setDefaultUncaughtExceptionHandler"}
{:name "setName"}
{:name "setPriority"}
{:name "setUncaughtExceptionHandler"}
{:name "sleep"}
{:name "start"}
{:name "toString"}
{:name "yield"}]}
java.net.URL
{:allPublicConstructors true
:allPublicFields true
;; generated with `public-declared-method-names`, see in
;; `comment` below
:methods [{:name "equals"}
{:name "getAuthority"}
{:name "getContent"}
{:name "getDefaultPort"}
{:name "getFile"}
{:name "getHost"}
{:name "getPath"}
{:name "getPort"}
{:name "getProtocol"}
{:name "getQuery"}
{:name "getRef"}
{:name "getUserInfo"}
{:name "hashCode"}
{:name "openConnection"}
{:name "openStream"}
{:name "sameFile"}
;; not supported: {:name "setURLStreamHandlerFactory"}
{:name "toExternalForm"}
{:name "toString"}
{:name "toURI"}]}}})
(defmacro gen-class-map []
(let [classes (concat (:all classes)
@ -175,11 +169,17 @@
(:constructors classes)
(:methods classes)
(:fields classes)
(:instance-checks classes))]
(apply hash-map
(for [c classes
c [(list 'quote c) c]]
c))))
(:instance-checks classes))
m (apply hash-map
(for [c classes
c [(list 'quote c) c]]
c))]
(assoc m :public-class
(fn [v]
(cond (instance? java.nio.file.Path v)
java.nio.file.Path
(instance? java.lang.Process v)
java.lang.Process)))))
(def class-map (gen-class-map))

View file

@ -169,6 +169,8 @@
(deftest process-builder-test
(is (str/includes? (bb nil "
(def ls (-> (ProcessBuilder. [\"ls\"]) (.start)))
(def input (.getOutputStream ls))
(.write (io/writer input) \"hello\") ;; dummy test just to see if this works
(def output (.getInputStream ls))
(assert (int? (.waitFor ls)))
(slurp output)")
@ -281,8 +283,8 @@
f2 (.toFile p')]
(bb nil (format
"(let [f (io/file \"%s\")
p (.toPath (io/file f))
p' (.resolveSibling p \"f2\")]
p (.toPath (io/file f))
p' (.resolveSibling p \"f2\")]
(.delete (.toFile p'))
(dotimes [_ 2]
(try