diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b5dfcb2..f2a55f26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ## Fixed +- Fix beholder watch functionality that would cause a NullPointerException earlier. + ## Changed # 1.91.1392 (2024-05-23 / c2d7e1f) diff --git a/doc/07_watch_mode.md b/doc/07_watch_mode.md index e715cc83..b27de744 100644 --- a/doc/07_watch_mode.md +++ b/doc/07_watch_mode.md @@ -34,7 +34,9 @@ interface, the provided links describes how they work in detail. ``` clojure #kaocha/v1 -{:kaocha.watch/ignore ["*.tmp"]} +{:kaocha.watch/ignore ["**.tmp"]} +; this will match all files ending in .tmp in the current directory and +; any subdirectory ``` When running in watch mode you can press the Enter (Return) key to manually diff --git a/src/kaocha/watch.clj b/src/kaocha/watch.clj index 2da8ba71..35a9f44d 100644 --- a/src/kaocha/watch.clj +++ b/src/kaocha/watch.clj @@ -22,7 +22,8 @@ [lambdaisland.tools.namespace.track :as ctn-track] [slingshot.slingshot :refer [try+]] [nextjournal.beholder :as beholder]) - (:import (java.nio.file FileSystems) + (:import (java.io File) + (java.nio.file FileSystems Path PathMatcher) (java.util.concurrent ArrayBlockingQueue BlockingQueue))) (defn make-queue [] @@ -93,9 +94,10 @@ for a description of the patterns, these are similar but not the same as typical shell glob patterns." [path patterns] + (assert (instance? Path path)) (let [fs (FileSystems/getDefault) patterns (map #(.getPathMatcher fs (str "glob:" %)) patterns)] - (some #(.matches % path) patterns))) + (some #(.matches ^PathMatcher % path) patterns))) (defn convert "Converts a Git-style ignore pattern into the equivalent pattern that Java PathMatcher uses." @@ -153,7 +155,7 @@ "Finds ignore files in the local directory and the system." [dir] (let [absolute-files [(io/file (str (System/getProperty "user.home") "/.config/git/ignore"))] - relative-files (filter #(glob? (.toPath %) ["**.gitignore" "**.ignore"]) (file-seq (io/file dir)))] + relative-files (filter #(glob? (.toPath ^File %) ["**.gitignore" "**.ignore"]) (file-seq (io/file dir)))] (into absolute-files relative-files))) (defn merge-ignore-files @@ -169,7 +171,7 @@ (defn wait-and-rescan! [q tracker watch-paths ignore] (let [f (qtake q)] (cond - (and (file? f) (glob? (.toPath f) ignore)) + (and (file? f) (glob? (.toPath ^File f) ignore)) (recur q tracker watch-paths ignore) (directory? f) @@ -281,7 +283,7 @@ errors as test errors." (map io/file)) (:kaocha/tests config)) ;; Without this, if any path doesn't exist the watching doesn't work. - (filter (fn [x] (.exists ^java.io.File x))))) + (filter (fn [x] (.exists ^File x))))) (defmulti watch! :type) @@ -295,8 +297,9 @@ errors as test errors." (defmethod watch! :beholder [{:keys [q watch-paths]}] (apply beholder/watch (fn [{:keys [type path]}] + (assert (instance? Path path)) (when (contains? #{:modify :create} type) - (qput q path))) + (qput q (.toFile ^Path path)))) (map str watch-paths))) (defn run* [config finish? q] @@ -307,7 +310,7 @@ errors as test errors." {}) watch-paths (if (:kaocha.watch/use-ignore-file config) (set/union (watch-paths config) - (set (map #(.getParentFile (.getCanonicalFile %)) (find-ignore-files ".")))) + (set (map #(.getParentFile (.getCanonicalFile ^File %)) (find-ignore-files ".")))) (watch-paths config)) tracker (ctn-track/tracker) ;; if t.n fails due to circular dependencies, do not track-reload.