Skip to content

Commit

Permalink
Make copyrights variable text and implment spacing for optional eleme…
Browse files Browse the repository at this point in the history
…nt tags

Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
  • Loading branch information
goneall committed Jul 2, 2019
1 parent 787c9fd commit cbc68b0
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 42 deletions.
21 changes: 19 additions & 2 deletions Test/org/spdx/licensexml/LicenseXmlDocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
public class LicenseXmlDocumentTest {

static final String TEST_FILE_PATH = "TestFiles" + File.separator + "test-license.xml";
static final String TEST_OPTIONAL_FILE_PATH = "TestFiles" + File.separator + "test-optional-annotations.xml";
private static final String TEST_LICENSE_COMMENT = "Test note";
private static final String TEST_LICENSE_ID = "test-id";
private static final String TEST_LICENSE_TEXT = "Test Copyright\n\nparagraph 1" +
Expand All @@ -56,7 +57,7 @@ public class LicenseXmlDocumentTest {
private static final String[] TEST_LICENSE_URLS = new String[] {"http://test/url1","http://test/url2"};
private static final String TEST_LICENSE_HEADER = "Test header optional var";
private static final String TEST_LICENSE_HEADER_TEMPLATE = "Test header<<beginOptional>> optional<<endOptional>> <<var;name=\"h1test\";original=\"var\";match=\".+\">>";
private static final String TEST_LICENSE_TEMPLATE = "Test Copyright\n\nparagraph 1" +
private static final String TEST_LICENSE_TEMPLATE = "<<var;name=\"copyright\";original=\"Test Copyright\";match=\".{0,1000}\">>\n\nparagraph 1" +
"\n\n <<var;name=\"bullet\";original=\"1.\";match=\".{0,20}\">>\n\n List item 1\n\n <<var;name=\"bullet\";original=\"2.\";match=\".{0,20}\">>\n\n List item 2\n\n" +
"Last Paragraph <<var;name=\"alttest\";original=\"Alternate Text\";match=\".+\">> Non matching line.<<beginOptional>> Optional text<<endOptional>>";

Expand All @@ -68,7 +69,7 @@ public class LicenseXmlDocumentTest {
private static final String TEST_DEP_LICENSE_NAME = "Test Deprecated License";
private static final String[] TEST_DEP_LICENSE_URLS = new String[] {"http://test/url1d","http://test/url2d"};
private static final String TEST_DEP_LICENSE_HEADER = "Test header dep";
private static final String TEST_DEP_LICENSE_TEMPLATE = "Test Copyright dep\n\nparagraph 1d" +
private static final String TEST_DEP_LICENSE_TEMPLATE = "<<var;name=\"copyright\";original=\"Test Copyright dep\";match=\".{0,1000}\">>\n\nparagraph 1d" +
"\n\n <<var;name=\"bullet\";original=\"1.d\";match=\".{0,20}\">>\n\n List item 1d\n\n <<var;name=\"bullet\";original=\"2.d\";match=\".{0,20}\">>\n\n List item 2d\n\n" +
"Last Paragraph dep <<var;name=\"alttestd\";original=\"Alternate Text dep\";match=\".+\">> Non matching line dep.<<beginOptional>> Optional text dep<<endOptional>>";

Expand All @@ -85,6 +86,8 @@ public class LicenseXmlDocumentTest {
"Last Paragraph exc <<var;name=\"altteste\";original=\"Alternate Text exc\";match=\".+\">> Non matching line. e<<beginOptional>> Optional text exc<<endOptional>>";
private static final String TEST_DEP_LICENSE_VERSION = "2.2";
private static final String AGPL3ONLY_FILE_PATH = "TestFiles" + File.separator + "AGPL-3.0-only.xml";



/**
* @throws java.lang.Exception
Expand All @@ -109,6 +112,20 @@ public void testLicenseXmlDocumentFile() throws Exception {
new LicenseXmlDocument(licenseFile);
// I guess if we don't get any exceptions, it passed
}

@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);
String[] lines = license.getLicenseText().split("\\n");
assertEquals(9, lines.length);
assertEquals("before optional Default optional text after optional.", lines[0]);
assertEquals("before optionalNone optional textafter optional.", lines[2]);
assertEquals("before optional Before optional textafter optional.", lines[4]);
assertEquals("before optionalAfter optional text after optional.", lines[6]);
assertEquals("before optional Both optional text after optional.", lines[8]);
}

/**
* Test method for {@link org.spdx.licensexml.LicenseXmlDocument#getListedLicense()}.
Expand Down
2 changes: 1 addition & 1 deletion TestFiles/test-license.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@
</p>
</text>
</exception>
</SPDXLicenseCollection>
</SPDXLicenseCollection>
11 changes: 11 additions & 0 deletions TestFiles/test-optional-annotations.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<SPDXLicenseCollection xmlns="http://www.spdx.org/license">
<license name="Test License" licenseId="test-id" isOsiApproved="true">
<text>
before optional<optional>Default optional text</optional>after optional.<br />
before optional<optional spacing="none">None optional text</optional>after optional.<br />
before optional<optional spacing="before">Before optional text</optional>after optional.<br />
before optional<optional spacing="after">After optional text</optional>after optional.<br />
before optional<optional spacing="both">Both optional text</optional>after optional.<br />
</text>
</license>
</SPDXLicenseCollection>
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.spdx</groupId>
<artifactId>licenseListPublisher</artifactId>
<version>2.1.20-SNAPSHOT</version>
<version>2.1.20</version>
<name>License List Publisher</name>
<description>Tool that generates license data found in the license-list-data repository from the license-list-XML source</description>
<licenses>
Expand Down Expand Up @@ -43,7 +43,7 @@
<dependency>
<groupId>org.spdx</groupId>
<artifactId>spdx-tools</artifactId>
<version>2.1.16</version>
<version>2.1.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/org/spdx/licensexml/LicenseXmlDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private ListedLicenseException getException(Element exceptionElement) throws Lic
NodeList urlNodes = exceptionElement.getElementsByTagName(SpdxRdfConstants.LICENSEXML_ELEMENT_CROSS_REF);
String[] sourceUrls = new String[urlNodes.getLength()];
for (int i = 0; i < urlNodes.getLength(); i++) {
sourceUrls[i] = urlNodes.item(i).getTextContent();
sourceUrls[i] = urlNodes.item(i).getTextContent().trim();
}
return new ListedLicenseException(id, name, text, template, sourceUrls, comment, html, deprecated, deprecatedVersion);
}
Expand Down
Loading

0 comments on commit cbc68b0

Please # to comment.