From b84e02c12f6c95a4dd31da7ee6aeea4ec54fce2c Mon Sep 17 00:00:00 2001 From: jem Date: Mon, 20 Jan 2020 21:35:01 +0100 Subject: [PATCH] reduce regexmania while using given java functions --- src/cryogen_core/classpath_able_io.clj | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/cryogen_core/classpath_able_io.clj b/src/cryogen_core/classpath_able_io.clj index 74bc1f6..7fbac90 100644 --- a/src/cryogen_core/classpath_able_io.clj +++ b/src/cryogen_core/classpath_able_io.clj @@ -35,6 +35,8 @@ :resource-type ResourceType}) ; ----------------------- Domain functions ------------------------ +(def no-link-option (into-array [LinkOption/NOFOLLOW_LINKS])) + (s/defn create-resource :- Resource ([short-path :- ShortPath uri :- ResourceUri @@ -67,11 +69,8 @@ (filter #(not (re-matches ignore-patterns %)) source-list)) ; ------------------- infra --------------------------------- - (def public "resources/public") -(def no-link-option (into-array [LinkOption/NOFOLLOW_LINKS])) - (defn current-path []) (defn user-dir [] @@ -79,7 +78,10 @@ (defn absolut-path [& path-elements] - (Paths/get (user-dir) (into-array String path-elements))) + (let [path (Paths/get (first path-elements) (into-array String (rest path-elements)))] + (if (.isAbsolute path) + path + (Paths/get (user-dir) (into-array String path-elements))))) (defn path "Creates path from given parts, ignore empty elements" @@ -118,14 +120,6 @@ (catch Exception e nil)))) -(s/defn construct-full-path - [fs-prefix - base-path - resource-path] - (if (st/starts-with? fs-prefix "./") - (str (st/replace fs-prefix #"\./" (str (user-dir) "/")) "/" base-path "/" resource-path) - (str fs-prefix "/" base-path "/" resource-path))) - (defn resource-from-cp-or-fs ; :- Resource [fs-prefix ; :- Prefix base-path ; :- ShortPath @@ -133,7 +127,7 @@ & {:keys [from-cp from-fs] :or {from-cp true from-fs true}}] - (let [full-path (construct-full-path fs-prefix base-path resource-path) + (let [full-path (.toString (absolut-path fs-prefix base-path resource-path)) cp-path (if (empty? base-path) resource-path (str base-path "/" resource-path))