Skip to content

Commit

Permalink
🚧 Ongoing work on issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
pmonks committed Sep 2, 2023
1 parent a7aa436 commit 5d28afc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
14 changes: 0 additions & 14 deletions src/lice_comb/impl/matching.clj
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,6 @@
(catch Exception _
nil))))

; TODO: THIS MAY BE UNNECESSARY AND IF SO SHOULD BE REMOVED
(comment
(defn listed-name->ids
"Returns the SPDX license and/or exception identifier(s) (a set) for
the given license name (matched case insensitively), or nil if there
aren't any.
Note that SPDX license names are not guaranteed to be unique - see
https://github.com/spdx/license-list-XML/blob/main/DOCS/license-fields.md"
[name]
(when-not (s/blank? name)
(get @lcis/index-name-to-id-d (s/trim (s/lower-case name)))))
)

(defn uri->ids
"Returns the SPDX license and/or exception identifiers (a set) for the given
uri, or nil if there aren't any. It does this via two steps:
Expand Down
15 changes: 10 additions & 5 deletions src/lice_comb/maven.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"Functionality related to finding and determining license information from
Maven POMs."
(:require [clojure.string :as s]
[clojure.set :as set]
[clojure.java.io :as io]
[clojure.data.xml :as xml]
[clojure.java.shell :as sh]
Expand Down Expand Up @@ -70,18 +71,22 @@
(.toURI local-pom)
(first (filter uri-resolves? (map #(java.net.URI. (str % "/" gav-path)) remote-maven-repos))))))))

;####TODO: Check both URI and name and merge the results!
(defn- licenses-from-pair
"Attempts to determine the license(s) (a set) from a POM license name/URL pair.
The result has metadata attached that describes how the identifiers in the
expression(s) were determined."
[{:keys [name url]}]
; Attempt to find a match from the name first
(if-let [expressions (lcmtch/name->expressions name)]
expressions
; Then match by url
(lcmtch/uri->ids url)))
(let [name-expressions (lcmtch/name->expressions name)]
(if (every? lcmtch/unlisted? name-expressions)
; If all we got were unlisted expressions from the name, try the URI
(let [uri-expressions (lcmtch/uri->ids url)]
(if (every? lcmtch/unlisted? uri-expressions)
; Neither worked, so just return all of the unlisted placeholders
(set/union name-expressions uri-expressions) ;####TODO: MERGE METADATA!!!!
uri-expressions))
name-expressions)))

(xml/alias-uri 'pom "http://maven.apache.org/POM/4.0.0")

Expand Down
36 changes: 22 additions & 14 deletions test/lice_comb/test_boilerplate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,27 @@
(def not-nil? (complement nil?))

(defn valid=
"Returns true if all of the SPDX exceptions in s2 are valid, and also
that s1 equals s2."
"Returns true if all of the following are true:
* s2 has metadata
* s2 is a set
* s2 is equal to s1
* every entry in s2 is a valid SPDX license expression
Also prints (to stdout) which of the above is not true, in the event that any
of them are not true."
[s1 s2]
(let [metadata? (not-nil? (meta s2))
is-a-set? (set? s2)
(let [metadata? (or (nil? s2) (not-nil? (meta s2)))
is-a-set? (or (nil? s2) (set? s2))
is-equal? (= s1 s2)
all-valid-expressions? (every? true? (map sexp/valid? s2))]
(when-not metadata? (println "☔️ Missing metadata"))
(when-not is-a-set? (println "☔️ Not a set"))
(when-not is-equal? (println "☔️ Not equal to expected value"))
(when-not all-valid-expressions? (println "☔️ Not all valid SPDX expressions"))
(and metadata?
is-a-set?
is-equal?
all-valid-expressions?)))

all-valid-expressions? (every? true? (map sexp/valid? s2))
result (and metadata?
is-a-set?
is-equal?
all-valid-expressions?)]
; Yes print here is deliberate, to ensure the output lines are grouped with the associated test failure message
(when-not result (print "\n☔️☔️☔️ Invalid result produced:"))
(when-not metadata? (print "\n* Missing metadata"))
(when-not is-a-set? (print "\n* Not a set"))
(when-not is-equal? (print "\n* Not equal to expected value"))
(when-not all-valid-expressions? (print "\n* Not all valid SPDX expressions"))
result))

0 comments on commit 5d28afc

Please sign in to comment.