From 25bb5b259c755a7fc8918b7da54725b665dc83d4 Mon Sep 17 00:00:00 2001 From: jem Date: Fri, 17 Jan 2020 18:38:38 +0100 Subject: [PATCH] Fix coding convention & introduce more semantic type for differnt kinds of uri --- src/cryogen_core/classpath_able_io.clj | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/cryogen_core/classpath_able_io.clj b/src/cryogen_core/classpath_able_io.clj index 2d2761f..04091ab 100644 --- a/src/cryogen_core/classpath_able_io.clj +++ b/src/cryogen_core/classpath_able_io.clj @@ -19,7 +19,9 @@ (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) @@ -27,7 +29,7 @@ (def Resource {:short-path ShortPath - :uri Uri + :uri ResourceUri :java-path JavaPath :source-type SourceType :resource-type ResourceType}) @@ -50,7 +52,7 @@ (s/defn create-resource :- Resource ([short-path :- ShortPath - uri :- Uri + uri :- ResourceUri java-path :- JavaPath source-type :- SourceType resource-type :- ResourceType] @@ -75,9 +77,9 @@ [resource :- Resource] (= :file (:resource-type resource))) -(s/defn create-FileSystem - [Resourece-Uri :- Uri] - (let [path-to-filesystem (st/join (pop (st/split (.toString Resourece-Uri) #"!")))] +(s/defn init-FileSystem + [resource-uri :- ResourceUri] + (let [path-to-filesystem (st/join (pop (st/split (.toString resource-uri) #"!")))] (try (FileSystems/newFileSystem (java.net.URI. path-to-filesystem) @@ -89,11 +91,11 @@ (s/defn path-from-cp ; :- JavaPath [resource-path :- ShortPath] (try - (let [Resource-Uri (.toURI (io/resource resource-path))] ; check if contains jar: - (when (st/starts-with? (.toString Resource-Uri) "jar:") - (create-FileSystem Resource-Uri)) - (when (Files/exists (Paths/get Resource-Uri) NoLinkOption) - (Paths/get Resource-Uri))) + (let [resource-uri (.toURI (io/resource resource-path))] ; check if contains jar: + (when (st/starts-with? (.toString resource-uri) "jar:") + (init-FileSystem resource-uri)) + (when (Files/exists (Paths/get resource-uri) NoLinkOption) + (Paths/get resource-uri))) (catch Exception e nil)))