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

Addresses issue 3 #23

Merged
merged 37 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
62de344
:new: Add nvd directory to ignore list
pmonks May 2, 2023
d9926f3
:books: Add note about upgrading to 2.0
pmonks May 3, 2023
0adf2ad
:arrow_up: Upgrade dependency
pmonks May 3, 2023
49be3a6
:construction: WIP commit
pmonks May 3, 2023
dc09fd6
:arrow_up: Upgrade dependencies
pmonks May 31, 2023
e7d3147
:construction: WIP commit while I switch to issue 20
pmonks Jun 2, 2023
749e17f
Merge branch 'dev' into issue-3
pmonks Jun 6, 2023
5e51290
Merge branch 'dev' into issue-3
pmonks Jun 14, 2023
37bae30
:construction: Migration to clj-spdx and fix fallout WIP
pmonks Jun 29, 2023
4bd9bbb
:construction: Add 579 license names obtained from pom.xml files on C…
pmonks Jul 14, 2023
82eef19
:fire: Delete accidentally added file
pmonks Jul 14, 2023
3660655
Merge branch 'main' into issue-3
pmonks Aug 1, 2023
d321836
:construction: Ongoing work on issue #3
pmonks Aug 1, 2023
9868d9f
:arrow_up: Add new dependencies and upgrade others
pmonks Aug 13, 2023
90656db
:construction: Ongoing work on issue #3
pmonks Aug 13, 2023
d8a54f0
:construction: Ongoing work on issue #3
pmonks Aug 18, 2023
eb41e92
:construction: Ongoing work on issue #3
pmonks Sep 1, 2023
5e5aba8
:construction: Ongoing work on issue #3
pmonks Sep 2, 2023
a7aa436
:construction: Ongoing work on issue #3
pmonks Sep 2, 2023
5d28afc
:construction: Ongoing work on issue #3
pmonks Sep 2, 2023
b418073
:construction: Ongoing work on issue #3
pmonks Sep 3, 2023
fce6fa2
:construction: Ongoing work on issue #3
pmonks Sep 3, 2023
8885937
:construction: Ongoing work on issue #3
pmonks Sep 4, 2023
5fdbe78
:construction: Ongoing work on issue #3
pmonks Sep 4, 2023
498eb5c
:construction: Ongoing work on issue #3
pmonks Sep 5, 2023
2a6aaf0
:arrow_up: Upgrade dependencies
pmonks Sep 5, 2023
645ed1c
:construction: Ongoing work on issue #3
pmonks Sep 6, 2023
086a85c
:construction: Ongoing work on issue #3
pmonks Sep 6, 2023
ed72a62
:books: Add demo section to readme
pmonks Sep 6, 2023
75bd5a7
:arrow_up: Upgrade dependencies
pmonks Sep 6, 2023
d7bed89
:construction: Ongoing work on issue #3
pmonks Sep 7, 2023
194ac22
:construction: Ongoing work on issue #3
pmonks Sep 8, 2023
ebc44be
:books: Updates to demo
pmonks Sep 8, 2023
82847fb
:art: Clean up fn names and locations and docstrings
pmonks Sep 8, 2023
f5db753
:books: Fix formatting
pmonks Sep 8, 2023
21cb69c
:arrow_up: Upgrade dependencies
pmonks Sep 8, 2023
787dc84
:art: More tweaks
pmonks Sep 9, 2023
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
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE/Invalid_id_constructed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: 🐛 Invalid SPDX identifier constructed
about: When the library constructs an invalid SPDX identifier. 😢

---

## `lice-comb` API(s) you were calling, if known:

_e.g. `lice-comb.deps/deps-licenses`_

## Input data that you provided to that API:

