Skip to content

Commit

Permalink
Add --include, --exclude, and --debounce watch task options
Browse files Browse the repository at this point in the history
- fixes #312
  • Loading branch information
micha committed Aug 28, 2016
1 parent 3913fea commit 076870c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
pom.properties TmpFiles in the fileset. This metadata is used by eg. the
`jar` task to select the "real" pom from multiple poms that might be in the
fileset from the `uber` task, etc. [#451][451]
- The `watch` task now accepts `--include` and `--exclude` options to restrict
the set of paths that will trigger a rebuild [#312][312].
- The `watch` task now accpets `--debounce` option to adjust how long it will
wait for all filesystem events to have fired before a rebuild is triggered.

##### API Functions

Expand Down Expand Up @@ -88,6 +92,7 @@
- The `speak` task, replaced by `notify`.

[230]: https://github.com/boot-clj/boot/issues/230
[312]: https://github.com/boot-clj/boot/issues/312
[374]: https://github.com/boot-clj/boot/issues/374
[451]: https://github.com/boot-clj/boot/issues/451
[465]: https://github.com/boot-clj/boot/issues/465
Expand Down
21 changes: 12 additions & 9 deletions boot/core/src/boot/task/built_in.clj
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,15 @@
(sync! fs :link (not no-link)))))

(core/deftask watch
"Call the next handler when source files change.
"Call the next handler when source files change."

Debouncing time is 10ms by default."
[q quiet bool "Suppress all output from running jobs."
v verbose bool "Print which files have changed."
M manual bool "Use a manual trigger instead of a file watcher."
d debounce MS int "Debounce time (how long to wait for filesystem events) in milliseconds."
i include REGEX #{regex} "The set of regexes the paths of changed files must match for watch to fire."
e exclude REGEX #{regex} "The set of regexes the paths of changed files must not match for watch to fire."]

[q quiet bool "Suppress all output from running jobs."
v verbose bool "Print which files have changed."
M manual bool "Use a manual trigger instead of a file watcher."]

(pod/require-in pod/worker-pod "boot.watcher")
(fn [next-task]
(fn [fileset]
(let [q (LinkedBlockingQueue.)
Expand All @@ -391,7 +391,10 @@
(into (core/user-dirs fileset))
(map (memfn getPath)))
watcher (apply file/watcher! :time srcdirs)
debounce (core/get-env :watcher-debounce)
incl-excl (if-not (or (seq include) (seq exclude))
identity
(let [f (partial file/keep-filters? include exclude)]
(partial filter (comp f io/file second))))
watch-target (if manual core/new-build-at core/last-file-change)]
(.offer q (System/currentTimeMillis))
(add-watch watch-target k #(.offer q %4))
Expand All @@ -403,7 +406,7 @@
(recur (conj ret more))
(let [start (System/currentTimeMillis)
etime #(- (System/currentTimeMillis) start)
changed (watcher)
changed (when-not manual (incl-excl (watcher)))
should-fire? (or manual (not (empty? changed)))]
(when should-fire?
(when verbose
Expand Down
3 changes: 2 additions & 1 deletion boot/pod/src/boot/file.clj
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@

(defn match-filter?
[filters f]
(letfn [(normalize [path] (str/replace path #"\\" "/"))]
(let [windows? (boot.App/isWindows)
normalize #(if-not windows? % (str/replace % #"\\" "/"))]
((apply some-fn (map (partial partial re-find) filters)) (normalize (.getPath ^File f)))))

(defn keep-filters?
Expand Down

0 comments on commit 076870c

Please sign in to comment.