Skip to content

Commit

Permalink
Fix #71: jar file stale check (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Oct 24, 2022
1 parent 30bd564 commit efffdc3
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 65 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
65 changes: 38 additions & 27 deletions deps.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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-> []
Expand Down Expand Up @@ -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)
Expand Down
65 changes: 38 additions & 27 deletions deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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-> []
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 6 additions & 9 deletions src/borkdude/deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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")))

Expand Down Expand Up @@ -592,23 +592,20 @@ 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]
(let [f (io/file manifest)]
(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))
Expand Down
3 changes: 1 addition & 2 deletions test/borkdude/deps_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit efffdc3

Please sign in to comment.