"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-or-filesystem
|
(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]
|
[fs-prefix resource-path]
|
||||||
(let [file-from-cp (io/file (io/resource resource-path))
|
(let [file-from-fs (io/file (str fs-prefix resource-path))]
|
||||||
file-from-fs (io/file (str fs-prefix resource-path))]
|
|
||||||
(println file-from-cp)
|
|
||||||
(println file-from-fs)
|
|
||||||
(try
|
(try
|
||||||
(when (.exists file-from-fs)
|
(when (.exists file-from-fs)
|
||||||
file-from-fs)
|
file-from-fs)
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(try (when (.exists file-from-cp)
|
nil))))
|
||||||
file-from-cp)
|
|
||||||
(catch Exception e
|
(defn file-from-cp-or-filesystem
|
||||||
(throw (IllegalArgumentException.
|
[fs-prefix resource-path]
|
||||||
(str "resource " resource-path " neither found on classpath nor filesystem")))
|
(let [from-fs (file-from-fs fs-prefix resource-path)]
|
||||||
))))))
|
(if (some? from-fs)
|
||||||
|
from-fs
|
||||||
|
(file-from-cp resource-path))))
|
||||||
|
|
||||||
|
|
||||||
(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