[#105] initial support for java.nio.file.Files
This commit is contained in:
parent
51b61a921e
commit
1885c45255
5 changed files with 79 additions and 11 deletions
|
|
@ -179,12 +179,14 @@ The following Java classes are available:
|
||||||
- `clojure.lang.ExceptionInfo`
|
- `clojure.lang.ExceptionInfo`
|
||||||
- `Integer`
|
- `Integer`
|
||||||
- `java.io.File`
|
- `java.io.File`
|
||||||
|
- `java.nio.Files`
|
||||||
- `java.util.regex.Pattern`
|
- `java.util.regex.Pattern`
|
||||||
- `String`
|
- `String`
|
||||||
- `System`
|
- `System`
|
||||||
- `Thread`
|
- `Thread`
|
||||||
|
|
||||||
More classes can be added by request.
|
More classes can be added by request. See `reflection.json` and the `:classes`
|
||||||
|
option in `main.clj`.
|
||||||
|
|
||||||
Babashka supports `import` : `(import clojure.lang.ExceptionInfo)`.
|
Babashka supports `import` : `(import clojure.lang.ExceptionInfo)`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,5 +121,45 @@
|
||||||
{
|
{
|
||||||
"name":"java.lang.UNIXProcess",
|
"name":"java.lang.UNIXProcess",
|
||||||
"allPublicMethods":true
|
"allPublicMethods":true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"java.nio.file.Path",
|
||||||
|
"allPublicMethods":true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"java.nio.file.CopyOption",
|
||||||
|
"allPublicMethods":true,
|
||||||
|
"allPublicFields": true,
|
||||||
|
"allPublicConstructors": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"java.nio.file.FileAlreadyExistsException",
|
||||||
|
"allPublicMethods":true,
|
||||||
|
"allPublicFields": true,
|
||||||
|
"allPublicConstructors": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"java.nio.file.Files",
|
||||||
|
"allPublicMethods":true,
|
||||||
|
"allPublicFields": true,
|
||||||
|
"allPublicConstructors": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"java.nio.file.NoSuchFileException",
|
||||||
|
"allPublicMethods":true,
|
||||||
|
"allPublicFields": true,
|
||||||
|
"allPublicConstructors": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"java.nio.file.StandardCopyOption",
|
||||||
|
"allPublicMethods":true,
|
||||||
|
"allPublicFields": true,
|
||||||
|
"allPublicConstructors": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"sun.nio.fs.UnixPath",
|
||||||
|
"allPublicMethods":true,
|
||||||
|
"allPublicFields": true,
|
||||||
|
"allPublicConstructors": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
2
sci
2
sci
|
|
@ -1 +1 @@
|
||||||
Subproject commit d91bf4bf1b831de58a4980379558aed6ce28a641
|
Subproject commit 736880b590e6df75e928a826f1aa24e17a613c67
|
||||||
|
|
@ -227,7 +227,14 @@ Everything after that is bound to *command-line-args*."))
|
||||||
'java.io.StringReader java.io.StringReader
|
'java.io.StringReader java.io.StringReader
|
||||||
'java.io.StringWriter java.io.StringWriter
|
'java.io.StringWriter java.io.StringWriter
|
||||||
'java.lang.System System
|
'java.lang.System System
|
||||||
'java.lang.Thread Thread}
|
'java.lang.Thread Thread
|
||||||
|
'sun.nio.fs.UnixPath sun.nio.fs.UnixPath
|
||||||
|
'java.nio.file.CopyOption java.nio.file.CopyOption
|
||||||
|
'java.nio.file.FileAlreadyExistsException java.nio.file.FileAlreadyExistsException
|
||||||
|
'java.nio.file.Files java.nio.file.Files
|
||||||
|
'java.nio.file.NoSuchFileException java.nio.file.NoSuchFileException
|
||||||
|
'java.nio.file.StandardCopyOption java.nio.file.StandardCopyOption
|
||||||
|
}
|
||||||
:imports '{ArithmeticException java.lang.ArithmeticException
|
:imports '{ArithmeticException java.lang.ArithmeticException
|
||||||
AssertionError java.lang.AssertionError
|
AssertionError java.lang.AssertionError
|
||||||
Boolean java.lang.Boolean
|
Boolean java.lang.Boolean
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@
|
||||||
|
|
||||||
(deftest eval-test
|
(deftest eval-test
|
||||||
(is (= "120\n" (test-utils/bb nil "(eval '(do (defn foo [x y] (+ x y))
|
(is (= "120\n" (test-utils/bb nil "(eval '(do (defn foo [x y] (+ x y))
|
||||||
(defn bar [x y] (* x y))
|
(defn bar [x y] (* x y))
|
||||||
(bar (foo 10 30) 3)))"))))
|
(bar (foo 10 30) 3)))"))))
|
||||||
|
|
||||||
(deftest preloads-test
|
(deftest preloads-test
|
||||||
|
|
@ -177,16 +177,16 @@
|
||||||
(deftest create-temp-file-test
|
(deftest create-temp-file-test
|
||||||
(let [temp-dir-path (System/getProperty "java.io.tmpdir")]
|
(let [temp-dir-path (System/getProperty "java.io.tmpdir")]
|
||||||
(is (= true
|
(is (= true
|
||||||
(bb nil (format "(let [tdir (io/file \"%s\")
|
(bb nil (format "(let [tdir (io/file \"%s\")
|
||||||
tfile
|
tfile
|
||||||
(File/createTempFile \"ctf\" \"tmp\" tdir)]
|
(File/createTempFile \"ctf\" \"tmp\" tdir)]
|
||||||
(.deleteOnExit tfile) ; for cleanup
|
(.deleteOnExit tfile) ; for cleanup
|
||||||
(.exists tfile))"
|
(.exists tfile))"
|
||||||
temp-dir-path))))))
|
temp-dir-path))))))
|
||||||
|
|
||||||
(deftest wait-for-port-test
|
(deftest wait-for-port-test
|
||||||
(is (= :timed-out
|
(is (= :timed-out
|
||||||
(bb nil "(def web-server (conch/proc \"python\" \"-m\" \"SimpleHTTPServer\" \"7171\"))
|
(bb nil "(def web-server (conch/proc \"python\" \"-m\" \"SimpleHTTPServer\" \"7171\"))
|
||||||
(wait/wait-for-port \"127.0.0.1\" 7171)
|
(wait/wait-for-port \"127.0.0.1\" 7171)
|
||||||
(conch/destroy web-server)
|
(conch/destroy web-server)
|
||||||
(wait/wait-for-port \"localhost\" 7172 {:default :timed-out :timeout 50})"))))
|
(wait/wait-for-port \"localhost\" 7172 {:default :timed-out :timeout 50})"))))
|
||||||
|
|
@ -194,7 +194,7 @@
|
||||||
(deftest wait-for-path-test
|
(deftest wait-for-path-test
|
||||||
(let [temp-dir-path (System/getProperty "java.io.tmpdir")]
|
(let [temp-dir-path (System/getProperty "java.io.tmpdir")]
|
||||||
(is (not= :timed-out
|
(is (not= :timed-out
|
||||||
(bb nil (format "(let [tdir (io/file \"%s\")
|
(bb nil (format "(let [tdir (io/file \"%s\")
|
||||||
tfile
|
tfile
|
||||||
(File/createTempFile \"wfp\" \"tmp\" tdir)
|
(File/createTempFile \"wfp\" \"tmp\" tdir)
|
||||||
tpath (.getPath tfile)]
|
tpath (.getPath tfile)]
|
||||||
|
|
@ -203,16 +203,16 @@
|
||||||
(wait/wait-for-path tpath
|
(wait/wait-for-path tpath
|
||||||
{:default :timed-out :timeout 100})
|
{:default :timed-out :timeout 100})
|
||||||
(.delete tfile))"
|
(.delete tfile))"
|
||||||
temp-dir-path))))
|
temp-dir-path))))
|
||||||
(is (= :timed-out
|
(is (= :timed-out
|
||||||
(bb nil (format "(let [tdir (io/file \"%s\")
|
(bb nil (format "(let [tdir (io/file \"%s\")
|
||||||
tfile
|
tfile
|
||||||
(File/createTempFile \"wfp-to\" \"tmp\" tdir)
|
(File/createTempFile \"wfp-to\" \"tmp\" tdir)
|
||||||
tpath (.getPath tfile)]
|
tpath (.getPath tfile)]
|
||||||
(.delete tfile) ; for timing out test and cleanup
|
(.delete tfile) ; for timing out test and cleanup
|
||||||
(wait/wait-for-path tpath
|
(wait/wait-for-path tpath
|
||||||
{:default :timed-out :timeout 100}))"
|
{:default :timed-out :timeout 100}))"
|
||||||
temp-dir-path))))))
|
temp-dir-path))))))
|
||||||
|
|
||||||
(deftest async-test
|
(deftest async-test
|
||||||
(is (= "process 2\n" (test-utils/bb nil "
|
(is (= "process 2\n" (test-utils/bb nil "
|
||||||
|
|
@ -269,3 +269,22 @@
|
||||||
|
|
||||||
(deftest with-in-str-test
|
(deftest with-in-str-test
|
||||||
(is (= 5 (bb nil "(count (with-in-str \"hello\" (read-line)))"))))
|
(is (= 5 (bb nil "(count (with-in-str \"hello\" (read-line)))"))))
|
||||||
|
|
||||||
|
(deftest java-nio-test
|
||||||
|
(let [f (java.io.File/createTempFile "foo" "bar")
|
||||||
|
temp-path (.getPath f)
|
||||||
|
p (.toPath (io/file f))
|
||||||
|
p' (.resolveSibling p "f2")
|
||||||
|
f2 (.toFile p')]
|
||||||
|
(bb nil (format
|
||||||
|
"(let [f (io/file \"%s\")
|
||||||
|
p (.toPath (io/file f))
|
||||||
|
p' (.resolveSibling p \"f2\")]
|
||||||
|
(.delete (.toFile p'))
|
||||||
|
(dotimes [_ 2]
|
||||||
|
(try
|
||||||
|
(java.nio.file.Files/copy p p' (into-array java.nio.file.CopyOption []))
|
||||||
|
(catch java.nio.file.FileAlreadyExistsException _
|
||||||
|
(java.nio.file.Files/copy p p' (into-array [java.nio.file.StandardCopyOption/REPLACE_EXISTING]))))))"
|
||||||
|
temp-path))
|
||||||
|
(is (.exists f2))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue