Skip to content

Commit

Permalink
Support for SPDX spec version 3
Browse files Browse the repository at this point in the history
This initial commit does not add any additional formats for version
three.  It merely updates the libraries to the latest which supports the
spec version 3 format.  It pass unit tests and has been tested with the
latest license list and passes.
  • Loading branch information
goneall committed Nov 25, 2024
1 parent f55028d commit f8292dc
Show file tree
Hide file tree
Showing 37 changed files with 3,544 additions and 1,662 deletions.
4,146 changes: 2,835 additions & 1,311 deletions LICENSE.spdx.json

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions Test/org/spdx/crossref/OsiApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,30 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.library.model.license.CrossRef;
import org.spdx.library.model.license.SpdxListedLicense;
import org.spdx.core.DefaultModelStore;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.ModelCopyManager;
import org.spdx.library.SpdxModelFactory;
import org.spdx.library.model.v2.license.CrossRef;
import org.spdx.library.model.v2.license.SpdxListedLicense;
import org.spdx.storage.simple.InMemSpdxStore;

/**
* @author Gary O'Neall
*
*/
public class OsiApiTest {

private static final String DOC_URI = "https://mydoc.uri";

/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
SpdxModelFactory.init();
DefaultModelStore.initialize(new InMemSpdxStore(), DOC_URI, new ModelCopyManager());

}

