Fix coding convention & introduce more semantic type for differnt kinds of uri
This commit is contained in:
parent
bd2e3ba250
commit
25bb5b259c
1 changed files with 13 additions and 11 deletions
|
@ -19,7 +19,9 @@
|
||||||
|
|
||||||
(def Prefix s/Str)
|
(def Prefix s/Str)
|
||||||
|
|
||||||
(def Uri s/Any) ; java.net.URI
|
(def FilesystemUri s/Any) ; java.net.URI
|
||||||
|
|
||||||
|
(def ResourceUri s/Any) ; java.net.URI
|
||||||
|
|
||||||
(def ShortPath s/Str)
|
(def ShortPath s/Str)
|
||||||
|
|
||||||
|
@ -27,7 +29,7 @@
|
||||||
|
|
||||||
(def Resource
|
(def Resource
|
||||||
{:short-path ShortPath
|
{:short-path ShortPath
|
||||||
:uri Uri
|
:uri ResourceUri
|
||||||
:java-path JavaPath
|
:java-path JavaPath
|
||||||
:source-type SourceType
|
:source-type SourceType
|
||||||
:resource-type ResourceType})
|
:resource-type ResourceType})
|
||||||
|
@ -50,7 +52,7 @@
|
||||||
|
|
||||||
(s/defn create-resource :- Resource
|
(s/defn create-resource :- Resource
|
||||||
([short-path :- ShortPath
|
([short-path :- ShortPath
|
||||||
uri :- Uri
|
uri :- ResourceUri
|
||||||
java-path :- JavaPath
|
java-path :- JavaPath
|
||||||
source-type :- SourceType
|
source-type :- SourceType
|
||||||
resource-type :- ResourceType]
|
resource-type :- ResourceType]
|
||||||
|
@ -75,9 +77,9 @@
|
||||||
[resource :- Resource]
|
[resource :- Resource]
|
||||||
(= :file (:resource-type resource)))
|
(= :file (:resource-type resource)))
|
||||||
|
|
||||||
(s/defn create-FileSystem
|
(s/defn init-FileSystem
|
||||||
[Resourece-Uri :- Uri]
|
[resource-uri :- ResourceUri]
|
||||||
(let [path-to-filesystem (st/join (pop (st/split (.toString Resourece-Uri) #"!")))]
|
(let [path-to-filesystem (st/join (pop (st/split (.toString resource-uri) #"!")))]
|
||||||
(try
|
(try
|
||||||
(FileSystems/newFileSystem
|
(FileSystems/newFileSystem
|
||||||
(java.net.URI. path-to-filesystem)
|
(java.net.URI. path-to-filesystem)
|
||||||
|
@ -89,11 +91,11 @@
|
||||||
(s/defn path-from-cp ; :- JavaPath
|
(s/defn path-from-cp ; :- JavaPath
|
||||||
[resource-path :- ShortPath]
|
[resource-path :- ShortPath]
|
||||||
(try
|
(try
|
||||||
(let [Resource-Uri (.toURI (io/resource resource-path))] ; check if contains jar:
|
(let [resource-uri (.toURI (io/resource resource-path))] ; check if contains jar:
|
||||||
(when (st/starts-with? (.toString Resource-Uri) "jar:")
|
(when (st/starts-with? (.toString resource-uri) "jar:")
|
||||||
(create-FileSystem Resource-Uri))
|
(init-FileSystem resource-uri))
|
||||||
(when (Files/exists (Paths/get Resource-Uri) NoLinkOption)
|
(when (Files/exists (Paths/get resource-uri) NoLinkOption)
|
||||||
(Paths/get Resource-Uri)))
|
(Paths/get resource-uri)))
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue