diff --git a/CHANGELOG.md b/CHANGELOG.md index a5ed540..b21d08e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ environment variable: DEPS_CLJ_TOOLS_VERSION=1.11.1.1165 bb clojure ``` +## Unreleased + +- [#71](https://github.com/borkdude/deps.clj/issues/71): Port stale check for jar files ([commit](https://github.com/clojure/brew-install/commit/f791abf1d93563c1ed8f256830bd0bfc085fdd53)] + ## v1.11.1.1165 - Add support for `CLJ_JVM_OPTS` and `JAVA_OPTS` environment variables ([@ikappaki](https://github.com/ikappaki)) diff --git a/deps.bat b/deps.bat index efece97..c6f94b3 100644 --- a/deps.bat +++ b/deps.bat @@ -280,8 +280,8 @@ For more info, see: [s] (when s (let [p (cond - (clojure.string/starts-with? s "http://") (subs s 7) - (clojure.string/starts-with? s "https://") (subs s 8) + (str/starts-with? s "http://") (subs s 7) + (str/starts-with? s "https://") (subs s 8) :else s) auth-proxy-match (re-matches authenticated-proxy-re p) unauth-proxy-match (re-matches unauthenticated-proxy-re p)] @@ -435,21 +435,25 @@ For more info, see: (def java-exe (if windows? "java.exe" "java")) +(defn- get-java-cmd + "Returns the path to java executable to invoke commands on." + [] + (or (*getenv-fn* "JAVA_CMD") + (let [java-cmd (which java-exe)] + (if (str/blank? java-cmd) + (let [java-home (*getenv-fn* "JAVA_HOME")] + (if-not (str/blank? java-home) + (let [f (io/file java-home "bin" java-exe)] + (if (and (.exists f) + (.canExecute f)) + (.getCanonicalPath f) + (throw (Exception. "Couldn't find 'java'. Please set JAVA_HOME.")))) + (throw (Exception. "Couldn't find 'java'. Please set JAVA_HOME.")))) + java-cmd)))) + (defn -main [& command-line-args] (let [opts (parse-args command-line-args) - java-cmd - (or (*getenv-fn* "JAVA_CMD") - (let [java-cmd (which java-exe)] - (if (str/blank? java-cmd) - (let [java-home (*getenv-fn* "JAVA_HOME")] - (if-not (str/blank? java-home) - (let [f (io/file java-home "bin" java-exe)] - (if (and (.exists f) - (.canExecute f)) - (.getCanonicalPath f) - (throw (Exception. "Couldn't find 'java'. Please set JAVA_HOME.")))) - (throw (Exception. "Couldn't find 'java'. Please set JAVA_HOME.")))) - java-cmd))) + java-cmd (get-java-cmd) env-tools-dir (or ;; legacy name (*getenv-fn* "CLOJURE_TOOLS_DIR") @@ -576,31 +580,38 @@ For more info, see: (println)) tree? (:tree opts) ;; Check for stale classpath file + cp-file (io/file cp-file) stale (or (:force opts) (:trace opts) tree? (:prep opts) - (not (.exists (io/file cp-file))) + (not (.exists cp-file)) (when tool-name (let [tool-file (io/file config-dir "tools" (str tool-name ".edn"))] (when (.exists tool-file) (> (.lastModified tool-file) - (.lastModified (io/file cp-file)))))) - (let [cp-file (io/file cp-file)] - (some (fn [config-path] - (let [f (io/file config-path)] - (when (.exists f) - (> (.lastModified f) - (.lastModified cp-file))))) config-paths)) + (.lastModified cp-file))))) + (some (fn [config-path] + (let [f (io/file config-path)] + (when (.exists f) + (> (.lastModified f) + (.lastModified cp-file))))) config-paths) + ;; Are deps.edn files stale? (when (.exists (io/file manifest-file)) - (let [manifests (-> manifest-file slurp str/split-lines) - cp-file (io/file cp-file)] + (let [manifests (-> manifest-file slurp str/split-lines)] (some (fn [manifest] (let [f (io/file manifest)] (or (not (.exists f)) (> (.lastModified f) - (.lastModified cp-file))))) manifests)))) + (.lastModified cp-file))))) manifests))) + ;; Are .jar files in classpath missing? + (let [cp (slurp cp-file) + entries (vec (.split ^String cp java.io.File/pathSeparator))] + (some (fn [entry] + (when (str/ends-with? entry ".jar") + (not (.exists (io/file entry))))) + entries))) tools-args (when (or stale (:pom opts)) (cond-> [] @@ -653,7 +664,7 @@ For more info, see: (let [cp (cond (or classpath-not-needed? (:prep opts)) nil (not (str/blank? (:force-cp opts))) (:force-cp opts) - :else (slurp (io/file cp-file)))] + :else (slurp cp-file))] (cond (:help opts) (do (println @help-text) (*exit-fn* 0)) (:version opts) (do (println "Clojure CLI version (deps.clj)" @version) diff --git a/deps.clj b/deps.clj index 6f8a1d8..5dd7b67 100755 --- a/deps.clj +++ b/deps.clj @@ -275,8 +275,8 @@ For more info, see: [s] (when s (let [p (cond - (clojure.string/starts-with? s "http://") (subs s 7) - (clojure.string/starts-with? s "https://") (subs s 8) + (str/starts-with? s "http://") (subs s 7) + (str/starts-with? s "https://") (subs s 8) :else s) auth-proxy-match (re-matches authenticated-proxy-re p) unauth-proxy-match (re-matches unauthenticated-proxy-re p)] @@ -430,21 +430,25 @@ For more info, see: (def java-exe (if windows? "java.exe" "java")) +(defn- get-java-cmd + "Returns the path to java executable to invoke commands on." + [] + (or (*getenv-fn* "JAVA_CMD") + (let [java-cmd (which java-exe)] + (if (str/blank? java-cmd) + (let [java-home (*getenv-fn* "JAVA_HOME")] + (if-not (str/blank? java-home) + (let [f (io/file java-home "bin" java-exe)] + (if (and (.exists f) + (.canExecute f)) + (.getCanonicalPath f) + (throw (Exception. "Couldn't find 'java'. Please set JAVA_HOME.")))) + (throw (Exception. "Couldn't find 'java'. Please set JAVA_HOME.")))) + java-cmd)))) + (defn -main [& command-line-args] (let [opts (parse-args command-line-args) - java-cmd - (or (*getenv-fn* "JAVA_CMD") - (let [java-cmd (which java-exe)] - (if (str/blank? java-cmd) - (let [java-home (*getenv-fn* "JAVA_HOME")] - (if-not (str/blank? java-home) - (let [f (io/file java-home "bin" java-exe)] - (if (and (.exists f) - (.canExecute f)) - (.getCanonicalPath f) - (throw (Exception. "Couldn't find 'java'. Please set JAVA_HOME.")))) - (throw (Exception. "Couldn't find 'java'. Please set JAVA_HOME.")))) - java-cmd))) + java-cmd (get-java-cmd) env-tools-dir (or ;; legacy name (*getenv-fn* "CLOJURE_TOOLS_DIR") @@ -571,31 +575,38 @@ For more info, see: (println)) tree? (:tree opts) ;; Check for stale classpath file + cp-file (io/file cp-file) stale (or (:force opts) (:trace opts) tree? (:prep opts) - (not (.exists (io/file cp-file))) + (not (.exists cp-file)) (when tool-name (let [tool-file (io/file config-dir "tools" (str tool-name ".edn"))] (when (.exists tool-file) (> (.lastModified tool-file) - (.lastModified (io/file cp-file)))))) - (let [cp-file (io/file cp-file)] - (some (fn [config-path] - (let [f (io/file config-path)] - (when (.exists f) - (> (.lastModified f) - (.lastModified cp-file))))) config-paths)) + (.lastModified cp-file))))) + (some (fn [config-path] + (let [f (io/file config-path)] + (when (.exists f) + (> (.lastModified f) + (.lastModified cp-file))))) config-paths) + ;; Are deps.edn files stale? (when (.exists (io/file manifest-file)) - (let [manifests (-> manifest-file slurp str/split-lines) - cp-file (io/file cp-file)] + (let [manifests (-> manifest-file slurp str/split-lines)] (some (fn [manifest] (let [f (io/file manifest)] (or (not (.exists f)) (> (.lastModified f) - (.lastModified cp-file))))) manifests)))) + (.lastModified cp-file))))) manifests))) + ;; Are .jar files in classpath missing? + (let [cp (slurp cp-file) + entries (vec (.split ^String cp java.io.File/pathSeparator))] + (some (fn [entry] + (when (str/ends-with? entry ".jar") + (not (.exists (io/file entry))))) + entries))) tools-args (when (or stale (:pom opts)) (cond-> [] @@ -648,7 +659,7 @@ For more info, see: (let [cp (cond (or classpath-not-needed? (:prep opts)) nil (not (str/blank? (:force-cp opts))) (:force-cp opts) - :else (slurp (io/file cp-file)))] + :else (slurp cp-file))] (cond (:help opts) (do (println @help-text) (*exit-fn* 0)) (:version opts) (do (println "Clojure CLI version (deps.clj)" @version) diff --git a/src/borkdude/deps.clj b/src/borkdude/deps.clj index 0c8f4e9..cb048b3 100755 --- a/src/borkdude/deps.clj +++ b/src/borkdude/deps.clj @@ -10,7 +10,7 @@ (set! *warn-on-reflection* true) (def path-separator (System/getProperty "path.separator")) -;; see https://github.com/clojure/brew-install/blob/1.10.3/CHANGELOG.md +;; see https://github.com/clojure/brew-install/blob/1.11.1/CHANGELOG.md (def version (delay (or (System/getenv "DEPS_CLJ_TOOLS_VERSION") "1.11.1.1165"))) @@ -592,6 +592,7 @@ For more info, see: (when (.exists f) (> (.lastModified f) (.lastModified cp-file))))) config-paths) + ;; Are deps.edn files stale? (when (.exists (io/file manifest-file)) (let [manifests (-> manifest-file slurp str/split-lines)] (some (fn [manifest] @@ -599,16 +600,12 @@ For more info, see: (or (not (.exists f)) (> (.lastModified f) (.lastModified cp-file))))) manifests))) - ;; this may appear in upstream, waiting for that - #_(let [cp (slurp cp-file) + ;; Are .jar files in classpath missing? + (let [cp (slurp cp-file) entries (vec (.split ^String cp java.io.File/pathSeparator))] - ;; Only check .jar files for non-existence. Gitlibs should be - ;; covered by manifest checks above. Other dirs may not exist, - ;; e.g. {:paths ["foo"]} and should not indicate staleness. (some (fn [entry] - (let [exists-when-jar? (or (not (str/ends-with? entry ".jar")) - (.exists (io/file entry)))] - (not exists-when-jar?))) + (when (str/ends-with? entry ".jar") + (not (.exists (io/file entry))))) entries))) tools-args (when (or stale (:pom opts)) diff --git a/test/borkdude/deps_test.clj b/test/borkdude/deps_test.clj index 85f25f9..9f97e1e 100644 --- a/test/borkdude/deps_test.clj +++ b/test/borkdude/deps_test.clj @@ -255,8 +255,7 @@ (deps/-main "-P"))] (is (not (some #{xx-pclf} sh-args))))))) -;; wait for fix in upstream -#_(deftest stale-cache-rm-mvn-dir-test +(deftest stale-cache-rm-mvn-dir-test (let [deps-map (pr-str '{:mvn/local-repo "test/mvn" :deps {medley/medley {:mvn/version "1.4.0"} io.github.borkdude/quickblog {:git/sha "8f5898ee911101a96295f59bb5ffc7517757bc8f"}}}) delete #(do (fs/delete-tree (fs/file "test" "mvn"))