aboutsummaryrefslogtreecommitdiff
path: root/lux-lein/src/leiningen/lux
diff options
context:
space:
mode:
Diffstat (limited to 'lux-lein/src/leiningen/lux')
-rw-r--r--lux-lein/src/leiningen/lux/utils.clj11
-rw-r--r--lux-lein/src/leiningen/lux/watch.clj41
2 files changed, 45 insertions, 7 deletions
diff --git a/lux-lein/src/leiningen/lux/utils.clj b/lux-lein/src/leiningen/lux/utils.clj
index 70d203865..6419e9de8 100644
--- a/lux-lein/src/leiningen/lux/utils.clj
+++ b/lux-lein/src/leiningen/lux/utils.clj
@@ -86,11 +86,8 @@
(when line
(println line)
(recur (.readLine std-out))))
- (loop [had-error? false
- line (.readLine std-err)]
- (if line
- (do (println line)
- (recur true (.readLine std-err)))
- (when had-error?
- (System/exit 1))))
+ (loop [line (.readLine std-err)]
+ (when line
+ (println line)
+ (recur (.readLine std-err))))
(println post))))
diff --git a/lux-lein/src/leiningen/lux/watch.clj b/lux-lein/src/leiningen/lux/watch.clj
new file mode 100644
index 000000000..d9cae9075
--- /dev/null
+++ b/lux-lein/src/leiningen/lux/watch.clj
@@ -0,0 +1,41 @@
+;; Copyright (c) Eduardo Julian. All rights reserved.
+;; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+;; If a copy of the MPL was not distributed with this file,
+;; You can obtain one at http://mozilla.org/MPL/2.0/.
+
+(ns leiningen.lux.watch
+ (:require [leiningen.core.classpath :as classpath])
+ (:import (java.io File)
+ (java.nio.file FileSystems
+ Path
+ WatchEvent$Kind
+ StandardWatchEventKinds
+ WatchService
+ WatchKey)))
+
+(defn ^:private file-tree [path]
+ (let [dir (new File path)]
+ (if (and (.exists dir)
+ (.isDirectory dir))
+ (->> (.listFiles dir) (mapcat (comp file-tree #(.getAbsolutePath ^File %))) (cons path))
+ (list))))
+
+(defn watch [action project]
+ (let [fs (FileSystems/getDefault)
+ ^WatchService watcher (.newWatchService fs)
+ dirs-to-watch (->> (concat (get project :test-paths (list))
+ (get project :source-paths (list)))
+ (mapcat file-tree)
+ (map #(.getPath fs % (into-array String []))))
+ _ (doseq [^Path dir dirs-to-watch]
+ (.register dir watcher (into-array WatchEvent$Kind [StandardWatchEventKinds/ENTRY_MODIFY])))]
+ (do (action)
+ (loop []
+ (do (when-let [^WatchKey key (.poll watcher)]
+ (when (.isValid key)
+ (.pollEvents key)
+ (.reset key)
+ (action)))
+ (Thread/sleep 1000)
+ (recur))))
+ ))