Skip to content

Commit f30c98d

Browse files
authored
Merge pull request #63 from pmonks/issue-62
Fix for issue #62
2 parents 4ef0a76 + 01ca17d commit f30c98d

File tree

5 files changed

+153
-143
lines changed

5 files changed

+153
-143
lines changed

src/lice_comb/impl/regex_matching.clj

+27-26
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929

3030
(defn- get-rencgs
3131
"Get a value for an re-ncg, potentially looking at multiple ncgs in order
32-
until a non-blank value is found. Also trims and lower-cases the value, and
33-
replaces all whitespace with a single space."
32+
until a non-blank value is found. Returns `default` when no non-blank value is
33+
found (and which defaults to `nil` if not provided). Trims and lower-cases the
34+
value, and replaces all whitespace with a single space."
3435
([m names] (get-rencgs m names nil))
3536
([m names default]
3637
(loop [f (first names)
@@ -123,8 +124,8 @@
123124
"netbsd" "NetBSD"
124125
"modification" "Modification"
125126
("no military license" "no military licence") "No-Military-License"
126-
("no nuclear license" "no nuclear licence") "No-Nuclear-License"
127127
("no nuclear license 2014" "no nuclear licence 2014") "No-Nuclear-License-2014"
128+
("no nuclear license" "no nuclear licence") "No-Nuclear-License"
128129
"no nuclear warranty" "No-Nuclear-Warranty"
129130
"open mpi" "Open-MPI"
130131
"shortened" "Shortened"
@@ -186,27 +187,27 @@
186187
(defn- gpl-id-constructor
187188
"An SPDX id constructor specific to the GNU family of licenses."
188189
[m]
189-
(let [variant (cond (contains? m "agpl") "AGPL"
190-
(contains? m "lgpl") "LGPL"
191-
(contains? m "gpl") "GPL")
192-
version (get-rencgs m ["version"] "")
193-
version (s/replace version #"\p{Punct}+" ".")
190+
(let [variant (cond (contains? m "agpl") "AGPL"
191+
(contains? m "lgpl") "LGPL"
192+
(contains? m "gpl") "GPL")
193+
version-present? (boolean (get-rencgs m ["version"] false))
194+
version (get-rencgs m ["version"] (if (= variant "LGPL") "2.0" "1.0"))
195+
version (s/replace version #"\p{Punct}+" ".")
194196
[confidence confidence-explanations]
195-
(if (s/blank? version)
196-
[:low #{:missing-version}]
197-
(if (s/includes? version ".")
198-
[:high]
199-
[:medium #{:partial-version}]))
200-
version (if (s/blank? version)
201-
(:latest-ver m)
202-
version)
203-
version (if (s/includes? version ".")
204-
version
205-
(str version ".0"))
206-
suffix (if (contains? m "orLater")
207-
"or-later"
208-
"only") ; Note: we (conservatively) default to "only" when we don't have an explicit suffix
209-
id (str variant "-" version "-" suffix)]
197+
(if (s/blank? version)
198+
[:low #{:missing-version}]
199+
(if (s/includes? version ".")
200+
[:high]
201+
[:medium #{:partial-version}]))
202+
version (if (s/includes? version ".")
203+
version
204+
(str version ".0"))
205+
[suffix confidence-explanations]
206+
(cond (contains? m "orLater") ["or-later" confidence-explanations]
207+
(contains? m "only") ["only" confidence-explanations]
208+
:else [(if version-present? "only" "or-later") ; Note: on the advice of SPDX technical team, default to "or later" variant if version not present
209+
(set/union #{:missing-version-suffix} confidence-explanations)])
210+
id (str variant "-" version "-" suffix)]
210211
[(assert-listed-id id) confidence confidence-explanations]))
211212
212213
(defn- simple-regex-match
@@ -221,9 +222,9 @@
221222

222223

223224
; The regex for the GNU family is a nightmare, so we build it up (and test it) in pieces
224-
(def agpl-re #"(?<agpl>AGPL|Affero)(\s+GNU)?(\s+General)?(\s+Public)?(\s+Licen[cs]e)?(\s+\(?AGPL\)?)?")
225-
(def lgpl-re #"(?<lgpl>L\s?GPL|GNU\s+(Library|Lesser)|(Library|Lesser)\s+(L?GPL|General\s+Public\s+Licen[cs]e))(\s+or\s+Lesser)?(\s+General)?(\s+Pub?lic)?(\s+Licen[cs]e)?(\s+\(?LGPL\)?)?")
226-
(def gpl-re #"(?<!(Affero|Lesser|Library)\s+)(?<gpl>GNU(?!\s+Classpath)|(?<!(L|A)\s*)GPL|General\s+Public\s+Licen[cs]e)(?!\s+(Affero|Library|Lesser|General\s+Lesser|General\s+Library|LGPL|AGPL))((\s+General)?(?!\s+(Affero|Lesser|Library))\s+Public\s+Licen[cs]e)?(\s+\(?GPL\)?)?")
225+
(def agpl-re #"(?<agpl>AGPL|Affero)(\s+GNU)?(\s+Genere?al)?(\s+Pub?lic)?(\s+Licen[cs]e)?(\s+\(?AGPL\)?)?")
226+
(def lgpl-re #"(?<lgpl>(GNU\s+(Genere?al\s+)?(Library\s+or\s+Lesser|Library|Lesser))|((Library\s+or\s+Lesser|Library|Lesser)\s+(GNU|GPL|Genere?al)|(L(esser\s)?\s*GPL)))(\s+Genere?al)?(\s+Pub?lic)?(\s+Licen[cs]e)?(\s+\(?L\s*GPL\)?)?")
227+
(def gpl-re #"(?<!(Affero|Lesser|Library)\s+)(?<gpl>GNU(?!\s+Classpath)|(?<!(L|A)\s*)GPL|Genere?al\s+Pub?lic\s+Licen[cs]e)(?!\s+(Affero|Library|Lesser|Genere?al\s+Lesser|Genere?al\s+Library|LGPL|AGPL))((\s+General)?(?!\s+(Affero|Lesser|Library))\s+Pub?lic\s+Licen[cs]e)?(\s+\(?GPL\)?)?")
227228
(def version-re #"[\s,-]*(_?V(ersion)?)?[\s\._]*(?<version>\d+([\._]\d+)?)?")
228229
(def only-or-later-re #"[\s,-]*((?<only>\(?only\)?)|(\(?or(\s+\(?at\s+your\s+(option|discretion)\)?)?(\s+any)?)?([\s-]*(?<orLater>lat[eo]r|newer|greater|\+)))?")
229230
(def gnu-re (lciu/re-concat "(?x)(?i)\\b(\n# Alternative 1: AGPL\n"

test/lice_comb/deps_test.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@
132132
(is (nil? (dep->expressions ['slipset/deps-deploy {:deps/manifest :mvn :mvn/version "0.2.0"}])))
133133
(is (nil? (dep->expressions ['borkdude/sci.impl.reflector {:deps/manifest :mvn :mvn/version "0.0.1"}]))))
134134
(testing "Valid deps - multi license"
135-
(is (valid= #{"EPL-1.0 OR LGPL-3.0-only"} (dep->expressions ['ch.qos.logback/logback-classic {:deps/manifest :mvn :mvn/version "1.2.7"}])))
136-
(is (valid= #{"EPL-1.0 OR LGPL-3.0-only"} (dep->expressions ['ch.qos.logback/logback-core {:deps/manifest :mvn :mvn/version "1.2.7"}])))
135+
(is (valid= #{"EPL-1.0 OR LGPL-2.0-or-later"} (dep->expressions ['ch.qos.logback/logback-classic {:deps/manifest :mvn :mvn/version "1.2.7"}])))
136+
(is (valid= #{"EPL-1.0 OR LGPL-2.0-or-later"} (dep->expressions ['ch.qos.logback/logback-core {:deps/manifest :mvn :mvn/version "1.2.7"}])))
137137
(is (valid= #{"CDDL-1.1 OR GPL-2.0-only WITH Classpath-exception-2.0"} (dep->expressions ['javax.mail/mail {:deps/manifest :mvn :mvn/version "1.4.7"}])))
138138
(is (valid= #{"Apache-2.0 OR LGPL-2.1-or-later"} (dep->expressions ['net.java.dev.jna/jna-platform {:deps/manifest :mvn :mvn/version "5.10.0"}])))
139139
(is (valid= #{"GPL-2.0-only WITH Classpath-exception-2.0 OR MIT"} (dep->expressions ['org.checkerframework/checker-compat-qual {:deps/manifest :mvn :mvn/version "2.5.5"}])))

0 commit comments

Comments
 (0)