Skip to content

Commit

Permalink
Explicitly close dependency-check engine when done (clj-holmes#89)
Browse files Browse the repository at this point in the history
* Explicitly close dependency-check engine when done

Restructured internal code slightly to match semantics of working with a
resource that is open then closed.

Closes clj-holmes#86

* review feedback: use a thread
  • Loading branch information
lread authored Aug 4, 2024
1 parent 22b7bd3 commit d32845e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Unreleased
* Bump deps [#75](https://github.com/clj-holmes/clj-watson/issues/75)
* Improve command line experience [#77](https://github.com/clj-holmes/clj-watson/issues/77)
* Explicitly close the dependency-check engine when we are done with it [#86](https://github.com/clj-holmes/clj-watson/issues/86)

* v5.1.3 5812615 -- 2024-07-31
* Address [#60](https://github.com/clj-holmes/clj-watson/issues/60) by updating `org.owasp/dependency-check-core` to 10.0.3.
Expand Down
40 changes: 21 additions & 19 deletions src/clj_watson/controller/dependency_check/scanner.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
(binding [*out* *err*]
(println "Downloading/Updating database.")
(.doUpdates engine)
(println "Download/Update completed.")))
(println "Download/Update completed."))
engine)

(defn- sanitize-property
"Given a line from a properties file, remove sensitive information."
Expand Down Expand Up @@ -57,26 +58,27 @@
settings))

(defn ^:private build-engine [dependency-check-properties clj-watson-properties]
(let [settings (create-settings dependency-check-properties clj-watson-properties)
engine (Engine. settings)]
(update-download-database engine)
engine))
(let [settings (create-settings dependency-check-properties clj-watson-properties)]
(Engine. settings)))

(defn ^:private clojure-file? [dependency-path]
(string/ends-with? dependency-path ".jar"))

(defn ^:private scan-jars [dependencies dependency-check-properties clj-watson-properties]
(let [engine (build-engine dependency-check-properties clj-watson-properties)]
(->> dependencies
(map :paths)
(apply concat)
(filter clojure-file?)
(map io/file)
(.scan engine))
(.analyzeDependencies engine)
engine))
(defn ^:private scan-jars [engine dependencies]
(->> dependencies
(map :paths)
(apply concat)
(filter clojure-file?)
(map io/file)
(.scan engine))
(.analyzeDependencies engine)
engine)

(defn start! [dependencies dependency-check-properties clj-watson-properties]
(let [engine (scan-jars dependencies dependency-check-properties clj-watson-properties)
scanned-dependencies (->> engine .getDependencies Arrays/asList)]
scanned-dependencies))
(defn start!
[dependencies dependency-check-properties clj-watson-properties]
(with-open [engine (build-engine dependency-check-properties clj-watson-properties)]
(-> engine
(update-download-database)
(scan-jars dependencies)
(.getDependencies)
(Arrays/asList))))

0 comments on commit d32845e

Please sign in to comment.