https://github.com/aschet/spdx-license-expression-tools
A library that provides various operations for SPDX license expressions.
https://github.com/aschet/spdx-license-expression-tools
simplification spdx spdx-license
Last synced: 5 months ago
JSON representation
A library that provides various operations for SPDX license expressions.
- Host: GitHub
- URL: https://github.com/aschet/spdx-license-expression-tools
- Owner: aschet
- License: apache-2.0
- Created: 2017-04-14T21:12:16.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-03-09T23:37:04.000Z (about 5 years ago)
- Last Synced: 2025-07-12T13:47:28.011Z (11 months ago)
- Topics: simplification, spdx, spdx-license
- Language: Java
- Size: 31.3 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# spdx-license-expression-tools
The [SPDX specification](https://spdx.org/spdx-specification-21-web-version) was created to exchange licensing information along a software supply chain in a standard way. Part of this specification are license expressions which can be used to describe the licensing of a software in a formal way e.g. `(LGPL-3.0 OR MIT)`.
Within the [SPDX tools](https://github.com/spdx/tools), the official specification implementation of the SPDX working group, license expressions are represented as `AnyLicenseInfo` composite. Interacting with this composite can be quite complicated, therefore the spdx-license-expression-tools Java library was created to provide various operations that can be performed on SPDX license expressions:
- simplification
- filtering
- merging
- splitting
## Operations
### Simplification
Removing of redundant terms and transforming license expressions to the distributed normal form (DNF):
```java
AnyLicenseInfo expression = LicenseInfoFactory.parseSPDXLicenseString("(((LGPL-3.0+ OR MIT) AND GPL-2.0) OR BSD-3-Clause)");
ExpressionSimplification.simplify(expression); // -> (BSD-3-Clause OR (LGPL-3.0+ AND GPL-2.0) OR (MIT AND GPL-2.0))
```
### Filtering
Removing of operators:
```java
AnyLicenseInfo expression = LicenseInfoFactory.parseSPDXLicenseString("LGPL-3.0+ WITH DigiRule-FOSS-exception AND MIT");
ExpressionFiltering.filterOperators(expression, OperatorFilter.FILTER_ALL); // -> (LGPL-3.0 AND MIT)
```
Removing of licenses:
```java
AnyLicenseInfo expression = LicenseInfoFactory.parseSPDXLicenseString("((LGPL-3.0+ AND MIT) AND BSD-3-Clause)");
LicenseMatcher matcher = ExpressionFiltering.createLicenseMatcher();
matcher.setLicense(LicenseInfoFactory.parseSPDXLicenseString("LGPL-3.0+"));
ExpressionFiltering.filterLicenses(expression, matcher); // -> (MIT AND BSD-3-Clause)
```
### Merging
Joining with `AND`:
```java
AnyLicenseInfo expression1 = LicenseInfoFactory.parseSPDXLicenseString("LGPL-3.0+ AND MIT");
AnyLicenseInfo expression2 = LicenseInfoFactory.parseSPDXLicenseString("BSD-3-Clause");
ExpressionMerging.andJoin(expression1, expression2); // -> ((LGPL-3.0+ AND MIT) AND BSD-3-Clause)
```
Joining with `OR`:
```java
AnyLicenseInfo expression1 = LicenseInfoFactory.parseSPDXLicenseString("LGPL-3.0+ AND MIT");
AnyLicenseInfo expression2 = LicenseInfoFactory.parseSPDXLicenseString("BSD-3-Clause");
ExpressionMerging.orJoin(expression1, expression2); // -> ((LGPL-3.0+ AND MIT) OR BSD-3-Clause)
```
### Splitting
Splitting to conjunctive sets (after simplification):
```java
AnyLicenseInfo expression = LicenseInfoFactory.parseSPDXLicenseString("(((LGPL-3.0+ OR MIT) AND GPL-2.0) OR BSD-3-Clause)");
ExpressionSplitting.splitToConjunctiveSets(expression); // -> BSD-3-Clause, (LGPL-3.0+ AND GPL-2.0), (MIT AND GPL-2.0)
```
Splitting to licenses (list of contents):
```java
AnyLicenseInfo expression = LicenseInfoFactory.parseSPDXLicenseString("(((LGPL-3.0+ OR MIT) AND GPL-2.0) OR BSD-3-Clause)");
ExpressionSplitting.splitToLicenses(expression); // -> BSD-3-Clause, LGPL-3.0+, GPL-2.0, MIT
```
## Compiling and Integration
Maven is used as build system. To build from source use:
```
mvn package
```
spdx-license-expression-tools is available via the Maven Central Repository:
```
com.github.aschet
spdx-license-expression-tools
1.1.0
```