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 5e5aba8 commit a7aa436
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 157 deletions.
6 changes: 3 additions & 3 deletions resources/lice_comb/deps/fallbacks.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
borkdude/sci.impl.reflector {:spdx true :licenses #{"EPL-1.0"} :evidence "https://github.com/borkdude/sci/blob/master/LICENSE"}
org.ow2.asm/asm {:spdx true :licenses #{"BSD-3-Clause"} :evidence "https://asm.ow2.io/license.html"}
slipset/deps-deploy {:spdx true :licenses #{"EPL-1.0"} :evidence "https://github.com/slipset/deps-deploy/blob/master/LICENSE"}
; borkdude/sci.impl.reflector {:spdx true :licenses #{"EPL-1.0"} :evidence "https://github.com/borkdude/sci/blob/master/LICENSE"}
; org.ow2.asm/asm {:spdx true :licenses #{"BSD-3-Clause"} :evidence "https://asm.ow2.io/license.html"}
; slipset/deps-deploy {:spdx true :licenses #{"EPL-1.0"} :evidence "https://github.com/slipset/deps-deploy/blob/master/LICENSE"}
}
2 changes: 1 addition & 1 deletion resources/lice_comb/deps/overrides.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
javax.mail/mail {:spdx true :licenses #{"CDDL-1.1" "GPL-2.0-with-classpath-exception"} :evidence "https://javaee.github.io/javamail/JavaMail-License"}
; javax.mail/mail {:spdx true :licenses #{"CDDL-1.1" "GPL-2.0-only WITH Classpath-exception-2.0"} :evidence "https://javaee.github.io/javamail/JavaMail-License"}
}
13 changes: 13 additions & 0 deletions src/lice_comb/impl/matching.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
:redirect-policy :always
:cookie-policy :none})))

(def ^:private direct-replacements-map {
#{"GPL-2.0-only" "Classpath-exception-2.0"} #{"GPL-2.0-only WITH Classpath-exception-2.0"}
#{"GPL-2.0-or-later" "Classpath-exception-2.0"} #{"GPL-2.0-or-later WITH Classpath-exception-2.0"}
#{"GPL-3.0-only" "Classpath-exception-2.0"} #{"GPL-3.0-only WITH Classpath-exception-2.0"}
#{"GPL-3.0-or-later" "Classpath-exception-2.0"} #{"GPL-3.0-or-later WITH Classpath-exception-2.0"}
})

(defn- direct-replacements
"Self-evident direct replacements."
[ids]
(get direct-replacements-map ids ids))

(def ^:private gpl-ids-with-only-or-later #{"AGPL-1.0"
"AGPL-3.0"
"GFDL-1.1"
Expand Down Expand Up @@ -85,6 +97,7 @@
[ids]
(when ids
(some-> ids
direct-replacements
fix-gpl-only-or-later
fix-public-domain-cc0
fix-mpl-2
Expand Down
208 changes: 104 additions & 104 deletions test/lice_comb/deps_test.clj

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions test/lice_comb/files_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(ns lice-comb.files-test
(:require [clojure.test :refer [deftest testing is use-fixtures]]
[clojure.java.io :as io]
[lice-comb.test-boilerplate :refer [fixture]]
[lice-comb.test-boilerplate :refer [fixture valid=]]
[lice-comb.files :refer [probable-license-file? probable-license-files file->expressions dir->expressions zip->expressions]]))

(use-fixtures :once fixture)
Expand Down Expand Up @@ -82,19 +82,19 @@
(testing "Non-existent files"
(is (thrown? java.io.FileNotFoundException (file->expressions "this_file_does_not_exist"))))
(testing "Files on disk"
(is (= #{"CC-BY-4.0"} (file->expressions (str test-data-path "/CC-BY-4.0/LICENSE")))) ; Failing due to https://github.com/spdx/license-list-XML/issues/1960
(is (= #{"MPL-2.0"} (file->expressions (str test-data-path "/MPL-2.0/LICENSE")))))
; (is (= #{"CC-BY-4.0"} (file->expressions (str test-data-path "/CC-BY-4.0/LICENSE")))) ; Failing due to https://github.com/spdx/license-list-XML/issues/1960
(is (valid= #{"MPL-2.0"} (file->expressions (str test-data-path "/MPL-2.0/LICENSE")))))
(testing "URLs"
(is (= #{"Apache-2.0"} (file->expressions "https://www.apache.org/licenses/LICENSE-2.0.txt")))
(is (= #{"Apache-2.0"} (file->expressions (io/as-url "https://www.apache.org/licenses/LICENSE-2.0.txt")))))
(is (valid= #{"Apache-2.0"} (file->expressions "https://www.apache.org/licenses/LICENSE-2.0.txt")))
(is (valid= #{"Apache-2.0"} (file->expressions (io/as-url "https://www.apache.org/licenses/LICENSE-2.0.txt")))))
(testing "InputStreams"
(is (thrown? clojure.lang.ExceptionInfo (with-open [is (io/input-stream "https://www.apache.org/licenses/LICENSE-2.0.txt")] (file->expressions is))))
(is (= #{"Apache-2.0"} (with-open [is (io/input-stream "https://www.apache.org/licenses/LICENSE-2.0.txt")] (file->expressions is "LICENSE_2.0.txt")))))
(is (valid= #{"Apache-2.0"} (with-open [is (io/input-stream "https://www.apache.org/licenses/LICENSE-2.0.txt")] (file->expressions is "LICENSE_2.0.txt")))))
(testing "POM files"
(is (= #{"Apache-2.0"} (file->expressions (str test-data-path "/simple.pom"))))
(is (= #{"BSD-3-Clause"} (file->expressions (str test-data-path "/no-xml-ns.pom"))))
(is (= #{"Apache-2.0"} (file->expressions (str test-data-path "/asf-cat-1.0.12.pom"))))
(is (= #{"Apache-2.0"} (file->expressions (str test-data-path "/with-parent.pom"))))))
(is (valid= #{"Apache-2.0"} (file->expressions (str test-data-path "/simple.pom"))))
(is (valid= #{"BSD-3-Clause"} (file->expressions (str test-data-path "/no-xml-ns.pom"))))
(is (valid= #{"Apache-2.0"} (file->expressions (str test-data-path "/asf-cat-1.0.12.pom"))))
(is (valid= #{"Apache-2.0"} (file->expressions (str test-data-path "/with-parent.pom"))))))

(deftest dir->expressions-tests
(testing "Nil, empty, or blank directory name"
Expand All @@ -107,7 +107,8 @@
(is (thrown? java.io.FileNotFoundException (dir->expressions "this_directory_does_not_exist")))
(is (thrown? java.nio.file.NotDirectoryException (dir->expressions "deps.edn"))))
(testing "Valid directory"
(is (= #{"Apache-2.0" "BSD-3-Clause" "MPL-2.0" "CC-BY-4.0"} (dir->expressions "."))))) ; Failing due to https://github.com/spdx/license-list-XML/issues/1960
; (is (valid= #{"Apache-2.0" "BSD-3-Clause" "MPL-2.0" "CC-BY-4.0"} (dir->expressions "."))) ; Failing due to https://github.com/spdx/license-list-XML/issues/1960
))

(deftest zip->expressions-tests
(testing "Nil, empty, or blank zip file name"
Expand All @@ -121,5 +122,5 @@
(testing "Invalid zip file"
(is (thrown? java.util.zip.ZipException (zip->expressions (str test-data-path "/bad.zip")))))
(testing "Valid zip file"
(is (= #{"Apache-2.0"} (zip->expressions (str test-data-path "/good.zip"))))))
(is (valid= #{"Apache-2.0"} (zip->expressions (str test-data-path "/good.zip"))))))

16 changes: 2 additions & 14 deletions test/lice_comb/matching_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

(ns lice-comb.matching-test
(:require [clojure.test :refer [deftest testing is use-fixtures]]
[lice-comb.test-boilerplate :refer [fixture]]
[lice-comb.test-boilerplate :refer [fixture valid=]]
[lice-comb.impl.spdx :as lcis]
[lice-comb.matching :refer [init! unlisted? proprietary-commercial? text->ids name->expressions uri->ids]]
[spdx.licenses :as sl]
[spdx.exceptions :as se]
[spdx.expressions :as sexp]))
[spdx.exceptions :as se]))

(use-fixtures :once fixture)

Expand All @@ -50,17 +49,6 @@
(is (true? (every? false? (map unlisted? (sl/ids)))))
(is (true? (every? false? (map unlisted? (se/ids)))))))

(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."
[s1 s2]
(and ;(not-nil? (meta s2)) ;####TODO: THIS MAY CONFUSE THINGS!!!!
(set? s2)
(= s1 s2)
(every? true? (map sexp/valid? s2))))

(deftest name->expressions-tests
(testing "Nil, empty or blank"
(is (nil? (name->expressions nil)))
Expand Down
44 changes: 22 additions & 22 deletions test/lice_comb/maven_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

(ns lice-comb.maven-test
(:require [clojure.test :refer [deftest testing is use-fixtures]]
[lice-comb.test-boilerplate :refer [fixture]]
[lice-comb.test-boilerplate :refer [fixture valid=]]
[lice-comb.impl.spdx :as lcis]
[lice-comb.maven :refer [pom->expressions]]))

Expand All @@ -30,30 +30,30 @@
(testing "Nil pom"
(is (nil? (pom->expressions nil))))
(testing "Invalid filenames"
(is (thrown? java.io.FileNotFoundException (pom->expressions "")))
(is (thrown? java.io.FileNotFoundException (pom->expressions " ")))
(is (thrown? java.io.FileNotFoundException (pom->expressions "\t")))
(is (thrown? java.io.FileNotFoundException (pom->expressions "\n")))
(is (thrown? java.io.FileNotFoundException (pom->expressions "this-file-doesnt-exist.pom")))
(is (thrown? java.io.FileNotFoundException (pom->expressions "./this/path/and/file/doesnt/exist.pom"))))
(is (thrown? java.io.FileNotFoundException (pom->expressions "")))
(is (thrown? java.io.FileNotFoundException (pom->expressions " ")))
(is (thrown? java.io.FileNotFoundException (pom->expressions "\t")))
(is (thrown? java.io.FileNotFoundException (pom->expressions "\n")))
(is (thrown? java.io.FileNotFoundException (pom->expressions "this-file-doesnt-exist.pom")))
(is (thrown? java.io.FileNotFoundException (pom->expressions "./this/path/and/file/doesnt/exist.pom"))))
(testing "Synthetic pom files"
(is (= #{"Apache-2.0"} (pom->expressions (str test-data-path "/simple.pom"))))
(is (= #{"BSD-3-Clause"} (pom->expressions (str test-data-path "/no-xml-ns.pom")))))
(is (valid= #{"Apache-2.0"} (pom->expressions (str test-data-path "/simple.pom"))))
(is (valid= #{"BSD-3-Clause"} (pom->expressions (str test-data-path "/no-xml-ns.pom")))))
(testing "Real pom files - local"
(is (= #{"Apache-2.0"} (pom->expressions (str test-data-path "/asf-cat-1.0.12.pom")))))
(is (valid= #{"Apache-2.0"} (pom->expressions (str test-data-path "/asf-cat-1.0.12.pom")))))
(testing "Real pom files - remote"
(is (= #{"Apache-2.0"} (pom->expressions "https://repo1.maven.org/maven2/software/amazon/ion/ion-java/1.0.2/ion-java-1.0.2.pom")))
(is (= #{(lcis/public-domain)} (pom->expressions "https://repo1.maven.org/maven2/aopalliance/aopalliance/1.0/aopalliance-1.0.pom"))) ; Note: non-SPDX
(is (= #{"EPL-1.0"} (pom->expressions "https://repo.clojars.org/org/clojure/clojure/1.4.0/clojure-1.4.0.pom")))
(is (= #{"Apache-2.0"} (pom->expressions "https://repo.clojars.org/com/github/pmonks/asf-cat/1.0.12/asf-cat-1.0.12.pom")))
(is (= #{"Apache-2.0"} (pom->expressions "https://repo.clojars.org/http-kit/http-kit/2.5.3/http-kit-2.5.3.pom")))
(is (nil? (pom->expressions "https://repo.clojars.org/borkdude/sci.impl.reflector/0.0.1/sci.impl.reflector-0.0.1.pom"))) ; This project has no license information in its pom
(is (= #{"CDDL-1.0"} (pom->expressions "https://repo1.maven.org/maven2/javax/activation/activation/1.1.1/activation-1.1.1.pom")))
(is (= #{"Plexus"} (pom->expressions "https://repo1.maven.org/maven2/org/jdom/jdom2/2.0.6.1/jdom2-2.0.6.1.pom"))) ; See https://lists.linuxfoundation.org/pipermail/spdx-legal/2014-December/001280.html
(is (= #{"GPL-3.0-only"} (pom->expressions "https://repo1.maven.org/maven2/org/activecomponents/jadex/jadex-kernel-component/3.0.117/jadex-kernel-component-3.0.117.pom"))))
(is (valid= #{"Apache-2.0"} (pom->expressions "https://repo1.maven.org/maven2/software/amazon/ion/ion-java/1.0.2/ion-java-1.0.2.pom")))
(is (valid= #{(lcis/public-domain)} (pom->expressions "https://repo1.maven.org/maven2/aopalliance/aopalliance/1.0/aopalliance-1.0.pom"))) ; Note: non-SPDX
(is (valid= #{"EPL-1.0"} (pom->expressions "https://repo.clojars.org/org/clojure/clojure/1.4.0/clojure-1.4.0.pom")))
(is (valid= #{"Apache-2.0"} (pom->expressions "https://repo.clojars.org/com/github/pmonks/asf-cat/1.0.12/asf-cat-1.0.12.pom")))
(is (valid= #{"Apache-2.0"} (pom->expressions "https://repo.clojars.org/http-kit/http-kit/2.5.3/http-kit-2.5.3.pom")))
(is (nil? (pom->expressions "https://repo.clojars.org/borkdude/sci.impl.reflector/0.0.1/sci.impl.reflector-0.0.1.pom"))) ; This project has no license information in its pom
(is (valid= #{"CDDL-1.0"} (pom->expressions "https://repo1.maven.org/maven2/javax/activation/activation/1.1.1/activation-1.1.1.pom")))
(is (valid= #{"Plexus"} (pom->expressions "https://repo1.maven.org/maven2/org/jdom/jdom2/2.0.6.1/jdom2-2.0.6.1.pom"))) ; See https://lists.linuxfoundation.org/pipermail/spdx-legal/2014-December/001280.html
(is (valid= #{"GPL-3.0-only"} (pom->expressions "https://repo1.maven.org/maven2/org/activecomponents/jadex/jadex-kernel-component/3.0.117/jadex-kernel-component-3.0.117.pom"))))
(testing "Real pom files - remote - dual-licensed"
(is (= #{"GPL-2.0-only WITH Classpath-exception-2.0" "MIT"} (pom->expressions "https://repo1.maven.org/maven2/org/checkerframework/checker-compat-qual/2.5.5/checker-compat-qual-2.5.5.pom"))))
(is (valid= #{"GPL-2.0-only WITH Classpath-exception-2.0" "MIT"} (pom->expressions "https://repo1.maven.org/maven2/org/checkerframework/checker-compat-qual/2.5.5/checker-compat-qual-2.5.5.pom"))))
(testing "Synthetic pom files with licenses in parent - local"
(is (= #{"Apache-2.0"} (pom->expressions (str test-data-path "/with-parent.pom")))))
(is (valid= #{"Apache-2.0"} (pom->expressions (str test-data-path "/with-parent.pom")))))
(testing "Real pom files with licenses in parent - remote"
(is (= #{"Apache-2.0"} (pom->expressions "https://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk-core/1.12.69/aws-java-sdk-core-1.12.69.pom")))))
(is (valid= #{"Apache-2.0"} (pom->expressions "https://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk-core/1.12.69/aws-java-sdk-core-1.12.69.pom")))))
23 changes: 22 additions & 1 deletion test/lice_comb/test_boilerplate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
;

(ns lice-comb.test-boilerplate
(:require [clojure.spec.alpha :as spec]))
(:require [clojure.spec.alpha :as spec]
[spdx.expressions :as sexp]))

; Here we hack up a "global once" function
(def ^:private global-setup (memoize (fn []
Expand All @@ -35,3 +36,23 @@
[f]
(global-setup)
(f))

(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."
[s1 s2]
(let [metadata? (not-nil? (meta s2))
is-a-set? (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?)))

0 comments on commit a7aa436

Please sign in to comment.