Permalink
Browse files

Honor :class-file-whitelist to make classes/ deletion more manageable.

  • Loading branch information...
1 parent 1943be7 commit 33846eddfb0661eb135cd427dc78039b48fc3a4e @technomancy committed Feb 28, 2011
Showing with 21 additions and 4 deletions.
  1. +3 −0 sample.project.clj
  2. +18 −4 src/leiningen/compile.clj
View
@@ -54,6 +54,9 @@
;; true to delete all non-project classes or set to a seq of regexes
;; to only delete class files that match one of the regexes.
:clean-non-project-classes true
+ ;; If :clean-non-project-classes is set to true, you can set this to
+ ;; be a regex; all class filenames that match this regex will be preserved.
+ :class-file-whitelist #"^(org/example|clojure)"
;; Additional files (besides :compile-path contents and jars/uberjars)
;; to be deleted during clean phase. May contain %s, which will be replaced
;; with the project's current version number.
View
@@ -220,22 +220,36 @@
(:compile-path project)
(:source-path project)) ".clj")))))
+(defn- relative-path [project f]
+ (let [root-length (if (= \/ (last (:compile-path project)))
+ (count (:compile-path project))
+ (inc (count (:compile-path project))))]
+ (subs (.getAbsolutePath f) root-length)))
+
(defn- blacklisted-class? [project f]
;; true indicates all non-project classes are blacklisted
(or (true? (:clean-non-project-classes project))
- (let [relative (subs (.getAbsolutePath f) (count (:root project)))]
- (some #(re-find % relative) (:clean-non-project-classes project)))))
+ (some #(re-find % (relative-path project f))
+ (:clean-non-project-classes project))))
+
+(defn- whitelisted-class? [project f]
+ (or (class-in-project? project f)
+ (and (:class-file-whitelist project)
+ (re-find (:class-file-whitelist project)
+ (relative-path project f)))))
(defn clean-non-project-classes [project]
(when (:clean-non-project-classes project)
(doseq [f (file-seq (file (:compile-path project)))
- :when (and (.isFile f) (not (class-in-project? project f))
+ :when (and (.isFile f)
+ (not (whitelisted-class? project f))
(blacklisted-class? project f))]
(.delete f))))
(defn- status [code msg]
(when-not *silently*
- (.write (if (zero? code) *out* *err*) (str msg "\n")))
+ (binding [*out* (if (zero? code) *out* *err*)]
+ (println msg)))
code)
(def ^{:private true} success (partial status 0))

0 comments on commit 33846ed

Please sign in to comment.