Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hypirion committed Feb 4, 2016
1 parent e14da08 commit c630502
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion leiningen-core/src/leiningen/core/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
(defn- update-each-contained [m keys f & args]
(reduce (fn [m k]
(if (contains? m k)
(apply update-in m [k] f args)
(apply update m k f args)
m)) m keys))

(defn- update-first [coll pred f]
Expand Down
8 changes: 8 additions & 0 deletions leiningen-core/src/leiningen/core/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,11 @@
(cons x (step (rest s) (conj seen fx)))))))
xs seen)))]
(reverse (step (reverse coll) #{}))))

(defn ancestor?
"Is a an ancestor of b?"
[a b]
(let [hypothetical-ancestor (.getCanonicalPath (io/file a))
hypothetical-descendant (.getCanonicalPath (io/file b))]
(and (.startsWith hypothetical-descendant hypothetical-ancestor)
(not (= hypothetical-descendant hypothetical-ancestor)))))
2 changes: 1 addition & 1 deletion leiningen-core/test/leiningen/core/test/classpath.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
(.mkdirs d1)
(spit (io/file d1 "project.clj")
(pr-str '(defproject hello "1.0")))
(is (= (for [path ["src" "dev-resources" "resources"
(is (= (for [path ["src" "dev-resources" "resources"
"target/classes" "foo"]]
(lthelper/pathify (format "/tmp/lein-sample-project/checkouts/d1/%s" path)))
(#'leiningen.core.classpath/checkout-deps-paths project)))
Expand Down
4 changes: 1 addition & 3 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
cemerick.pomegranate
classlojure.core
clojure.tools.nrepl
clj-http.core
;; to avoid compile warnings at runtime:
clj-http.client]}}
clj-http.core]}}
:test-selectors {:default (complement :disabled)
:offline (comp (partial not-any? identity)
(juxt :online :disabled))}
Expand Down
12 changes: 2 additions & 10 deletions src/leiningen/clean.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@
(.setWritable f true)
(io/delete-file f silently)))

(defn- ancestor?
"Is a an ancestor of b?"
[a b]
(let [hypothetical-ancestor (.getCanonicalPath (io/file a))
hypothetical-descendant (.getCanonicalPath (io/file b))]
(and (.startsWith hypothetical-descendant hypothetical-ancestor)
(not (= hypothetical-descendant hypothetical-ancestor)))))

(defn- protected-paths
"Returns a set of leiningen project source directories and important files."
[project]
Expand All @@ -52,7 +44,7 @@
[project path]
(let [protected-paths (protected-paths project)]
(or (protected-paths (.getCanonicalPath (io/file path)))
(some #(ancestor? % path) protected-paths))))
(some #(utils/ancestor? % path) protected-paths))))

(defn- protect-clean-targets?
"Returns the value of :protect in the metadata map for the :clean-targets
Expand All @@ -72,7 +64,7 @@
[project clean-target]
(when (and (string? clean-target)
(protect-clean-targets? project))
(cond (not (ancestor? (:root project) clean-target))
(cond (not (utils/ancestor? (:root project) clean-target))
(main/abort (error-msg "Deleting path outside of the project root [\""
clean-target "\"] is not allowed."))
(protected-path? project clean-target)
Expand Down
8 changes: 3 additions & 5 deletions src/leiningen/update_in.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
task+args]))

(defn ^:internal update-project [project keys-vec f args]
(let [f #(apply apply (concat (if (seq keys-vec)
[clj/update-in % keys-vec f]
[f %])
args
[nil]))]
(let [f #(if (seq keys-vec)
(apply clj/update-in % keys-vec f args)
(apply f % args))]
(-> (vary-meta (f project) clj/update-in [:without-profiles] f)
(project/load-plugins)
(project/activate-middleware))))
Expand Down

0 comments on commit c630502

Please sign in to comment.