"Mob Session DONE [ci-skip]"
This commit is contained in:
parent
9cd41d54e7
commit
0204170811
2 changed files with 27 additions and 17 deletions
|
@ -3,22 +3,31 @@
|
||||||
[clojure.string :as s]))
|
[clojure.string :as s]))
|
||||||
|
|
||||||
; TODO: loading from cpasspath results in nil even if file exists
|
; TODO: loading from cpasspath results in nil even if file exists
|
||||||
|
(defn file-from-cp
|
||||||
|
[resource-path]
|
||||||
|
(let [file-from-cp (io/file (io/resource resource-path))]
|
||||||
|
(try
|
||||||
|
(when (.exists file-from-cp)
|
||||||
|
file-from-cp)
|
||||||
|
(catch Exception e
|
||||||
|
nil))))
|
||||||
|
|
||||||
|
(defn file-from-fs
|
||||||
|
[fs-prefix resource-path]
|
||||||
|
(let [file-from-fs (io/file (str fs-prefix resource-path))]
|
||||||
|
(try
|
||||||
|
(when (.exists file-from-fs)
|
||||||
|
file-from-fs)
|
||||||
|
(catch Exception e
|
||||||
|
nil))))
|
||||||
|
|
||||||
(defn file-from-cp-or-filesystem
|
(defn file-from-cp-or-filesystem
|
||||||
[fs-prefix resource-path]
|
[fs-prefix resource-path]
|
||||||
(let [file-from-cp (io/file (io/resource resource-path))
|
(let [from-fs (file-from-fs fs-prefix resource-path)]
|
||||||
file-from-fs (io/file (str fs-prefix resource-path))]
|
(if (some? from-fs)
|
||||||
(println file-from-cp)
|
from-fs
|
||||||
(println file-from-fs)
|
(file-from-cp resource-path))))
|
||||||
(try
|
|
||||||
(when (.exists file-from-fs)
|
|
||||||
file-from-fs)
|
|
||||||
(catch Exception e
|
|
||||||
(try (when (.exists file-from-cp)
|
|
||||||
file-from-cp)
|
|
||||||
(catch Exception e
|
|
||||||
(throw (IllegalArgumentException.
|
|
||||||
(str "resource " resource-path " neither found on classpath nor filesystem")))
|
|
||||||
))))))
|
|
||||||
|
|
||||||
(defn copy-dir
|
(defn copy-dir
|
||||||
[source-path target-path ignored-files]
|
[source-path target-path ignored-files]
|
||||||
|
|
|
@ -15,10 +15,11 @@
|
||||||
(and (verify-file-exists path)
|
(and (verify-file-exists path)
|
||||||
(.isDirectory (io/file path))))
|
(.isDirectory (io/file path))))
|
||||||
|
|
||||||
|
(deftest test-file-from-cp
|
||||||
|
(is
|
||||||
|
(sut/file-from-cp ".gitkeep")))
|
||||||
|
|
||||||
(deftest test-file-from-cp-or-filesystem
|
(deftest test-file-from-cp-or-filesystem
|
||||||
(is (thrown? IllegalArgumentException
|
|
||||||
(sut/file-from-cp-or-filesystem
|
|
||||||
"./" "Not_Existing")))
|
|
||||||
(is
|
(is
|
||||||
(.exists (sut/file-from-cp-or-filesystem
|
(.exists (sut/file-from-cp-or-filesystem
|
||||||
"./test-resources/" "templates/themes/bootstrap4-test/js")))
|
"./test-resources/" "templates/themes/bootstrap4-test/js")))
|
||||||
|
|
Loading…
Reference in a new issue