An open API service indexing awesome lists of open source software.

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.

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

```