File tree 6 files changed +46
-3
lines changed
6 files changed +46
-3
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
3
## Unreleased
4
+ ### Added
5
+ - Support for listing in resource filesystem.
4
6
5
7
## [ 1.2.3] - 2023-01-09
6
8
### Fixed
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ Features:
19
19
| [ hdfs] ( #hdfs ) | • | • | • | • | • | • | • | • | ` hdfs://[host]/path/to/file.txt ` |
20
20
| [ http(s)] ( #https ) | • | | :cat : | :cat : | | | | | ` http[s]://host[:port]/path/to/file.txt ` |
21
21
| [ mem] ( #mem ) | • | • | • | • | • | • | • | • | ` mem:///path/to/file.txt ` |
22
- | [ res] ( #res ) | • | | | • | | | | | ` res:///com/mypackage/file.txt ` |
22
+ | [ res] ( #res ) | • | | | • | | | • | | ` res:///com/mypackage/file.txt ` |
23
23
| [ s3] ( #s3 ) | • | • | • | • | • | :dog : | • | • | ` s3://bucket/key/with/slashes.txt ` |
24
24
| [ sftp] ( #sftp ) | • | :bug : | • | • | :pig : | • | • | • | ` sftp://host[:port]/path/to/file.txt ` |
25
25
Original file line number Diff line number Diff line change 40
40
" -target" " 1.8"
41
41
" -Xlint:deprecation"
42
42
" -Xlint:unchecked" ]
43
+ :resource-paths [" resources" ]
43
44
44
45
:profiles {:dev {:dependencies [[midje " 1.9.2" ]]
45
46
:plugins [[lein-midje " 3.2.1" ]]}}
Original file line number Diff line number Diff line change
1
+ gdbg
Original file line number Diff line number Diff line change 4
4
; ^^^ triple slash
5
5
;
6
6
(ns uio.fs.res
7
- (:require [uio.impl :refer :all ])
8
- (:import (clojure.java.api Clojure)))
7
+ (:require
8
+ [uio.impl :refer :all ])
9
+ (:import (clojure.java.api Clojure)
10
+ (java.io File)))
9
11
10
12
(defn assert-res-url [url]
11
13
(if (host url)
20
22
(defmethod exists? :res [url & args] (if (.getResource Clojure (path (assert-res-url url)))
21
23
true
22
24
false ))
25
+
26
+ (defmethod ls :res [url & args]
27
+ (->>
28
+ (.substring (path (normalize url)) 1 ) ; get path and remove leading slash
29
+ (.getResources (.getClassLoader Clojure)) ; Multiple resources can have the same name
30
+ (enumeration-seq )
31
+ (map #(File. (.getPath %)))
32
+ (map #(if (.isFile %)
33
+ %
34
+ (seq (.listFiles %))))
35
+ (flatten ) ; If it's a directory, flatten the list of files.
36
+ (map #(do {:url (str " file://" %)})))) ; expected format is a list of maps
Original file line number Diff line number Diff line change
1
+ (ns uio.fs.test-res
2
+ (:require [midje.sweet :refer :all ]
3
+ [uio.fs.mem :refer :all ]
4
+ [uio.impl :refer :all ]))
5
+
6
+ (facts " from"
7
+ (slurp (from " res:///test/test.txt" )) => " gdbg\n " )
8
+
9
+ (facts " exists"
10
+ (exists? " res:///" ) => true
11
+ (exists? " res:///test" ) => true
12
+ (exists? " res:///test/" ) => true
13
+ (exists? " res:///test/te" ) => false
14
+ (exists? " res:///test/test.txt" ) => true )
15
+
16
+ (facts " Listing"
17
+ (fact " listing root succeeds"
18
+ (ls " res:///" ) =not=> [])
19
+ (fact " listing test dir gives correct results"
20
+ (count (ls " res:///test/" )) => 1
21
+ (:url (first (ls " res:///test" ))) => (has-suffix " test/test.txt" )
22
+ (:url (first (ls " res:///test/" ))) => (has-suffix " test/test.txt" ))
23
+ (fact " listing test file returns just the same file"
24
+ (count (ls " res:///test/test.txt" )) => 1
25
+ (:url (first (ls " res:///test/test.txt" ))) => (has-suffix " test/test.txt" )))
You can’t perform that action at this time.
0 commit comments