_e.g. a license name, or the URI of a file containing the license text, or the `tools.deps` coordinate of the dependency, etc._
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- uses: DeLaGuardo/setup-clojure@11.0
- uses: DeLaGuardo/setup-clojure@12.1
with:
cli: latest
- uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
container:
image: uochan/antq
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: java -jar /tmp/antq/antq.jar --skip=pom --error-format="::error file={{file}}::{{message}}"
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
environment: clojars

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Make sure we get the full history, or else the version number gets screwed up
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- uses: DeLaGuardo/setup-clojure@11.0
- uses: DeLaGuardo/setup-clojure@12.1
with:
cli: latest
- uses: actions/cache@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- uses: DeLaGuardo/setup-clojure@11.0
- uses: DeLaGuardo/setup-clojure@12.1
with:
cli: latest
- uses: actions/cache@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.nvd
*.iml
pom.xml
pom.xml.asc
Expand Down
4 changes: 4 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lice-comb
Copyright © 2021 Peter Monks (https://github.com/pmonks)

This project contains source code for rdrop-while, which is copyright Joshua Suskalo (https://github.com/IGJoshua) 2023 and licensed as "CC0-1.0 OR MIT". For details, see https://discord.com/channels/729136623421227082/732641743723298877/1141786961875583097.
128 changes: 113 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,134 @@

# lice-comb

A Clojure library for software license detection. It does this by combing through text, files, and even entire directory structures, and attempting to detect what license(s) they contain.
A Clojure library for software *lice*nse detection. It does this by *comb*ing through tools.deps and Leiningen dependencies, directory structures, and JAR & ZIP files, attempting to detect what license(s) they contain, and then normalising them into [SPDX license expression(s)](https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions/).

This library leverages, and is inspired by, the *excellent* [SPDX project](https://spdx.dev/). It's a great shame that it doesn't have greater traction in the Java & Clojure (and wider open source) communities. If you're new to SPDX and would prefer to read a primer rather than dry specification documents, I can thoroughly recommend [David A. Wheeler's SPDX Tutorial](https://github.com/david-a-wheeler/spdx-tutorial#spdx-tutorial).

## Using the library
## System Requirements

### Documentation
* `lice-comb` (all versions) requires an internet connection.

[API documentation is available here](https://pmonks.github.io/lice-comb/).
* `lice-comb` (all versions) assumes Maven is installed and in the `PATH` (but has fallback logic if it isn't available).

[An FAQ is available here](https://github.com/pmonks/lice-comb/wiki/FAQ).
* `lice-comb` (v2.0+) requires JDK 11 or higher.

## Installation

`lice-comb` is available as a Maven artifact from [Clojars](https://clojars.org/com.github.pmonks/lice-comb).

### Trying it Out

#### Clojure CLI

### Dependency
```shell
$ # Where #.#.# is replaced with an actual version number (see badge above)
$ clj -Sdeps '{:deps {com.github.pmonks/lice-comb {:mvn/version "#.#.#"}}}'
```

#### Leiningen

```shell
$ lein try com.github.pmonks/lice-comb
```

Express the correct maven dependencies in your `deps.edn`:
#### deps-try

```edn
{:deps {com.github.pmonks/lice-comb {:mvn/version "LATEST_CLOJARS_VERSION"}}}
```shell
$ deps-try com.github.pmonks/lice-comb
```

### Require one or more of the namespaces
### Demo

```clojure
(ns your.ns
(:require [lice-comb.deps :as lcd]
[lice-comb.files :as lcf]
[lice-comb.maven :as lcm]
[lice-comb.spdx :as lcs]))
;; License name, uri and full text matching
(require '[lice-comb.matching :as lcm])

; Initialise the matching namespace
; Notes:
; 1. This is slow (takes ~1 minute on my laptop), almost all of which is Spdx-Java-Library's initialisation (see https://github.com/spdx/Spdx-Java-Library/issues/193)
; 2. This step is optional, though initialisation will still happen regardless, and when it does you'll incur the same cost
(lcm/init!)

(lcm/name->expressions "Apache")
;=> #{"Apache-2.0"}

(lcm/name->expressions "GNU Public License 2.0 w/ the GNU Classpath Exception")
;=> #{"GPL-2.0-only WITH Classpath-exception-2.0"}

(lcm/text->ids (slurp "https://www.apache.org/licenses/LICENSE-2.0.txt"))
;=> #{"Apache-2.0"}

(lcm/uri->ids "https://www.apache.org/licenses/LICENSE-2.0.txt")
;=> #{"Apache-2.0"}

;; License extraction from Maven poms, including ones that aren't locally downloaded
(require '[lice-comb.maven :as lcmvn])

(lcmvn/pom->expressions (str (System/getProperty "user.home") "/.m2/repository/org/clojure/clojure/1.11.1/clojure-1.11.1.pom"))
;=> #{"EPL-1.0"}

(lcmvn/pom->expressions "https://repo1.maven.org/maven2/org/springframework/spring-core/6.0.11/spring-core-6.0.11.pom")
;=> #{"Apache-2.0"}

;; License extraction from tools.deps dependency maps
(require '[lice-comb.deps :as lcd])

(lcd/dep->expressions ['org.clojure/clojure {:deps/manifest :mvn :mvn/version "1.11.1"}])
;=> #{"EPL-1.0"}

;; Information about matches (useful for better understanding how lice-comb arrived at a given set of expressions, and
;; how confident it is in the values it's providing)
(lcm/name->expressions-info "Apache-2.0")
;=> {"Apache-2.0" ({:type :declared, :strategy :spdx-expression, :source ("Apache-2.0")})}

(lcm/name->expressions-info "GNU Public License 2.0 or later w/ the GNU Classpath Exception")
;=> {"GPL-2.0-or-later WITH Classpath-exception-2.0"
; ({:type :concluded, :confidence :low, :strategy :expression-inference, :source ("GNU Public License 2.0 or later w/ the GNU Classpath Exception")}
; {:id "GPL-2.0-or-later", :type :concluded, :confidence :medium, :strategy :regex-matching, :source ("GNU Public License 2.0 or later w/ the GNU Classpath Exception"
; "GNU Public License 2.0 or later")}
; {:id "Classpath-exception-2.0", :type :concluded, :confidence :low, :strategy :regex-matching, :source ("GNU Public License 2.0 or later w/ the GNU Classpath Exception"
; "the GNU Classpath Exception"
; "Classpath Exception")})}

(lcmvn/pom->expressions-info "https://repo.clojars.org/canvas/canvas/0.1.6/canvas-0.1.6.pom")
;=> {"EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
; ({:type :declared, :strategy :spdx-expression, :source ("https://repo.clojars.org/canvas/canvas/0.1.6/canvas-0.1.6.pom"
; "<name>"
; "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0")})}

;; Pretty print expressions-info
(require '[lice-comb.utils :as lcu])

(println (lcu/expressions-info->string (lcd/dep->expressions-info ['com.amazonaws/aws-java-sdk-s3 {:deps/manifest :mvn :mvn/version "1.12.129"}])))
;=> Apache-2.0:
; Concluded
; Confidence: high
; Strategy: regular expression matching
; Source:
; > com.amazonaws/[email protected]
; > https://repo.maven.apache.org/maven2/com/amazonaws/aws-java-sdk-s3/1.12.129/aws-java-sdk-s3-1.12.129.pom
; > https://repo.maven.apache.org/maven2/com/amazonaws/aws-java-sdk-pom/1.12.129/aws-java-sdk-pom-1.12.129.pom
; > <name>
; > Apache License, Version 2.0
nil
```

### API Documentation

[API documentation is available here](https://pmonks.github.io/lice-comb/), or [here on cljdoc](https://cljdoc.org/d/com.github.pmonks/lice-comb/).

[An FAQ is available here](https://github.com/pmonks/lice-comb/wiki/FAQ).

## Upgrading

### 1.x -> 2.x

The implementation of [issue #3](https://github.com/pmonks/lice-comb/issues/3) resulted in a number of unavoidable breaking changes, including:

* A wholesale change from returning sets of SPDX identifiers to returning sets of SPDX expressions
* The creation of [a dedicated SPDX-specific library (`clj-spdx`)](https://github.com/pmonks/clj-spdx) that leverages [the official SPDX Java library](https://github.com/spdx/Spdx-Java-Library)

## Contributor Information

[Contributor FAQ](https://github.com/pmonks/lice-comb/wiki/FAQ#contributor-faqs)
Expand Down
14 changes: 9 additions & 5 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
{:paths ["src" "resources"]
:deps
{org.clojure/tools.logging {:mvn/version "1.2.4"}
commons-validator/commons-validator {:mvn/version "1.7"}
org.clojure/data.xml {:mvn/version "0.2.0-alpha8"}
cheshire/cheshire {:mvn/version "5.11.0"}
clj-xml-validation/clj-xml-validation {:mvn/version "1.0.2"}
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}
tolitius/xml-in {:mvn/version "0.1.1"}}
tolitius/xml-in {:mvn/version "0.1.1"}
hato/hato {:mvn/version "0.9.0"}
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/rencg {:mvn/version "1.0.34"}}
:aliases
{:build {:deps {io.github.clojure/tools.build {:git/tag "v0.9.4" :git/sha "76b78fe"}
com.github.pmonks/pbr {:mvn/version "RELEASE"}}
{:build {:deps {com.github.pmonks/pbr {:mvn/version "RELEASE"}}
:ns-default pbr.build}}}
2 changes: 1 addition & 1 deletion pbr.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(def lib 'com.github.pmonks/lice-comb)

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

(defn set-opts
[opts]
Expand Down
8 changes: 8 additions & 0 deletions resources/lice_comb/names.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; Map of name values seen in the wild that are too ambiguous / cursed to support any reasonable form of automated parsing
{
; Seen in https://repo.maven.apache.org/maven2/com/sun/mail/all/1.4.7/all-1.4.7.pom
"GPLv2+CE" {"GPL-2.0-only WITH Classpath-exception-2.0"
({:type :concluded :confidence :high :strategy :manual-verification :source ("GPLv2+CE")}
{:id "GPL-2.0-only" :type :concluded :confidence :high :strategy :manual-verification :source ("GPLv2+CE" "GPLv2")}
{:id "Classpath-exception-2.0" :type :concluded :confidence :high :strategy :manual-verification :source ("GPLv2+CE" "CE")})}
}
27 changes: 0 additions & 27 deletions src/lice_comb/data.clj

This file was deleted.

Loading