From 3f05b8775ca540fbe566d75994b9a36b206803a3 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Fri, 26 Feb 2021 22:01:58 -0800 Subject: [PATCH 1/3] Fix formatting of text files for paragraph tags Signed-off-by: Gary O'Neall --- src/org/spdx/licensexml/LicenseXmlHelper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/org/spdx/licensexml/LicenseXmlHelper.java b/src/org/spdx/licensexml/LicenseXmlHelper.java index 333b732..cba0b77 100644 --- a/src/org/spdx/licensexml/LicenseXmlHelper.java +++ b/src/org/spdx/licensexml/LicenseXmlHelper.java @@ -161,6 +161,8 @@ private static boolean appendNodeText(Node node, boolean useTemplateFormat, Stri appendElementChildrenText(element, useTemplateFormat, sb, indentCount, unprocessedTags, includeHtmlTags); if (includeHtmlTags) { sb.append("

\n"); + } else { + addNewline(sb, indentCount); } } else if (SpdxConstants.LICENSEXML_ELEMENT_TITLE_TEXT.equals(tagName)) { if (!inALtBlock(element)) { @@ -431,7 +433,7 @@ private static boolean appendAltText(Element element, String altName, String mat sb.append("<>"); @@ -638,7 +640,9 @@ public static Object getHeaderTextHtml(Element headerElement) throws LicenseXmlE * @return Text normalized for different character variations */ private static String fixUpText(String string) { - return string.replaceAll(DOUBLE_QUOTES_REGEX, "\"").replaceAll(SINGLE_QUOTES_REGEX, "'"); + return string.replaceAll(DOUBLE_QUOTES_REGEX, "\"") + .replaceAll(SINGLE_QUOTES_REGEX, "'") + .replaceAll("\\n\\s*\\n\\s*\\n", "\n\n"); } /** From 1459032c9c421c10058a8ef23d04bb4cd8f05fa7 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Fri, 26 Feb 2021 22:04:27 -0800 Subject: [PATCH 2/3] Resolve issue #95 - check for duplicates when publishing a single file Signed-off-by: Gary O'Neall --- .../LicenseRDFAGenerator.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/org/spdx/licenselistpublisher/LicenseRDFAGenerator.java b/src/org/spdx/licenselistpublisher/LicenseRDFAGenerator.java index d5ab9ea..6356516 100644 --- a/src/org/spdx/licenselistpublisher/LicenseRDFAGenerator.java +++ b/src/org/spdx/licenselistpublisher/LicenseRDFAGenerator.java @@ -522,6 +522,24 @@ private static Set writeLicenseList(String version, String releaseDate, } } } + if (addedLicIdTextMap.size() == 1) { + // Since we are only creating a single file, we should check the listed licenses for duplicates + addedLicIdTextMap.entrySet().forEach(entry -> { + String[] matchingLicenseIds; + try { + matchingLicenseIds = LicenseCompareHelper.matchingStandardLicenseIds(entry.getValue()); + for (String matchingId:matchingLicenseIds) { + if (!entry.getKey().equals(matchingId)) { + warnings.add("Duplicates licenses: "+entry.getKey()+", "+matchingId); + } + } + } catch (InvalidSPDXAnalysisException e) { + warnings.add("Error comparing single license to existing listed licenses: "+e.getMessage()); + } catch (SpdxCompareException e) { + warnings.add("Error comparing single license to existing listed licenses: "+e.getMessage()); + } + }); + } return addedLicIdTextMap.keySet(); } finally { if (licenseIter instanceof Closeable) { From 8d5d3855ee38372d52377e9fd5a99a104a63c925 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Fri, 26 Feb 2021 22:06:45 -0800 Subject: [PATCH 3/3] Add unit tests for regression issues Signed-off-by: Gary O'Neall --- .../licensexml/LicenseXmlDocumentTest.java | 29 ++- TestFiles/BSD-Protection.xml | 168 ++++++++++++++++++ pom.xml | 16 +- 3 files changed, 197 insertions(+), 16 deletions(-) create mode 100644 TestFiles/BSD-Protection.xml diff --git a/Test/org/spdx/licensexml/LicenseXmlDocumentTest.java b/Test/org/spdx/licensexml/LicenseXmlDocumentTest.java index 496e5a8..c530c00 100644 --- a/Test/org/spdx/licensexml/LicenseXmlDocumentTest.java +++ b/Test/org/spdx/licensexml/LicenseXmlDocumentTest.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -53,32 +54,32 @@ public class LicenseXmlDocumentTest { private static final String TEST_LICENSE_ID = "test-id"; private static final String TEST_LICENSE_TEXT = "Test Copyright\n\nparagraph 1" + "\n\n 1.\n\n List item 1\n\n 2.\n\n List item 2\n\n" + - "Last Paragraph Alternate Text Non matching line. Optional text"; + "Last Paragraph Alternate Text Non matching line. Optional text\n\n"; private static final String TEST_LICENSE_NAME = "Test License"; private static final List TEST_LICENSE_URLS = Arrays.asList(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<> optional<> <>"; - private static final String TEST_LICENSE_TEMPLATE = "<>\n\nparagraph 1" + + private static final String TEST_LICENSE_TEMPLATE = "<>\n\nparagraph 1" + "\n\n <>\n\n List item 1\n\n <>\n\n List item 2\n\n" + - "Last Paragraph <> Non matching line.<> Optional text<>"; + "Last Paragraph <> Non matching line.<> Optional text<>\n\n"; private static final String TEST_DEP_LICENSE_COMMENT = "Test dep note"; private static final String TEST_DEP_LICENSE_ID = "test-dep"; private static final String TEST_DEP_LICENSE_TEXT = "Test Copyright dep\n\nparagraph 1d" + "\n\n 1.d\n\n List item 1d\n\n 2.d\n\n List item 2d\n\n" + - "Last Paragraph dep Alternate Text dep Non matching line dep. Optional text dep"; + "Last Paragraph dep Alternate Text dep Non matching line dep. Optional text dep\n\n"; private static final String TEST_DEP_LICENSE_NAME = "Test Deprecated License"; private static final List TEST_DEP_LICENSE_URLS = Arrays.asList(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 = "<>\n\nparagraph 1d" + + private static final String TEST_DEP_LICENSE_TEMPLATE = "<>\n\nparagraph 1d" + "\n\n <>\n\n List item 1d\n\n <>\n\n List item 2d\n\n" + - "Last Paragraph dep <> Non matching line dep.<> Optional text dep<>"; + "Last Paragraph dep <> Non matching line dep.<> Optional text dep<>\n\n"; private static final String TEST_EXCEPTION_COMMENT = "Test note exception"; private static final String TEST_EXCEPTION_ID = "test-ex"; private static final String TEST_EXCEPTION_TEXT = "Test Copyrighte\n\nparagraph 1e" + "\n\n 1.e\n\n List item 1e\n\n 2.e\n\n List item 2e\n\n" + - "Last Paragraph exc Alternate Text exc Non matching line. e Optional text exc"; + "Last Paragraph exc Alternate Text exc Non matching line. e Optional text exc\n\n"; private static final String TEST_EXCEPTION_NAME = "Test Exception"; private static final List TEST_EXCEPTION_URLS = Arrays.asList(new String[] {"http://test/url1e","http://test/url2e"}); @SuppressWarnings("unused") @@ -87,7 +88,7 @@ public class LicenseXmlDocumentTest { "Last Paragraph exc <> Non matching line. e<> Optional text exc<>"; 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"; - + private static final String BSD_PROTECTION_FILE_PATH = "TestFiles" + File.separator + "BSD-Protection.xml"; /** @@ -200,4 +201,16 @@ public void testRegressionAgpl3Only() throws LicenseXmlException, InvalidSPDXAna List 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 licenses = doc.getListedLicenses(); + assertEquals(1, licenses.size()); + SpdxListedLicense result = licenses.get(0); + String template = result.getStandardLicenseTemplate(); + Pattern matchingModificationLine = Pattern.compile("<>\\s?----------------------------------------------------------------<>",Pattern.MULTILINE); + assertTrue(matchingModificationLine.matcher(template).find()); + } } diff --git a/TestFiles/BSD-Protection.xml b/TestFiles/BSD-Protection.xml new file mode 100644 index 0000000..5194dbe --- /dev/null +++ b/TestFiles/BSD-Protection.xml @@ -0,0 +1,168 @@ + + + + + https://fedoraproject.org/wiki/Licensing/BSD_Protection_License + + + +

BSD Protection License +
February 2002 +

+
+ +

Preamble +
-------- +

+

The Berkeley Software Distribution ("BSD") license has proven very effective over the years at + allowing for a wide spread of work throughout both commercial and non-commercial products. For + programmers whose primary intention is to improve the general quality of available software, it is + arguable that there is no better license than the BSD license, as it permits improvements to be used + wherever they will help, without idealogical or metallic constraint.

+

This is of particular value to those who produce reference implementations of proposed standards: The + case of TCP/IP clearly illustrates that freely and universally available implementations leads the + rapid acceptance of standards -- often even being used instead of a de jure standard (eg, OSI network + models).

+

With the rapid proliferation of software licensed under the GNU General Public License, however, the + continued success of this role is called into question. Given that the inclusion of a few lines of + "GPL-tainted" work into a larger body of work will result in restricted distribution -- and + given that further work will likely build upon the "tainted" portions, making them difficult + to remove at a future date -- there are inevitable circumstances where authors would, in order to + protect their goal of providing for the widespread usage of their work, wish to guard against such + "GPL-taint".

+

In addition, one can imagine that companies which operate by producing and selling (possibly + closed-source) code would wish to protect themselves against the rise of a GPL-licensed competitor. + While under existing licenses this would mean not releasing their code under any form of open license, + if a license existed under which they could incorporate any improvements back into their own + (commercial) products then they might be far more willing to provide for non-closed distribution.

+

For the above reasons, we put forth this "BSD Protection License": A license designed to retain + the freedom granted by the BSD license to use licensed works in a wide variety of settings, both + non-commercial and commercial, while protecting the work from having future contributors restrict that + freedom.

+

The precise terms and conditions for copying, distribution, and modification follow.

+
+ +

BSD PROTECTION LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION

+ ---------------------------------------------------------------- + + + 0. + Definitions. + + + + a) + "Program", below, refers to any program or work distributed under the terms of this + license. + + + b) + A "work based on the Program", below, refers to either the Program or any + derivative work under copyright law. + + + c) + "Modification", below, refers to the act of creating derivative works. + + + d) + "You", below, refers to each licensee. + + + + 1. + Scope. +
This license governs the copying, distribution, and modification of the Program. Other + activities are outside the scope of this license; The act of running the Program is + not restricted, and the output from the Program is covered only if its contents + constitute a work based on the Program. + +
+ + 2. + Verbatim copies. +
You may copy and distribute verbatim copies of the Program as you receive it, in any + medium, provided that you conspicuously and appropriately publish on each copy an + appropriate copyright notice; keep intact all the notices that refer to this License + and to the absence of any warranty; and give any other recipients of the Program a + copy of this License along with the Program. + +
+ + 3. + Modification and redistribution under closed license. +
You may modify your copy or copies of the Program, and distribute the resulting derivative + works, provided that you meet the following conditions: + +
+ + + a) + The copyright notice and disclaimer on the Program must be reproduced and included in the + source code, documentation, and/or other materials provided in a manner in which such + notices are normally distributed. + + + b) + The derivative work must be clearly identified as such, in order that it may not be confused + with the original work. + + + c) + The license under which the derivative work is distributed must expressly prohibit the + distribution of further derivative works. + + + + 4. + Modification and redistribution under open license. +
You may modify your copy or copies of the Program, and distribute the resulting derivative + works, provided that you meet the following conditions: + +
+ + + a) + The copyright notice and disclaimer on the Program must be reproduced and included in the + source code, documentation, and/or other materials provided in a manner in which such + notices are normally distributed. + + + b) + You must clearly indicate the nature and date of any changes made to the Program. The full + details need not necessarily be included in the individual modified files, provided that + each modified file is clearly marked as such and instructions are included on where the + full details of the modifications may be found. + + + c) + You must cause any work that you distribute or publish, that in whole or in part contains or + is derived from the Program or any part thereof, to be licensed as a whole at no charge to + all third parties under the terms of this License. + + + + 5. + Implied acceptance. +
You may not copy or distribute the Program or any derivative works except as expressly + provided under this license. Consequently, any such action will be taken as implied + acceptance of the terms of this license. + +
+ + 6. + NO WARRANTY. + +
+

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR + REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT, EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + DAMAGES.

+
+
+
diff --git a/pom.xml b/pom.xml index 9f3733a..9ed2df5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.spdx licenseListPublisher - 2.2.0-SNAPSHOT + 2.2.0 License List Publisher Tool that generates license data found in the license-list-data repository from the license-list-XML source @@ -33,11 +33,11 @@ scm:git:ssh://git@github.com:spdx/LicenseListPublisher.git - - bintray-spdx-spdx-LicenseListPublisher - spdx-spdx-LicenseListPublisher - https://api.bintray.com/maven/spdx/spdx-tools/LicenseListPublisher/;publish=1 - + + ossrh + spdx-spdx-tools + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + UTF-8 @@ -77,7 +77,7 @@ org.spdx java-spdx-library - 0.0.5 + 1.0.1 com.github.spullara.mustache.java @@ -97,7 +97,7 @@ org.spdx spdx-rdf-store - 0.0.5 + 1.0.0