Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.0.235 #58

Merged
merged 5 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
{:deps
{jansi-clj/jansi-clj {:mvn/version "1.0.3"}
com.github.pmonks/clj-wcwidth {:mvn/version "1.0.85"}
com.github.pmonks/lice-comb {:mvn/version "2.0.292"}
com.github.pmonks/asf-cat {:mvn/version "2.0.135"}
com.github.pmonks/tools-convenience {:mvn/version "1.0.151"}}
com.github.pmonks/lice-comb {:mvn/version "2.0.321"}
com.github.pmonks/asf-cat {:mvn/version "2.0.139"}
com.github.pmonks/tools-convenience {:mvn/version "1.0.154"}}
:aliases
{:build {:deps {com.github.pmonks/pbr {:mvn/version "RELEASE"}
com.github.pmonks/tools-licenses {:local/root "."}}
Expand Down
67 changes: 38 additions & 29 deletions src/tools_licenses/tasks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,6 @@
(when (seq exps)
(seq (sort-by #(s/lower-case (human-readable-expression identity %)) exps))))

(defn- dep-and-license-expressions
[dep-name license-expressions]
(let [sorted-license-expressions (sort-license-expressions (if (map? license-expressions) (keys license-expressions) license-expressions))]
(str dep-name
" [" (if sorted-license-expressions
(s/join ", " (map human-readable-expression sorted-license-expressions))
(ansi/fg-bright :red "No licenses found"))
"]")))

(defn- dep-and-licenses->string
[[dep-ga dep-info :as dep]]
(let [dep-ga (str dep-ga)
dep-v (lcd/dep->version dep)
license-expressions (:lice-comb/license-info dep-info)]
(dep-and-license-expressions (str dep-ga "@" dep-v) license-expressions)))

(defn- fit-width
"Pads or trims string s to display width w, with control over whether padding
happens before or after"
Expand All @@ -126,31 +110,56 @@
(defn- summary-output!
"Emit summary output to stdout."
[proj-expressions-info deps-lib-map-with-info]
(let [proj-expressions (sort-license-expressions (keys proj-expressions-info))
freqs (frequencies (filter identity (mapcat #(keys (get % :lice-comb/license-info)) (vals deps-lib-map-with-info))))
deps-expressions (sort-license-expressions (keys freqs))
no-license-count (count (filter empty? (map #(:lice-comb/license-info (val %)) deps-lib-map-with-info)))
single-license-count (count (filter #(= (count %) 1) (map #(:lice-comb/license-info (val %)) deps-lib-map-with-info)))
multi-license-count (count (filter #(> (count %) 1) (map #(:lice-comb/license-info (val %)) deps-lib-map-with-info)))]
(let [proj-expressions (sort-license-expressions (keys proj-expressions-info))
freqs (frequencies (filter identity (mapcat #(keys (get % :lice-comb/license-info)) (vals deps-lib-map-with-info))))
deps-expressions (sort-license-expressions (keys freqs))
license-infos (map #(:lice-comb/license-info (val %)) deps-lib-map-with-info)
no-license-count (count (filter empty? license-infos))
single-license-count (count (filter #(and (= 1 (count (keys %))) (sexp/simple? (first (keys %)))) license-infos))
multi-license-count (count (filter #(or (> (count (keys %)) 1) (some sexp/compound? (keys %))) license-infos))
multiple-exprs-license-count (count (filter #(> (count (keys %)) 1) license-infos))]

(print (str "\n" (ansi/bold "This project: ")))
(if (seq proj-expressions)
(println (s/join ", " (map human-readable-expression proj-expressions)))
(println (ansi/fg-bright :red "No licenses found")))

(println (ansi/bold "\nLicense Expression # of Deps"
"\n------------------------------------------------------------ ---------"))
(if (or deps-expressions (pos? no-license-count))
(do
(run! #(println (str (fit-width 60 (human-readable-expression %)) " " (fit-width 9 (ansi/default (str (get freqs %))) false))) deps-expressions)
(when (pos? no-license-count) (println (str (fit-width 60 (ansi/fg-bright :red "No licenses found")) " " (fit-width 9 no-license-count false)))))
(println " - no dependencies found -"))

(println (str (ansi/bold "------------------------------------------------------------ ---------")
"\n"
"\n " (ansi/bold "Deps with no licensing: ") (fit-width 9 (str no-license-count) false)
"\n " (ansi/bold "Deps with 1 license expression: ") (fit-width 9 (str single-license-count) false)
"\n " (ansi/bold "Deps with multiple license expressions: ") (fit-width 9 (str multi-license-count) false)
"\n " (ansi/bold "TOTAL DEPS: " (fit-width 9 (str (+ no-license-count single-license-count multi-license-count)) false))
"\n " (ansi/bold "Deps with no detected licenses: ") (fit-width 9 (str no-license-count) false)
"\n " (ansi/bold "Deps with 1 license: ") (fit-width 9 (str single-license-count) false)
"\n " (ansi/bold "Deps with multiple licenses: ") (fit-width 9 (str multi-license-count) false)
"\n " (ansi/bold "Deps with multiple license expressions: ") (fit-width 9 (str multiple-exprs-license-count) false)
"\n"
"\n " (ansi/bold " Direct deps: ") (fit-width 9 (str (count (into {} (remove (fn [[_ v]] (seq (:dependents v))) deps-lib-map-with-info)))) false)
"\n " (ansi/bold "Transitive deps: ") (fit-width 9 (count (into {} (filter (fn [[_ v]] (seq (:dependents v))) deps-lib-map-with-info))) false)
"\n " (ansi/bold " TOTAL DEPS: ") (fit-width 9 (count deps-lib-map-with-info) false)
"\n"))))

(defn- dep-and-license-expressions
[dep-name license-expressions]
(let [sorted-license-expressions (sort-license-expressions (if (map? license-expressions) (keys license-expressions) license-expressions))]
(str (ansi/fg-bright :black dep-name)
" "
(if sorted-license-expressions
(s/join ", " (map human-readable-expression sorted-license-expressions))
(ansi/fg-bright :red "No licenses found")))))

(defn- dep-and-licenses->string
[[dep-ga dep-info :as dep]]
(let [dep-ga (str dep-ga)
dep-v (lcd/dep->version dep)
license-expressions (:lice-comb/license-info dep-info)]
(dep-and-license-expressions (str dep-ga "@" dep-v) license-expressions)))

(defn- detailed-output!
"Emit detailed output to stdout."
[opts proj-expressions-info deps-lib-map-with-info]
Expand Down Expand Up @@ -198,12 +207,12 @@
(defn- explain-with-licenses!
[dep-expr-info]
(let [exprs (sort-license-expressions (keys dep-expr-info))]
(println (ansi/bold "Licenses:") (s/join ", " (map human-readable-expression exprs)) "\n")
(println (ansi/bold "License(s):") (s/join ", " (map human-readable-expression exprs)) "\n")
(println (s/join "\n\n" (map (partial expression-info->string dep-expr-info) exprs)) "\n")))

(defn- explain-without-licenses!
[dep]
(println (ansi/bold "Licenses:") (ansi/fg-bright :red "No licenses found"))
(println (ansi/bold "License(s):") (ansi/fg-bright :red "No licenses found"))
(println (ansi/bold "\nLocations checked:"))
(println (s/join "\n" (map remove-file-prefix (lcd/dep->locations dep))))
(println))
Expand All @@ -214,7 +223,7 @@
(if ga
(if-let [version (lcd/dep->version dep)]
(do
(println (str "\n" (ansi/bold "Artifact: ") (str ga "@" version)))
(println (str "\n" (ansi/bold " Artifact: ") (str ga "@" version)))
(if (empty? dep-expr-info)
(explain-without-licenses! dep)
(explain-with-licenses! dep-expr-info)))
Expand Down