now using resource type internaly
This commit is contained in:
parent
23ca87a8cd
commit
42de012fb4
2 changed files with 92 additions and 41 deletions
|
@ -67,6 +67,10 @@
|
||||||
(.isFile file) :file
|
(.isFile file) :file
|
||||||
:else :unknown)}))
|
:else :unknown)}))
|
||||||
|
|
||||||
|
(s/defn is-file? :- s/Bool
|
||||||
|
[resource :- Resource]
|
||||||
|
(= :file (:resource-type resource)))
|
||||||
|
|
||||||
(s/defn file-from-cp ; :- File
|
(s/defn file-from-cp ; :- File
|
||||||
[resource-path :- Path]
|
[resource-path :- Path]
|
||||||
(let [file-from-cp (io/file (io/resource resource-path))]
|
(let [file-from-cp (io/file (io/resource resource-path))]
|
||||||
|
@ -86,17 +90,21 @@
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
nil))))
|
nil))))
|
||||||
|
|
||||||
(defn resource-from-cp-or-filesystem ; :- Resource
|
(defn resource-from-cp-or-fs ; :- Resource
|
||||||
[fs-prefix ; :- Prefix
|
[fs-prefix ; :- Prefix
|
||||||
|
base-path ; :- Path
|
||||||
resource-path ; :- Path
|
resource-path ; :- Path
|
||||||
& {:keys [from-cp from-fs]
|
& {:keys [from-cp from-fs]
|
||||||
:or {from-cp true
|
:or {from-cp true
|
||||||
from-fs true}}]
|
from-fs true}}]
|
||||||
(let [file-from-fs (if from-fs
|
(let [full-path (if (empty? base-path)
|
||||||
(file-from-fs fs-prefix resource-path)
|
resource-path
|
||||||
|
(str base-path "/" resource-path))
|
||||||
|
file-from-fs (if from-fs
|
||||||
|
(file-from-fs fs-prefix full-path)
|
||||||
nil)
|
nil)
|
||||||
file-from-cp (if from-cp
|
file-from-cp (if from-cp
|
||||||
(file-from-cp resource-path)
|
(file-from-cp full-path)
|
||||||
nil)]
|
nil)]
|
||||||
(cond
|
(cond
|
||||||
(some? file-from-fs)
|
(some? file-from-fs)
|
||||||
|
@ -105,20 +113,19 @@
|
||||||
(create-resource resource-path file-from-cp :classpath)
|
(create-resource resource-path file-from-cp :classpath)
|
||||||
:else nil)))
|
:else nil)))
|
||||||
|
|
||||||
(defn uri-from-cp-or-filesystem
|
(defn file-from-cp-or-fs ; :- File
|
||||||
[fs-prefix resource-path
|
[fs-prefix ; :- Prefix
|
||||||
|
base-path ; :- Path
|
||||||
|
resource-path; :- Path
|
||||||
& {:keys [from-cp from-fs]
|
& {:keys [from-cp from-fs]
|
||||||
:or {from-cp true
|
:or {from-cp true
|
||||||
from-fs true}}]
|
from-fs true}}]
|
||||||
(let [from-fs-file (if from-fs
|
(let [resource (resource-from-cp-or-fs
|
||||||
(file-from-fs fs-prefix resource-path)
|
fs-prefix base-path resource-path
|
||||||
nil)
|
:from-cp from-cp
|
||||||
from-cp-file (if from-cp
|
:from-fs from-fs)]
|
||||||
(file-from-cp resource-path)
|
(when (some? resource)
|
||||||
nil)]
|
(:file resource))))
|
||||||
(if (some? from-fs-file)
|
|
||||||
from-fs-file
|
|
||||||
from-cp-file)))
|
|
||||||
|
|
||||||
(defn get-resources-recursive ;:- [Resource]
|
(defn get-resources-recursive ;:- [Resource]
|
||||||
[fs-prefix ;:- Prefix
|
[fs-prefix ;:- Prefix
|
||||||
|
@ -132,15 +139,18 @@
|
||||||
(if (not (empty? paths))
|
(if (not (empty? paths))
|
||||||
(do
|
(do
|
||||||
(let [path-to-work-with (first paths)
|
(let [path-to-work-with (first paths)
|
||||||
resource-to-work-with (resource-from-cp-or-filesystem
|
resource-to-work-with (resource-from-cp-or-fs
|
||||||
fs-prefix
|
fs-prefix
|
||||||
(str base-path "/" path-to-work-with)
|
base-path
|
||||||
|
path-to-work-with
|
||||||
:from-cp from-cp
|
:from-cp from-cp
|
||||||
:from-fs from-fs)
|
:from-fs from-fs)
|
||||||
result (into result [path-to-work-with])]
|
result (into result
|
||||||
|
[resource-to-work-with])]
|
||||||
(cond
|
(cond
|
||||||
(nil? resource-to-work-with) []
|
(nil? resource-to-work-with) []
|
||||||
(= :file (:resource-type resource-to-work-with)) (recur (drop 1 paths) result)
|
(is-file? resource-to-work-with)
|
||||||
|
(recur (drop 1 paths) result)
|
||||||
:else
|
:else
|
||||||
(recur (into (drop 1 paths)
|
(recur (into (drop 1 paths)
|
||||||
(map #(str path-to-work-with "/" %)
|
(map #(str path-to-work-with "/" %)
|
||||||
|
@ -160,9 +170,10 @@
|
||||||
(if (not (empty? paths))
|
(if (not (empty? paths))
|
||||||
(do
|
(do
|
||||||
(let [path-to-work-with (first paths)
|
(let [path-to-work-with (first paths)
|
||||||
resource-to-work-with (resource-from-cp-or-filesystem
|
resource-to-work-with (resource-from-cp-or-fs
|
||||||
fs-prefix
|
fs-prefix
|
||||||
(str base-path "/" path-to-work-with)
|
base-path
|
||||||
|
path-to-work-with
|
||||||
:from-cp from-cp
|
:from-cp from-cp
|
||||||
:from-fs from-fs)
|
:from-fs from-fs)
|
||||||
result (into result [path-to-work-with])]
|
result (into result [path-to-work-with])]
|
||||||
|
@ -201,9 +212,10 @@
|
||||||
source-paths " not found")))
|
source-paths " not found")))
|
||||||
(doseq [resource-path resource-paths]
|
(doseq [resource-path resource-paths]
|
||||||
(let [target-file (io/file target-path resource-path)
|
(let [target-file (io/file target-path resource-path)
|
||||||
source-file (io/file (uri-from-cp-or-filesystem
|
source-file (io/file (file-from-cp-or-fs
|
||||||
fs-prefix
|
fs-prefix
|
||||||
(str base-path "/" resource-path)))]
|
base-path
|
||||||
|
resource-path))]
|
||||||
(io/make-parents target-file)
|
(io/make-parents target-file)
|
||||||
(when (.isFile source-file)
|
(when (.isFile source-file)
|
||||||
(io/copy source-file target-file)))))))
|
(io/copy source-file target-file)))))))
|
||||||
|
|
|
@ -25,14 +25,65 @@
|
||||||
(and (verify-file-exists path)
|
(and (verify-file-exists path)
|
||||||
(.isDirectory (io/file path))))
|
(.isDirectory (io/file path))))
|
||||||
|
|
||||||
(deftest test-uri-from-cp-or-filesystem
|
(defn filter-object
|
||||||
|
[e]
|
||||||
|
{:path (:path e)
|
||||||
|
:source-type (:source-type e)
|
||||||
|
:resource-type (:resource-type e)})
|
||||||
|
|
||||||
|
(deftest test-uri-from-cp
|
||||||
(is
|
(is
|
||||||
(some? (sut/uri-from-cp-or-filesystem
|
(sut/file-from-cp ".gitkeep")))
|
||||||
|
|
||||||
|
(deftest test-resource-from-cp-or-fs
|
||||||
|
(is
|
||||||
|
(.exists
|
||||||
|
(:file
|
||||||
|
(sut/resource-from-cp-or-fs
|
||||||
"./test-resources/"
|
"./test-resources/"
|
||||||
"templates/themes/bootstrap4-test/js")))
|
"templates/themes/bootstrap4-test"
|
||||||
|
"js"))))
|
||||||
(is
|
(is
|
||||||
(some? (sut/uri-from-cp-or-filesystem
|
(.exists
|
||||||
"./not-existing-so-load-from-cp" ".gitkeep"))))
|
(:file
|
||||||
|
(sut/resource-from-cp-or-fs
|
||||||
|
"./" "" ".gitkeep"))))
|
||||||
|
(is
|
||||||
|
(some? (sut/resource-from-cp-or-fs
|
||||||
|
"./test-resources/"
|
||||||
|
"templates/themes/bootstrap4-test"
|
||||||
|
"js")))
|
||||||
|
(is
|
||||||
|
(some? (sut/resource-from-cp-or-fs
|
||||||
|
"./not-existing-so-load-from-cp" "" ".gitkeep")))
|
||||||
|
(is (=
|
||||||
|
{:path "js/subdir"
|
||||||
|
:source-type :classpath
|
||||||
|
:resource-type :dir}
|
||||||
|
(filter-object
|
||||||
|
(sut/resource-from-cp-or-fs
|
||||||
|
"./not-existing-so-load-from-cp"
|
||||||
|
"templates/themes/bootstrap4-test"
|
||||||
|
"js/subdir")))))
|
||||||
|
|
||||||
|
(deftest test-get-resources-recursive
|
||||||
|
(is (=
|
||||||
|
[]
|
||||||
|
(sut/get-resources-recursive "" "templates/themes/bootstrap4-test" ["not-existing"])))
|
||||||
|
(is (=
|
||||||
|
[{:path "js/dummy.js"
|
||||||
|
:source-type :classpath
|
||||||
|
:resource-type :file}]
|
||||||
|
(map filter-object
|
||||||
|
(sut/get-resources-recursive
|
||||||
|
"" "templates/themes/bootstrap4-test" ["js/dummy.js"]))))
|
||||||
|
(is (=
|
||||||
|
["js/subdir"
|
||||||
|
"js/subdir/test.js"
|
||||||
|
"js/subdir/subdummy.js"]
|
||||||
|
(map #(:path %)
|
||||||
|
(sut/get-resources-recursive
|
||||||
|
"" "templates/themes/bootstrap4-test" ["js/subdir"])))))
|
||||||
|
|
||||||
(deftest test-get-resource-paths-recursive
|
(deftest test-get-resource-paths-recursive
|
||||||
(is (=
|
(is (=
|
||||||
|
@ -80,18 +131,6 @@
|
||||||
["file.js"]
|
["file.js"]
|
||||||
(sut/filter-for-ignore-patterns #".*\.ignore" ["file.js" "file.ignore"]))))
|
(sut/filter-for-ignore-patterns #".*\.ignore" ["file.js" "file.ignore"]))))
|
||||||
|
|
||||||
(deftest test-uri-from-cp
|
|
||||||
(is
|
|
||||||
(sut/file-from-cp ".gitkeep")))
|
|
||||||
|
|
||||||
(deftest test-uri-from-cp-or-filesystem
|
|
||||||
(is
|
|
||||||
(.exists (sut/uri-from-cp-or-filesystem
|
|
||||||
"./test-resources/" "templates/themes/bootstrap4-test/js")))
|
|
||||||
(is
|
|
||||||
(.exists (sut/uri-from-cp-or-filesystem
|
|
||||||
"./" ".gitkeep"))))
|
|
||||||
|
|
||||||
(deftest test-copy-resources-from-theme! (is (do
|
(deftest test-copy-resources-from-theme! (is (do
|
||||||
(sut/delete-resource-recursive! (str "target/tmp" target))
|
(sut/delete-resource-recursive! (str "target/tmp" target))
|
||||||
(sut/copy-resources-from-theme! "./" theme target "")
|
(sut/copy-resources-from-theme! "./" theme target "")
|
||||||
|
|
Loading…
Reference in a new issue