Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sneaking in just under 1000 LOC modulo lein-newnew.
- Loading branch information
1 parent
ec89737
commit b1046bc
Showing
16 changed files
with
126 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,62 +1,8 @@ | |||
(ns leiningen.deps | (ns leiningen.deps | ||
"Download all dependencies." | "Download all dependencies." | ||
(:require [clojure.java.io :as io] | (:require [leiningen.core.classpath :as classpath])) | ||
[leiningen.clean :as clean] | |||
[leiningen.core.classpath :as classpath] | |||
[leiningen.core.user :as user]) | |||
(:import (java.security MessageDigest) | |||
(java.util.jar JarFile))) | |||
|
|||
(defn- sha1-digest [content] | |||
(.toString (BigInteger. 1 (-> (MessageDigest/getInstance "SHA1") | |||
(.digest (.getBytes content)))) 16)) | |||
|
|||
(defn- deps-checksum [project] | |||
(sha1-digest (pr-str (:dependencies project)))) | |||
|
|||
(defn- new-deps-checksum-file [project] | |||
(io/file (:target-path project) ".lein-deps-sum")) | |||
|
|||
(defn- has-dependencies? [project] | |||
(some (comp seq project) [:dependencies :dev-dependencies])) | |||
|
|||
;; TODO: is this necessary with keeping everything in ~/.m2? | |||
(defn fetch-deps? | |||
"Should we even bother fetching dependencies?" | |||
[project] | |||
(let [deps-checksum-file (new-deps-checksum-file project)] | |||
(and (has-dependencies? project) | |||
;; There's got to be a better way to detect direct invocation? | |||
(or ;; (= "deps" *current-task*) | |||
(not (:checksum-deps project (:checksum-deps (user/settings) true))) | |||
(not (.exists deps-checksum-file)) | |||
(not= (slurp deps-checksum-file) (deps-checksum project)))))) | |||
|
|||
(defn- jar-files [files] | |||
(for [file files | |||
:when (.endsWith (.getName file) ".jar")] | |||
(JarFile. file))) | |||
|
|||
(defn extract-native-deps [project files] | |||
(doseq [jar (jar-files files) | |||
entry (enumeration-seq (.entries jar)) | |||
:when (.startsWith (.getName entry) "native/")] | |||
(let [f (io/file (:native-path project) | |||
(subs (.getName entry) (count "native/")))] | |||
(if (.isDirectory entry) | |||
(.mkdirs f) | |||
(io/copy (.getInputStream jar entry) f))))) | |||
|
|
||
(defn deps | (defn deps | ||
"Download :dependencies and put them in :library-path." | "Download all dependencies. You should never need to invoke this manually." | ||
[project] | [project] | ||
(when (fetch-deps? project) | (classpath/resolve-dependencies project)) | ||
(when-not (or (:disable-deps-clean project) | |||
(:disable-implicit-clean project)) | |||
(clean/clean project)) | |||
(let [files (classpath/resolve-dependencies project)] | |||
(extract-native-deps project files) | |||
(let [checksum-file (new-deps-checksum-file project)] | |||
(.mkdirs (.getParentFile checksum-file)) | |||
(spit checksum-file (deps-checksum project))) | |||
files))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.