Skip to content

Commit 0cd9061

Browse files
committed
Extract parse-classpath for clarity and improve commentary
1 parent c042fa3 commit 0cd9061

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/nvd/task/check.clj

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,31 @@
3737
(delay {:nvd-clojure (get-version "nvd-clojure" "nvd-clojure")
3838
:dependency-check (.getImplementationVersion (.getPackage Engine))}))
3939

40+
(def classpath-separator-re
41+
(re-pattern (str File/pathSeparatorChar)))
42+
4043
(defn absolute-path ^String [file]
4144
(s/replace-first file #"^~" (System/getProperty "user.home")))
4245

46+
(defn parse-classpath
47+
"Accepts a classpath string (i.e. colon-separated paths) and returns a sequence of analyzable
48+
absolute paths.
49+
50+
In particular, source paths such as `src`, while part of the classpath, won't be meaningfully
51+
analyzed by dependency-check-core. We only care about regular files (e.g. *.jar or
52+
package-lock.json). Thus, skip directories in general as well as non-existing files."
53+
[classpath-string]
54+
(into []
55+
(comp (remove (fn [^String s]
56+
(let [file (io/file s)]
57+
(or (.isDirectory file)
58+
(not (.exists file))))))
59+
(map absolute-path))
60+
(s/split classpath-string classpath-separator-re)))
61+
4362
(defn- scan-and-analyze [project]
4463
(let [^Engine engine (:engine project)]
64+
;; See `parse-classpath` for details on which classpath entries are considered here.
4565
(doseq [p (:classpath project)]
4666
(.scan engine (absolute-path p)))
4767
(try
@@ -90,24 +110,12 @@
90110
fail-build?
91111
conditional-exit)))
92112

93-
(def classpath-separator-re
94-
(re-pattern (str File/pathSeparatorChar)))
95-
96113
(defn -main [& [config-filename ^String classpath-string]]
97114
(when (s/blank? classpath-string)
98115
(throw (ex-info "nvd-clojure requires a classpath value to be explicitly passed as a CLI argument.
99116
Older usages are deprecated." {})))
100117

101-
(let [classpath (s/split classpath-string classpath-separator-re)
102-
classpath (into []
103-
(remove (fn [^String s]
104-
;; Source paths such as `src`, while part of the classpath, won't
105-
;; be meaningfully analyzed by dependency-check-core. Thus, skip
106-
;; directories in general as well as non-existing files.
107-
(let [file (io/file s)]
108-
(or (.isDirectory file)
109-
(not (.exists file))))))
110-
classpath)]
118+
(let [classpath (parse-classpath classpath-string)]
111119

112120
(when-not (System/getProperty "nvd-clojure.internal.skip-self-check")
113121
(when-let [bad-entry (->> classpath

0 commit comments

Comments
 (0)