Skip to content

Commit 8b33f35

Browse files
committed
add -i and -x options to all fileset tasks
1 parent 7abb66d commit 8b33f35

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

boot/core/src/boot/task/built_in.clj

+24-23
Original file line numberDiff line numberDiff line change
@@ -220,35 +220,37 @@
220220
(core/deftask add-dir
221221
"Add files in resource directories to fileset.
222222
223-
The filters option specifies a set of regular expressions (as strings) that
224-
will be used to filter the resource files. If no filters are specified, or if
225-
any of the filter regexes match the path of the resource file relative to the
226-
resource dir, then the file is added to the fileset."
223+
The include and exclude options specify sets of regular expressions (strings)
224+
that will be used to filter the source files. If no filters are specified then
225+
all files are added to the fileset."
227226

228227
[d dirs PATH #{str} "The set of resource directories."
229-
f filters REGEX #{str} "The set of regular expressions to match against."]
228+
i include REGEX #{str} "The set of regexes that paths must match."
229+
x exclude REGEX #{str} "The set of regexes that paths must not match."]
230230

231231
(let [tgt (core/mktgtdir! ::add-dir-tgt)]
232232
(core/with-pre-wrap
233233
(util/info "Adding resource directories...\n")
234-
(binding [file/*filters* (mapv re-pattern filters)]
234+
(binding [file/*include* (mapv re-pattern include)
235+
file/*exclude* (mapv re-pattern exclude)]
235236
(apply file/sync :time tgt dirs)))))
236237

237238
(core/deftask add-src
238239
"Add source files to fileset.
239240
240-
The filters option specifies a set of regular expressions (as strings) that
241-
will be used to filter the source files. If no filters are specified, or if
242-
any of the filter regexes match the path of the source file relative to its
243-
source dir, then the file is added to the fileset."
241+
The include and exclude options specify sets of regular expressions (strings)
242+
that will be used to filter the source files. If no filters are specified then
243+
all files are added to the fileset."
244244

245-
[f filters REGEX #{str} "The set of regular expressions to match against."]
245+
[i include REGEX #{str} "The set of regexes that paths must match."
246+
x exclude REGEX #{str} "The set of regexes that paths must not match."]
246247

247248
(let [tgt (core/mktgtdir! ::add-srcs-tgt)]
248249
(core/with-pre-wrap
249250
(when-let [dirs (seq (remove core/tmpfile? (core/get-env :src-paths)))]
250251
(util/info "Adding src files...\n")
251-
(binding [file/*filters* (mapv re-pattern filters)]
252+
(binding [file/*include* (mapv re-pattern include)
253+
file/*exclude* (mapv re-pattern exclude)]
252254
(apply file/sync :time tgt dirs))))))
253255

254256
(core/deftask uber
@@ -258,28 +260,27 @@
258260
to the fileset: compile, runtime, and provided. The exclude option may be used
259261
to exclude dependencies with the given scope(s).
260262
261-
The filters option specifies a set of regular expressions (as strings) that
262-
will be used to filter the jar entries. If no filters are specified, or if
263-
any of the filter regexes match the path of the jar entry, then the entry is
264-
added to the fileset."
263+
The include and exclude options specify sets of regular expressions (strings)
264+
that will be used to filter the entries. If no filters are specified then all
265+
entries are added to the fileset."
265266

266-
[x exclude-scope SCOPE #{str} "The set of excluded scopes."
267-
f filters REGEX #{str} "The set of regular expressions to match against."]
267+
[S exclude-scope SCOPE #{str} "The set of excluded scopes."
268+
i include REGEX #{str} "The set of regexes that paths must match."
269+
x exclude REGEX #{str} "The set of regexes that paths must not match."]
268270

269271
(let [tgt (core/mktgtdir! ::uber-tgt)
270272
dfl-scopes #{"compile" "runtime" "provided"}
271273
scopes (set/difference dfl-scopes exclude-scope)
272-
filters (map re-pattern filters)
273-
keep? (when (seq filters)
274-
(apply some-fn (map (partial partial re-find) filters)))]
274+
include (map re-pattern include)
275+
exclude (map re-pattern exclude)]
275276
(core/with-pre-wrap
276277
(let [scope? #(contains? scopes (:scope (util/dep-as-map %)))
277278
urls (-> (core/get-env)
278279
(update-in [:dependencies] (partial filter scope?))
279280
pod/jar-entries-in-dep-order)]
280281
(util/info "Adding uberjar entries...\n")
281-
(doseq [[relpath url-str] urls]
282-
(when (or (empty? filters) (keep? relpath))
282+
(doseq [[relpath url-str] urls :let [f (io/file relpath)]]
283+
(when (file/keep-filters? include exclude f)
283284
(let [segs (file/split-path relpath)
284285
outfile (apply io/file tgt segs)]
285286
(when-not (or (.exists outfile) (= "META-INF" (first segs)))

boot/pod/src/boot/file.clj

+11-5
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
(defn select-keys-by [m pred?]
8484
(select-keys m (filter pred? (keys m))))
8585

86-
(def ^:dynamic *filters* nil)
86+
(def ^:dynamic *include* nil)
87+
(def ^:dynamic *exclude* nil)
8788

8889
(defn dir-set
8990
([dir]
@@ -126,15 +127,20 @@
126127
rm (map #(vector :rm (file dst %)) to-rm)]
127128
(concat cp rm)))
128129

130+
(defn match-filter?
131+
[filters f]
132+
((apply some-fn (map (partial partial re-find) filters)) (.getPath f)))
133+
129134
(defn keep-filters?
130-
[f]
131-
(or (empty? *filters*)
132-
((apply some-fn (map (partial partial re-find) *filters*)) (.getPath f))))
135+
[include exclude f]
136+
(and
137+
(or (empty? include) (match-filter? include f))
138+
(or (empty? exclude) (not (match-filter? exclude f)))))
133139

134140
(defn sync*
135141
[ops]
136142
(let [opfn {:rm #(.delete (nth % 1))
137-
:cp #(when (keep-filters? (nth % 2))
143+
:cp #(when (keep-filters? *include* *exclude* (nth % 2))
138144
(copy-with-lastmod (nth % 1) (nth % 2)))}]
139145
(doseq [[op s d :as cmd] ops] ((opfn op) cmd))))
140146

0 commit comments

Comments
 (0)