/**
Expand Down
19 changes: 13 additions & 6 deletions Test/org/spdx/licenselistpublisher/TestMarkdownTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.spdx.library.DefaultModelStore;
import org.spdx.library.model.license.LicenseException;
import org.spdx.library.model.license.SpdxListedLicense;
import org.spdx.core.DefaultModelStore;
import org.spdx.library.ModelCopyManager;
import org.spdx.library.SpdxModelFactory;
import org.spdx.library.model.v2.license.LicenseException;
import org.spdx.library.model.v2.license.ListedLicenseException;
import org.spdx.library.model.v2.license.SpdxListedLicense;
import org.spdx.storage.simple.InMemSpdxStore;

public class TestMarkdownTable {

private static final String DOC_URI = "https://mydoc.uri";

@Before
public void setUp() throws Exception {
DefaultModelStore.reset();
SpdxModelFactory.init();
DefaultModelStore.initialize(new InMemSpdxStore(), DOC_URI, new ModelCopyManager());
}

@After
Expand Down Expand Up @@ -48,12 +55,12 @@ public void test() throws Exception {
String name4 = "name4";
String id4 = "id4";
String text4 = "text4";
LicenseException ex1 = new LicenseException(id4, name4, text4);
LicenseException ex1 = new ListedLicenseException(id4, name4, text4);
md.addException(ex1, false);
String name5 = "name5";
String id5 = "id5";
String text5 = "text5";
LicenseException ex2 = new LicenseException(id5, name5, text5);
LicenseException ex2 = new ListedLicenseException(id5, name5, text5);
md.addException(ex2, false);
StringWriter result = new StringWriter();
md.writeTOC(result);
Expand Down
90 changes: 72 additions & 18 deletions Test/org/spdx/licensexml/LicenseXmlDocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,21 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.library.model.license.LicenseException;
import org.spdx.library.model.license.ListedLicenseException;
import org.spdx.library.model.license.SpdxListedLicense;
import org.spdx.core.IModelCopyManager;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.ModelCopyManager;
import org.spdx.library.SpdxModelFactory;
import org.spdx.library.model.v2.license.LicenseException;
import org.spdx.library.model.v2.license.SpdxListedLicense;
import org.spdx.library.model.v3_0_1.SpdxConstantsV3;
import org.spdx.library.model.v3_0_1.expandedlicensing.ListedLicense;
import org.spdx.library.model.v3_0_1.expandedlicensing.ListedLicenseException;
import org.spdx.licenseTemplate.InvalidLicenseTemplateException;
import org.spdx.licenselistpublisher.ListedExceptionContainer;
import org.spdx.licenselistpublisher.ListedLicenseContainer;
import org.spdx.licenselistpublisher.UnitTestHelper;
import org.spdx.storage.IModelStore;
import org.spdx.storage.simple.InMemSpdxStore;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -90,12 +99,19 @@ public class LicenseXmlDocumentTest {
private static final String AGPL3ONLY_FILE_PATH = "TestFiles" + File.separator + "AGPL-3.0-only.xml";
private static final String BSD_PROTECTION_FILE_PATH = "TestFiles" + File.separator + "BSD-Protection.xml";

private IModelStore v2ModelStore;
private IModelStore v3ModelStore;
private IModelCopyManager copyManager;

/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
SpdxModelFactory.init();
v2ModelStore = new InMemSpdxStore();
v3ModelStore = new InMemSpdxStore();
copyManager = new ModelCopyManager();
}

/**
Expand All @@ -112,7 +128,7 @@ public void tearDown() throws Exception {
public void testLicenseXmlDocumentFile() throws Exception {
File licenseFile = new File(TEST_FILE_PATH);
try {
new LicenseXmlDocument(licenseFile);
new LicenseXmlDocument(licenseFile, v2ModelStore, v3ModelStore, copyManager);
} catch(Exception ex) {
fail("Error creating XML document: "+ex.getMessage());
}
Expand All @@ -121,15 +137,23 @@ public void testLicenseXmlDocumentFile() throws Exception {
@Test
public void testOptionalAnnotations() throws Exception {
File licenseFile = new File(TEST_OPTIONAL_FILE_PATH);
LicenseXmlDocument licenseDoc = new LicenseXmlDocument(licenseFile);
SpdxListedLicense license = licenseDoc.getListedLicenses().get(0);
LicenseXmlDocument licenseDoc = new LicenseXmlDocument(licenseFile, v2ModelStore, v3ModelStore, copyManager);
SpdxListedLicense license = licenseDoc.getListedLicenses().get(0).getV2ListedLicense();
String[] lines = license.getLicenseText().split("\\n");
assertEquals(5, lines.length);
assertEquals("before optional Default optional text after optional.", lines[0]);
assertEquals("before optionalNone optional textafter optional.", lines[1]);
assertEquals("before optional Before optional textafter optional.", lines[2]);
assertEquals("before optionalAfter optional text after optional.", lines[3]);
assertEquals("before optional Both optional text after optional.", lines[4]);
ListedLicense v3License = licenseDoc.getListedLicenses().get(0).getV3ListedLicense();
lines = v3License.getLicenseText().split("\\n");
assertEquals(5, lines.length);
assertEquals("before optional Default optional text after optional.", lines[0]);
assertEquals("before optionalNone optional textafter optional.", lines[1]);
assertEquals("before optional Before optional textafter optional.", lines[2]);
assertEquals("before optionalAfter optional text after optional.", lines[3]);
assertEquals("before optional Both optional text after optional.", lines[4]);
}

/**
Expand All @@ -140,11 +164,14 @@ public void testOptionalAnnotations() throws Exception {
@Test
public void testGetListedLicense() throws LicenseXmlException, InvalidSPDXAnalysisException {
File licenseFile = new File(TEST_FILE_PATH);
LicenseXmlDocument doc = new LicenseXmlDocument(licenseFile);
List<SpdxListedLicense> licenses = doc.getListedLicenses();
LicenseXmlDocument doc = new LicenseXmlDocument(licenseFile, v2ModelStore, v3ModelStore, copyManager);
List<ListedLicenseContainer> licenses = doc.getListedLicenses();
assertEquals(2, licenses.size());
for (SpdxListedLicense license : licenses) {
for (ListedLicenseContainer licenseContainer : licenses) {
SpdxListedLicense license = licenseContainer.getV2ListedLicense();
ListedLicense v3License = licenseContainer.getV3ListedLicense();
if (license.isDeprecated()) {
assertTrue(v3License.getIsDeprecatedLicenseId().get());
assertEquals(TEST_DEP_LICENSE_VERSION,license.getDeprecatedVersion());
assertFalse(license.isOsiApproved());
assertEquals(TEST_DEP_LICENSE_COMMENT, license.getComment());
Expand All @@ -154,7 +181,18 @@ public void testGetListedLicense() throws LicenseXmlException, InvalidSPDXAnalys
assertTrue(UnitTestHelper.isCollectionsEqual(TEST_DEP_LICENSE_URLS, license.getSeeAlso()));
assertEquals(TEST_DEP_LICENSE_HEADER, license.getStandardLicenseHeader());
assertEquals(TEST_DEP_LICENSE_TEMPLATE, license.getStandardLicenseTemplate());

assertEquals(TEST_DEP_LICENSE_VERSION,v3License.getDeprecatedVersion().get());
assertFalse(v3License.getIsOsiApproved().get());
assertEquals(TEST_DEP_LICENSE_COMMENT, v3License.getComment().get());
assertEquals(SpdxConstantsV3.SPDX_LISTED_LICENSE_NAMESPACE + TEST_DEP_LICENSE_ID, v3License.getObjectUri());
assertEquals(TEST_DEP_LICENSE_TEXT, v3License.getLicenseText());
assertEquals(TEST_DEP_LICENSE_NAME, v3License.getName().get());
assertTrue(UnitTestHelper.isCollectionsEqual(TEST_DEP_LICENSE_URLS, v3License.getSeeAlsos()));
assertEquals(TEST_DEP_LICENSE_HEADER, v3License.getStandardLicenseHeader().get());
assertEquals(TEST_DEP_LICENSE_TEMPLATE, v3License.getStandardLicenseTemplate().get());
} else {
assertFalse(v3License.getIsDeprecatedLicenseId().get());
assertTrue(license.isOsiApproved());
assertEquals(TEST_LICENSE_COMMENT, license.getComment());
assertEquals(TEST_LICENSE_ID, license.getLicenseId());
Expand All @@ -164,6 +202,15 @@ public void testGetListedLicense() throws LicenseXmlException, InvalidSPDXAnalys
assertEquals(TEST_LICENSE_HEADER, license.getStandardLicenseHeader());
assertEquals(TEST_LICENSE_HEADER_TEMPLATE, license.getStandardLicenseHeaderTemplate());
assertEquals(TEST_LICENSE_TEMPLATE, license.getStandardLicenseTemplate());

assertTrue(v3License.getIsOsiApproved().get());
assertEquals(TEST_LICENSE_COMMENT, v3License.getComment().get());
assertEquals(SpdxConstantsV3.SPDX_LISTED_LICENSE_NAMESPACE + TEST_LICENSE_ID, v3License.getObjectUri());
assertEquals(TEST_LICENSE_TEXT, v3License.getLicenseText());
assertEquals(TEST_LICENSE_NAME, v3License.getName().get());
assertTrue(UnitTestHelper.isCollectionsEqual(TEST_LICENSE_URLS, v3License.getSeeAlsos()));
assertEquals(TEST_LICENSE_HEADER, v3License.getStandardLicenseHeader().get());
assertEquals(TEST_LICENSE_TEMPLATE, v3License.getStandardLicenseTemplate().get());
}
}
}
Expand All @@ -176,15 +223,22 @@ public void testGetListedLicense() throws LicenseXmlException, InvalidSPDXAnalys
@Test
public void testGetLicenseException() throws LicenseXmlException, InvalidSPDXAnalysisException {
File licenseFile = new File(TEST_FILE_PATH);
LicenseXmlDocument doc = new LicenseXmlDocument(licenseFile);
List<ListedLicenseException> exceptions = doc.getLicenseExceptions();
LicenseXmlDocument doc = new LicenseXmlDocument(licenseFile, v2ModelStore, v3ModelStore, copyManager);
List<ListedExceptionContainer> exceptions = doc.getLicenseExceptions();
assertEquals(1, exceptions.size());
LicenseException exception = exceptions.get(0);
LicenseException exception = exceptions.get(0).getV2Exception();
ListedLicenseException v3Exception = exceptions.get(0).getV3Exception();
assertEquals(TEST_EXCEPTION_COMMENT, exception.getComment());
assertEquals(TEST_EXCEPTION_ID, exception.getLicenseExceptionId());
assertEquals(TEST_EXCEPTION_TEXT, exception.getLicenseExceptionText());
assertEquals(TEST_EXCEPTION_NAME, exception.getName());
assertTrue(UnitTestHelper.isCollectionsEqual(TEST_EXCEPTION_URLS, exception.getSeeAlso()));

assertEquals(TEST_EXCEPTION_COMMENT, v3Exception.getComment().get());
assertEquals(SpdxConstantsV3.SPDX_LISTED_LICENSE_NAMESPACE + TEST_EXCEPTION_ID, v3Exception.getObjectUri());
assertEquals(TEST_EXCEPTION_TEXT, v3Exception.getAdditionText());
assertEquals(TEST_EXCEPTION_NAME, v3Exception.getName().get());
assertTrue(UnitTestHelper.isCollectionsEqual(TEST_EXCEPTION_URLS, v3Exception.getSeeAlsos()));
}

@Test
Expand All @@ -200,18 +254,18 @@ public void testParserBehavior() throws ParserConfigurationException, SAXExcepti
@Test
public void testRegressionAgpl3Only() throws LicenseXmlException, InvalidSPDXAnalysisException, InvalidLicenseTemplateException {
File licenseFile = new File(AGPL3ONLY_FILE_PATH);
LicenseXmlDocument doc = new LicenseXmlDocument(licenseFile);
List<SpdxListedLicense> licenses = doc.getListedLicenses();
LicenseXmlDocument doc = new LicenseXmlDocument(licenseFile, v2ModelStore, v3ModelStore, copyManager);
List<ListedLicenseContainer> licenses = doc.getListedLicenses();
assertEquals(1, licenses.size());
}

@Test
public void testRegressionBsdProtection() throws LicenseXmlException, InvalidSPDXAnalysisException, InvalidLicenseTemplateException {
File licenseFile = new File(BSD_PROTECTION_FILE_PATH);
LicenseXmlDocument doc = new LicenseXmlDocument(licenseFile);
List<SpdxListedLicense> licenses = doc.getListedLicenses();
LicenseXmlDocument doc = new LicenseXmlDocument(licenseFile, v2ModelStore, v3ModelStore, copyManager);
List<ListedLicenseContainer> licenses = doc.getListedLicenses();
assertEquals(1, licenses.size());
SpdxListedLicense result = licenses.get(0);
SpdxListedLicense result = licenses.get(0).getV2ListedLicense();
String template = result.getStandardLicenseTemplate();
Pattern matchingModificationLine = Pattern.compile("<<beginOptional>>\\s?----------------------------------------------------------------<<endOptional>>",Pattern.MULTILINE);
assertTrue(matchingModificationLine.matcher(template).find());
Expand Down
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<dependency>
<groupId>org.spdx</groupId>
<artifactId>java-spdx-library</artifactId>
<version>1.1.10</version>
<version>2.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
Expand All @@ -88,7 +88,7 @@
<dependency>
<groupId>org.spdx</groupId>
<artifactId>spdx-rdf-store</artifactId>
<version>1.1.9</version>
<version>2.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
Expand All @@ -100,6 +100,11 @@
<artifactId>commons-io</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>org.spdx</groupId>
<artifactId>spdx-v3jsonld-store</artifactId>
<version>0.1.1-SNAPSHOT</version>
</dependency>
</dependencies>
<profiles>
<profile>
Expand Down Expand Up @@ -286,7 +291,7 @@
<plugin>
<groupId>org.spdx</groupId>
<artifactId>spdx-maven-plugin</artifactId>
<version>0.6.4</version>
<version>0.7.3</version>
<executions>
<execution>
<id>build-spdx</id>
Expand Down
6 changes: 3 additions & 3 deletions src/org/spdx/crossref/CrossRefHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.library.model.license.CrossRef;
import org.spdx.library.model.license.SpdxListedLicense;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.model.v2.license.CrossRef;
import org.spdx.library.model.v2.license.SpdxListedLicense;

/**
* Helper class that provides details for each url in the array it receives
Expand Down
6 changes: 4 additions & 2 deletions src/org/spdx/crossref/Live.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.net.HttpURLConnection;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.concurrent.Callable;

import org.slf4j.Logger;
Expand Down Expand Up @@ -54,8 +55,9 @@ public static boolean urlLinkExists(String URLName){
int responseCode = con.getResponseCode();
return (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_NOT_MODIFIED
|| responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
}
catch (Exception e) {
} catch (UnknownHostException e) {
return false;
} catch (Exception e) {
logger.warn("Failed checking live status.",e.getMessage());
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/spdx/crossref/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.jsoup.nodes.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spdx.library.model.license.SpdxListedLicense;
import org.spdx.library.model.v2.license.SpdxListedLicense;
import org.spdx.utility.compare.LicenseCompareHelper;

public class Match implements Callable<String> {
Expand Down
6 changes: 3 additions & 3 deletions src/org/spdx/crossref/OsiApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.library.model.license.CrossRef;
import org.spdx.library.model.license.SpdxListedLicense;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.model.v2.license.CrossRef;
import org.spdx.library.model.v2.license.SpdxListedLicense;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
Expand Down
5 changes: 3 additions & 2 deletions src/org/spdx/crossref/Timestamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.time.format.DateTimeFormatter;
import java.util.concurrent.Callable;

import org.spdx.library.SpdxConstants;
import org.spdx.library.model.v2.SpdxConstantsCompatV2;


/**
* Gets the current timestamp, to be added to the url details
Expand All @@ -36,7 +37,7 @@ public class Timestamp implements Callable<String> {
*/
public static String getTimestamp(){
// Get current timestamp
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(SpdxConstants.SPDX_DATE_FORMAT);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(SpdxConstantsCompatV2.SPDX_DATE_FORMAT);
String timeStamp = ZonedDateTime.now( ZoneOffset.UTC ).format( formatter );
return timeStamp.toString();
}
Expand Down
4 changes: 2 additions & 2 deletions src/org/spdx/htmltemplates/ExceptionHtml.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import java.util.List;
import java.util.Map;

import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.library.model.license.ListedLicenseException;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.model.v2.license.ListedLicenseException;
import org.spdx.licenseTemplate.InvalidLicenseTemplateException;

import com.github.mustachejava.DefaultMustacheFactory;
Expand Down
4 changes: 2 additions & 2 deletions src/org/spdx/htmltemplates/ExceptionHtmlToc.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.Map;

import org.apache.commons.lang3.StringEscapeUtils;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.library.model.license.LicenseException;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.model.v2.license.LicenseException;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
Expand Down
Loading

0 comments on commit f8292dc

Please # to comment.