Use list of jar-entries instead of recursion for jar/get-resources
This commit is contained in:
parent
b466d14d4c
commit
3bc2035173
1 changed files with 34 additions and 36 deletions
|
@ -48,6 +48,7 @@
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(FileSystems/newFileSystem (filesystem-uri resource-uri) {}))))
|
(FileSystems/newFileSystem (filesystem-uri resource-uri) {}))))
|
||||||
|
|
||||||
|
; (path-if-exists "") => ".../test"
|
||||||
(defn path-if-exists ;:- JavaPath
|
(defn path-if-exists ;:- JavaPath
|
||||||
[& path-elements ;:- VirtualPath
|
[& path-elements ;:- VirtualPath
|
||||||
]
|
]
|
||||||
|
@ -66,15 +67,17 @@
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
(defn filter-and-remove-for-dir
|
(defn filter-and-remove-for-dir
|
||||||
[path-to-filter-for
|
[base-path-to-filter-for
|
||||||
elements-list]
|
elements-list]
|
||||||
(let [norm-path-to-filter-for (str path-to-filter-for "/")]
|
|
||||||
(map
|
(map
|
||||||
#(subs % (count norm-path-to-filter-for))
|
(fn [el]
|
||||||
|
(if (st/ends-with? el "/")
|
||||||
|
(st/join "" (drop-last el))
|
||||||
|
el))
|
||||||
(filter
|
(filter
|
||||||
(fn [element] (and (st/starts-with? element norm-path-to-filter-for)
|
(fn [element] (and (st/starts-with? element base-path-to-filter-for)
|
||||||
(not (= element norm-path-to-filter-for))))
|
(not (= element base-path-to-filter-for))))
|
||||||
elements-list))))
|
elements-list)))
|
||||||
|
|
||||||
(defn jar-file-for-resource
|
(defn jar-file-for-resource
|
||||||
[resource]
|
[resource]
|
||||||
|
@ -85,38 +88,33 @@
|
||||||
(.getSchemeSpecificPart
|
(.getSchemeSpecificPart
|
||||||
(filesystem-uri (:java-uri resource))))))))
|
(filesystem-uri (:java-uri resource))))))))
|
||||||
|
|
||||||
|
(defn list-entries ;:- [s/Str]
|
||||||
|
[resource ;:- Resource
|
||||||
|
]
|
||||||
|
(map #(.getName ^JarEntry %)
|
||||||
|
(enumeration-seq
|
||||||
|
(.entries
|
||||||
|
(jar-file-for-resource resource)))))
|
||||||
|
|
||||||
(defn list-entries-for-dir ;:- [VirtualPath]
|
(defn list-entries-for-dir ;:- [VirtualPath]
|
||||||
[resource ;:- Resource
|
[resource ;:- Resource
|
||||||
]
|
]
|
||||||
(filter-and-remove-for-dir
|
(filter-and-remove-for-dir
|
||||||
(:virtual-path resource)
|
(:virtual-path resource)
|
||||||
(map #(.getName ^JarEntry %)
|
(list-entries resource)))
|
||||||
(enumeration-seq
|
|
||||||
(.entries
|
|
||||||
(jar-file-for-resource resource))))))
|
|
||||||
|
|
||||||
; TODO: Statt rekursion list-entries-for-dir direkt verwenden
|
|
||||||
(defn get-resources;:- [Resource]
|
(defn get-resources;:- [Resource]
|
||||||
[base-path ;:- VirtualPath
|
[base-path ;:- VirtualPath
|
||||||
paths ;:- [VirtualPath]
|
paths ;:- [VirtualPath]
|
||||||
]
|
]
|
||||||
(loop [paths paths
|
(let [entry-list (flatten
|
||||||
result []]
|
(map
|
||||||
(if (not (empty? paths))
|
(fn [p]
|
||||||
(do
|
(let [p (if (empty? base-path) p (str base-path "/" p))]
|
||||||
(let [path-to-work-with (first paths)
|
(list-entries-for-dir
|
||||||
resource-to-work-with (create-resource
|
(create-resource p
|
||||||
path-to-work-with
|
(path-if-exists p)))))
|
||||||
(path-if-exists base-path path-to-work-with))
|
paths))]
|
||||||
result (into result
|
(map (fn [entry]
|
||||||
[resource-to-work-with])]
|
(create-resource entry (path-if-exists entry)))
|
||||||
(cond
|
entry-list)))
|
||||||
(nil? resource-to-work-with) []
|
|
||||||
(type/is-file? resource-to-work-with)
|
|
||||||
(recur (drop 1 paths) result)
|
|
||||||
:else
|
|
||||||
(recur (into (drop 1 paths)
|
|
||||||
(map #(str path-to-work-with "/" %)
|
|
||||||
(list-entries-for-dir resource-to-work-with)))
|
|
||||||
result))))
|
|
||||||
result)))
|
|
||||||
|
|
Loading…
Reference in a new issue