improve copy-resources!
This commit is contained in:
parent
5d0fec3969
commit
c0c9115b5f
3 changed files with 25 additions and 17 deletions
|
@ -12,8 +12,7 @@
|
||||||
[cryogen-core.classpath-able-io.cp :as cp]
|
[cryogen-core.classpath-able-io.cp :as cp]
|
||||||
[cryogen-core.classpath-able-io.this :as this]
|
[cryogen-core.classpath-able-io.this :as this]
|
||||||
[schema.core :as s])
|
[schema.core :as s])
|
||||||
(:import [java.nio.file Files StandardCopyOption]
|
(:import [java.nio.file Files]))
|
||||||
[java.nio.file.attribute FileAttribute]))
|
|
||||||
|
|
||||||
(def SourceType this/SourceType)
|
(def SourceType this/SourceType)
|
||||||
(def ResourceType this/ResourceType)
|
(def ResourceType this/ResourceType)
|
||||||
|
@ -125,21 +124,20 @@
|
||||||
target-path ;:- VirtualPath
|
target-path ;:- VirtualPath
|
||||||
ignore-patterns ;:- s/Str
|
ignore-patterns ;:- s/Str
|
||||||
]
|
]
|
||||||
(let [resource-paths
|
(let [resources
|
||||||
(sort (get-resource-paths-recursive fs-prefix base-path source-paths))]
|
(sort
|
||||||
(if (empty? resource-paths)
|
this/compare-resource
|
||||||
(throw (IllegalArgumentException. (str "resource " resource-paths ", "
|
(get-resources-recursive fs-prefix base-path source-paths))]
|
||||||
|
(if (empty? resources)
|
||||||
|
(throw (IllegalArgumentException. (str "resource " base-path ", "
|
||||||
source-paths " not found")))
|
source-paths " not found")))
|
||||||
(doseq [resource-path resource-paths]
|
(doseq [resource resources]
|
||||||
(let [target-file (fs/absolut-path target-path resource-path)
|
(let [target-path (fs/absolut-path target-path (:virtual-path resource))
|
||||||
source-file (path-from-cp-or-fs
|
source-path (:java-path resource)]
|
||||||
fs-prefix
|
(when (this/is-dir? resource)
|
||||||
base-path
|
(Files/createDirectories target-path fs/no-attributes))
|
||||||
resource-path)]
|
(when (this/is-file? resource)
|
||||||
(when (Files/isDirectory source-file fs/no-link-option)
|
(Files/copy source-path target-path fs/overwrite-preserve-attributes)
|
||||||
(Files/createDirectories target-file (into-array FileAttribute [])))
|
|
||||||
(when (Files/isRegularFile source-file fs/no-link-option)
|
|
||||||
(Files/copy source-file target-file (into-array StandardCopyOption [StandardCopyOption/COPY_ATTRIBUTES StandardCopyOption/REPLACE_EXISTING]))
|
|
||||||
))))))
|
))))))
|
||||||
|
|
||||||
(defn distinct-resources-by-path
|
(defn distinct-resources-by-path
|
||||||
|
|
|
@ -8,11 +8,16 @@
|
||||||
|
|
||||||
(ns cryogen-core.classpath-able-io.fs
|
(ns cryogen-core.classpath-able-io.fs
|
||||||
(:require [cryogen-core.classpath-able-io.this :as this])
|
(:require [cryogen-core.classpath-able-io.this :as this])
|
||||||
(:import [java.nio.file Paths Files LinkOption]))
|
(:import [java.nio.file Paths Files LinkOption StandardCopyOption]
|
||||||
|
[java.nio.file.attribute FileAttribute]))
|
||||||
|
|
||||||
; ----------------------- Domain functions ------------------------
|
; ----------------------- Domain functions ------------------------
|
||||||
(def no-link-option (into-array [LinkOption/NOFOLLOW_LINKS]))
|
(def no-link-option (into-array [LinkOption/NOFOLLOW_LINKS]))
|
||||||
(def follow-link-option (into-array LinkOption []))
|
(def follow-link-option (into-array LinkOption []))
|
||||||
|
(def no-attributes (into-array FileAttribute []))
|
||||||
|
(def overwrite-preserve-attributes
|
||||||
|
(into-array StandardCopyOption
|
||||||
|
[StandardCopyOption/COPY_ATTRIBUTES StandardCopyOption/REPLACE_EXISTING]))
|
||||||
|
|
||||||
(defn user-dir []
|
(defn user-dir []
|
||||||
(java.lang.System/getProperty "user.dir"))
|
(java.lang.System/getProperty "user.dir"))
|
||||||
|
|
|
@ -37,3 +37,8 @@
|
||||||
(st/join "/"
|
(st/join "/"
|
||||||
(filter #(not (empty? %))
|
(filter #(not (empty? %))
|
||||||
path-elements)))
|
path-elements)))
|
||||||
|
|
||||||
|
(s/defn compare-resource
|
||||||
|
[first :- Resource
|
||||||
|
second :- Resource]
|
||||||
|
(compare (:virtual-path first) (:virtual-path second)))
|
||||||
|
|
Loading…
Reference in a new issue