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.175-RC4 #27

Merged
merged 4 commits into from
Sep 28, 2023
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
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
dev.weavejester/medley {:mvn/version "1.7.0"}
dom-top/dom-top {:mvn/version "1.0.8"}
miikka/clj-base62 {:mvn/version "0.1.1"}
com.github.pmonks/clj-spdx {:mvn/version "1.0.95"}
com.github.pmonks/clj-spdx {:mvn/version "1.0.103"}
com.github.pmonks/rencg {:mvn/version "1.0.34"}}
:aliases
{:build {:deps {com.github.pmonks/pbr {:mvn/version "RELEASE"}}
Expand Down
9 changes: 3 additions & 6 deletions pbr.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
; SPDX-License-Identifier: Apache-2.0
;

(def lib 'com.github.pmonks/lice-comb)

#_{:clj-kondo/ignore [:unresolved-namespace]}
(def version (format "2.0.%s-RC3" (b/git-count-revs nil)))

(defn set-opts
[opts]
(assoc opts
:lib lib
:version version
:lib 'com.github.pmonks/lice-comb
; :version (pbr/calculate-version 2 0)
:version (format "2.0.%s-RC4" (b/git-count-revs nil))
:write-pom true
:validate-pom true
:pom {:description "A Clojure library for software license detection."
Expand Down
4 changes: 2 additions & 2 deletions src/lice_comb/maven.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
pair. Returns nil if no matches were found."
[{:keys [name url]}]
; 1. Look in the name field(s)
(if-let [name-expressions (lciei/prepend-source "<name>" (lcmtch/name->expressions-info name))]
(if-let [name-expressions (lciei/prepend-source "<licenses><license><name>" (lcmtch/name->expressions-info name))]
name-expressions
; 2. If the names didn't give us any licenses, look in the url field(s) (this tends to be slower and less accurate)
(when-let [uri-expressions (lciei/prepend-source "<url>" (lcmtch/uri->expressions-info url))]
(when-let [uri-expressions (lciei/prepend-source "<licenses><license><url>" (lcmtch/uri->expressions-info url))]
uri-expressions)))

(defn- xml-find-all-alts
Expand Down
117 changes: 63 additions & 54 deletions src/lice_comb/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,76 @@
"Miscellaneous functionality."
(:require [clojure.string :as s]))

(def ^:private strategy->string {
:spdx-expression "SPDX expression"
:spdx-listed-identifier-exact-match "SPDX identifier"
:spdx-listed-identifier-case-insensitive-match "SPDX identifier (case insensitive match)"
:spdx-text-matching "SPDX license text matching"
:spdx-listed-name "SPDX listed name (case insensitive match)"
:spdx-listed-uri "SPDX listed URI (relaxed matching)"
:expression-inference "inferred SPDX expression"
:regex-matching "regular expression matching"
:unlisted "fallback to unlisted LicenseRef"
:manual-verification "manual verification"})
(def strategy->string
"A map that turns a matching strategy from an expression-info map into a
human readable equivalent. This is mostly intended for debugging / developer
discovery purposes, and the behaviour may change without warning."
{:spdx-expression "SPDX expression"
:spdx-listed-identifier-exact-match "SPDX identifier"
:spdx-listed-identifier-case-insensitive-match "SPDX identifier (case insensitive match)"
:spdx-text-matching "SPDX license text matching"
:spdx-listed-name "SPDX listed name (case insensitive match)"
:spdx-listed-uri "SPDX listed URI (relaxed matching)"
:expression-inference "inferred SPDX expression"
:regex-matching "regular expression matching"
:unlisted "fallback to unlisted LicenseRef"
:manual-verification "manual verification"})

(defn- expression-info-keyfn
"sort-by keyfn for lice-comb info maps"
[metadata]
(str (case (:id metadata)
nil "0"
"1")
"-"
(case (:type metadata)
:declared "0"
:concluded "1")
"-"
(case (:confidence metadata)
nil "0"
:high "1"
:medium "2"
:low "3")
"-"
(case (:strategy metadata)
:spdx-expression "0"
:spdx-listed-identifier-exact-match "1"
:spdx-listed-identifier-case-insensitive-match "2"
:spdx-text-matching "3"
:spdx-listed-name "4"
:spdx-listed-uri "5"
:expression-inference "6"
:regex-matching "7"
:unlisted "8"
:manual-verification "9")))
(defn expression-info-sort-by-keyfn
"A sort-by keyfn for expression-info maps. This is mostly intended for
debugging / developer discovery purposes, and the behaviour may change without
warning."
[m]
(when m
(str (case (:id m)
nil "0"
"1")
"-"
(case (:type m)
:declared "0"
:concluded "1")
"-"
(case (:confidence m)
nil "0"
:high "1"
:medium "2"
:low "3")
"-"
(case (:strategy m)
:spdx-expression "0"
:spdx-listed-identifier-exact-match "1"
:spdx-listed-identifier-case-insensitive-match "2"
:spdx-text-matching "3"
:spdx-listed-name "4"
:spdx-listed-uri "5"
:expression-inference "6"
:regex-matching "7"
:unlisted "8"
:manual-verification "9"))))

(defn- expression-info->string
(defn expression-info->string
"Converts the given expression-info map into a human-readable string, using
the information in license-info map m."
the information in license-info map m. This is mostly intended for
debugging / developer discovery purposes, and the behaviour may change without
warning."
[m id]
(str id ":\n"
(when-let [info-list (sort-by expression-info-keyfn (seq (get m id)))]
(s/join "\n" (map #(str " "
(when-let [md-id (:id %)] (when (not= id md-id) (str md-id " ")))
(case (:type %)
:declared "Declared"
:concluded "Concluded")
(when-let [confidence (:confidence %)] (str "\n Confidence: " (name confidence)))
(when-let [strategy (:strategy %)] (str "\n Strategy: " (get strategy->string strategy (name strategy))))
(when-let [source (seq (:source %))] (str "\n Source:\n > " (s/join "\n > " source))))
info-list)))))
(when (and m id)
(str id ":\n"
(when-let [info-list (sort-by expression-info-sort-by-keyfn (seq (get m id)))]
(s/join "\n" (map #(str " "
(when-let [md-id (:id %)] (when (not= id md-id) (str md-id " ")))
(case (:type %)
:declared "Declared"
:concluded "Concluded")
(when-let [confidence (:confidence %)] (str "\n Confidence: " (name confidence)))
(when-let [strategy (:strategy %)] (str "\n Strategy: " (get strategy->string strategy (name strategy))))
(when-let [source (seq (:source %))] (str "\n Source:\n > " (s/join "\n > " source))))
info-list))))))

(defn expressions-info->string
"Converts the given expressions-info map into a human-readable string. This
function is mostly intended for debugging / developer discovery purposes, and
the content and format of the output may change without warning."
is mostly intended for debugging / developer discovery purposes, and the
behaviour may change without warning."
[m]
(when m
(let [ids (sort (keys m))]
Expand Down