some kind of listing jar directories
This commit is contained in:
parent
75b887d326
commit
4643343a02
3 changed files with 45 additions and 9 deletions
|
@ -11,6 +11,7 @@
|
||||||
[clojure.string :as st]
|
[clojure.string :as st]
|
||||||
[schema.core :as s])
|
[schema.core :as s])
|
||||||
(:import [java.net URI]
|
(:import [java.net URI]
|
||||||
|
[java.util.jar JarFile JarEntry]
|
||||||
[java.nio.file FileSystems Paths Files SimpleFileVisitor LinkOption StandardCopyOption]
|
[java.nio.file FileSystems Paths Files SimpleFileVisitor LinkOption StandardCopyOption]
|
||||||
[java.nio.file.attribute FileAttribute]))
|
[java.nio.file.attribute FileAttribute]))
|
||||||
|
|
||||||
|
@ -93,13 +94,17 @@
|
||||||
(st/join "/")
|
(st/join "/")
|
||||||
(#(st/replace % #"/+" "/"))))
|
(#(st/replace % #"/+" "/"))))
|
||||||
|
|
||||||
|
(s/defn
|
||||||
|
filesystem-uri
|
||||||
|
[resource-uri :- JavaUri]
|
||||||
|
(URI. (first (st/split (.toString resource-uri) #"!"))))
|
||||||
|
|
||||||
(s/defn init-file-system
|
(s/defn init-file-system
|
||||||
[resource-uri :- JavaUri]
|
[resource-uri :- JavaUri]
|
||||||
(let [filesystem-uri (URI. (first (st/split (.toString resource-uri) #"!")))]
|
(try
|
||||||
(try
|
(FileSystems/getFileSystem (filesystem-uri resource-uri))
|
||||||
(FileSystems/getFileSystem filesystem-uri)
|
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(FileSystems/newFileSystem filesystem-uri {})))))
|
(FileSystems/newFileSystem (filesystem-uri resource-uri) {}))))
|
||||||
|
|
||||||
; contains either a jar or a file
|
; contains either a jar or a file
|
||||||
(s/defn path-from-cp ;:- JavaPath
|
(s/defn path-from-cp ;:- JavaPath
|
||||||
|
@ -160,9 +165,24 @@
|
||||||
(when (some? resource)
|
(when (some? resource)
|
||||||
(:java-path resource))))
|
(:java-path resource))))
|
||||||
|
|
||||||
(s/defn list-entries-for-dir ;:- [VirtualPath]
|
(s/defn
|
||||||
|
list-entries-for-dir ;:- [VirtualPath]
|
||||||
[resource :- Resource]
|
[resource :- Resource]
|
||||||
(.list (io/file (.toString (:java-path resource))))) ; TODO doesnt work in jars
|
(if (= :java-classpath-jar (:source-type resource))
|
||||||
|
(filter
|
||||||
|
(fn [je] (and (st/starts-with? je (:virtual-path resource))
|
||||||
|
(not (= je (str (:virtual-path resource) "/")))))
|
||||||
|
(map #(.getName ^JarEntry %)
|
||||||
|
(enumeration-seq
|
||||||
|
(.entries
|
||||||
|
(JarFile.
|
||||||
|
(.toFile
|
||||||
|
(Paths/get
|
||||||
|
(URI.
|
||||||
|
(.getSchemeSpecificPart
|
||||||
|
(filesystem-uri (:java-uri resource)))))))))))
|
||||||
|
; Bsp-Code: https://github.com/clojure/java.classpath/blob/c10fc96a8ff98db4eb925a13ef0f5135ad8dacc6/src/main/clojure/clojure/java/classpath.clj#L50
|
||||||
|
(.list (.toFile (:java-path resource)))))
|
||||||
|
|
||||||
(defn get-resources-recursive ;:- [Resource]
|
(defn get-resources-recursive ;:- [Resource]
|
||||||
[fs-prefix ;:- Prefix
|
[fs-prefix ;:- Prefix
|
||||||
|
@ -193,7 +213,6 @@
|
||||||
:else
|
:else
|
||||||
(recur (into (drop 1 paths)
|
(recur (into (drop 1 paths)
|
||||||
(map #(str path-to-work-with "/" %)
|
(map #(str path-to-work-with "/" %)
|
||||||
; Bsp-Code: https://github.com/clojure/java.classpath/blob/c10fc96a8ff98db4eb925a13ef0f5135ad8dacc6/src/main/clojure/clojure/java/classpath.clj#L50
|
|
||||||
(list-entries-for-dir resource-to-work-with)))
|
(list-entries-for-dir resource-to-work-with)))
|
||||||
result))))
|
result))))
|
||||||
result)))
|
result)))
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
"./not-existing-so-load-from-cp"
|
"./not-existing-so-load-from-cp"
|
||||||
"templates/themes/bootstrap4-test"
|
"templates/themes/bootstrap4-test"
|
||||||
"js/subdir")))))
|
"js/subdir")))))
|
||||||
(is (= ["dummy-from-jar"]
|
(is (= ["dummy_from_jar"]
|
||||||
(sut/list-entries-for-dir (sut/resource-from-cp-or-fs
|
(sut/list-entries-for-dir (sut/resource-from-cp-or-fs
|
||||||
"not-existing-filesystem-path"
|
"not-existing-filesystem-path"
|
||||||
""
|
""
|
||||||
|
|
|
@ -24,3 +24,20 @@ TODO: to solve reading from jars:
|
||||||
""
|
""
|
||||||
"dummy"))
|
"dummy"))
|
||||||
|
|
||||||
|
|
||||||
|
(filter
|
||||||
|
#(str/starts-with? % "dummy")
|
||||||
|
(map
|
||||||
|
#(.getName ^JarEntry %)
|
||||||
|
(enumeration-seq
|
||||||
|
(.entries
|
||||||
|
(JarFile.
|
||||||
|
(.toFile
|
||||||
|
(Paths/get
|
||||||
|
(URI.
|
||||||
|
(.getSchemeSpecificPart
|
||||||
|
(filesystem-uri
|
||||||
|
(:java-uri (resource-from-cp-or-fs
|
||||||
|
"not-existing-filesystem-path"
|
||||||
|
""
|
||||||
|
"dummy"))))))))))))
|
||||||
|
|
Loading…
Reference in a new issue