diff --git a/TestFiles/eCos-exception-2.0.txt b/TestFiles/eCos-exception-2.0.txt new file mode 100644 index 000000000..a0bf0077c --- /dev/null +++ b/TestFiles/eCos-exception-2.0.txt @@ -0,0 +1,3 @@ +As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. + +This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. diff --git a/src/main/java/org/spdx/library/LicenseInfoFactory.java b/src/main/java/org/spdx/library/LicenseInfoFactory.java index 89ff65f50..5ee13ee35 100644 --- a/src/main/java/org/spdx/library/LicenseInfoFactory.java +++ b/src/main/java/org/spdx/library/LicenseInfoFactory.java @@ -96,7 +96,7 @@ public static SpdxListedLicense getListedLicenseByIdCompatV2(String licenseId)th * @throws DefaultStoreNotInitializedException if the default model store is not initialized */ public static org.spdx.library.model.v2.license.AnyLicenseInfo parseSPDXLicenseStringCompatV2(String licenseString, @Nullable IModelStore store, - @Nullable String documentUri, @Nullable IModelCopyManager copyManager) throws InvalidLicenseStringException, DefaultStoreNotInitializedException { + @Nullable String documentUri, @Nullable IModelCopyManager copyManager) throws DefaultStoreNotInitializedException { if (Objects.isNull(store)) { store = DefaultModelStore.getDefaultModelStore(); } diff --git a/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java b/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java index dc0059808..f12c872db 100644 --- a/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java +++ b/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java @@ -468,27 +468,59 @@ public static boolean isStandardLicenseExceptionWithinText(String text, ListedLi return result; } + /** + * Returns a list of SPDX Listed Exception ID's that match the text provided using + * the SPDX matching guidelines. + * @param exceptionText Text to compare to the listed exception texts + * @return List of SPDX listed exception IDs that match + * @throws InvalidSPDXAnalysisException If an error occurs accessing the listed exceptions + * @throws SpdxCompareException If an error occurs in the comparison + */ + public static List listAllListedExceptionIdsMatched(String exceptionText) throws InvalidSPDXAnalysisException, SpdxCompareException { + List listedExceptionIds = ListedLicenses.getListedLicenses().getSpdxListedExceptionIds(); + List matchingIds = new ArrayList<>(); + for (String exceptionId : listedExceptionIds) { + ListedLicenseException exception = ListedLicenses.getListedLicenses().getListedExceptionById(exceptionId); + if (!isTextStandardException(exception, exceptionText).isDifferenceFound()) { + matchingIds.add(licenseUriToLicenseId(exception.getObjectUri())); + } + } + return matchingIds; + } /** - * Returns a list of SPDX Standard License ID's that match the text provided using + * Returns a list of SPDX Listed License ID's that match the text provided using * the SPDX matching guidelines. - * @param licenseText Text to compare to the standard license texts - * @return Array of SPDX standard license IDs that match - * @throws InvalidSPDXAnalysisException If an error occurs accessing the standard licenses + * @param licenseText Text to compare to the listed license texts + * @return List of SPDX listed license IDs that match + * @throws InvalidSPDXAnalysisException If an error occurs accessing the listed licenses * @throws SpdxCompareException If an error occurs in the comparison */ - public static String[] matchingStandardLicenseIds(String licenseText) throws InvalidSPDXAnalysisException, SpdxCompareException { - List stdLicenseIds = ListedLicenses.getListedLicenses().getSpdxListedLicenseIds(); + public static List listAllListedLicenseIdsMatched(String licenseText) throws InvalidSPDXAnalysisException, SpdxCompareException { + List listedLicenseIds = ListedLicenses.getListedLicenses().getSpdxListedLicenseIds(); List matchingIds = new ArrayList<>(); - for (String stdLicId : stdLicenseIds) { - ListedLicense license = ListedLicenses.getListedLicenses().getListedLicenseById(stdLicId); + for (String listedLicId : listedLicenseIds) { + ListedLicense license = ListedLicenses.getListedLicenses().getListedLicenseById(listedLicId); if (!isTextStandardLicense(license, licenseText).isDifferenceFound()) { matchingIds.add(licenseUriToLicenseId(license.getObjectUri())); } } - return matchingIds.toArray(new String[0]); + return matchingIds; } + /** + * Returns an array of SPDX Listed License ID's that match the text provided using + * the SPDX matching guidelines. Deprecated in favor of listAllListedLicenseIdsMatched(String licenseText) + * @param licenseText Text to compare to the listed license texts + * @return Array of SPDX listed license IDs that match + * @throws InvalidSPDXAnalysisException If an error occurs accessing the listed licenses + * @throws SpdxCompareException If an error occurs in the comparison + */ + @SuppressWarnings("DeprecatedIsStillUsed") + @Deprecated + public static String[] matchingStandardLicenseIds(String licenseText) throws InvalidSPDXAnalysisException, SpdxCompareException { + return listAllListedLicenseIdsMatched(licenseText).toArray(new String[0]); + } /** * Returns a list of SPDX Standard License ID's from the provided list that were found within the text, using @@ -497,7 +529,7 @@ public static String[] matchingStandardLicenseIds(String licenseText) throws Inv * @param licenseIds License ids to compare against * @return List of SPDX standard license IDs from licenseIds that match * @throws InvalidSPDXAnalysisException If an error occurs accessing the standard licenses - */ + */ public static List matchingStandardLicenseIdsWithinText(String text, List licenseIds) throws InvalidSPDXAnalysisException { List result = new ArrayList<>(); diff --git a/src/test/java/org/spdx/utility/compare/CompareConsistencyHelper.java b/src/test/java/org/spdx/utility/compare/CompareConsistencyHelper.java index 173599060..fbfd381ce 100644 --- a/src/test/java/org/spdx/utility/compare/CompareConsistencyHelper.java +++ b/src/test/java/org/spdx/utility/compare/CompareConsistencyHelper.java @@ -62,7 +62,7 @@ public static String explainCompareInconsistencies(final String licenseId, final final boolean isDifferenceFound = LicenseCompareHelper.isTextStandardLicense(listedLicense, text).isDifferenceFound(); final boolean isStandardLicenseWithinText = LicenseCompareHelper.isStandardLicenseWithinText(text, listedLicense); - final List matchingStandardLicenseIds = Arrays.asList(LicenseCompareHelper.matchingStandardLicenseIds(text)); + final List matchingStandardLicenseIds = LicenseCompareHelper.listAllListedLicenseIdsMatched(text); final List matchingStandardLicenseIdsWithinText = LicenseCompareHelper.matchingStandardLicenseIdsWithinText(text); // Note: we sort these lists because we don't care about different orderings within them - just that they contain the same elements (in any order) diff --git a/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java b/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java index cdb4bb0a2..85e2b7c81 100644 --- a/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java +++ b/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java @@ -104,6 +104,7 @@ public class LicenseCompareHelperTest extends TestCase { static final String GPL_2_TEMPLATE = "TestFiles" + File.separator + "GPL-2.0-only.template.txt"; static final String IMAGE_MAGIK_TEMPLATE = "TestFiles" + File.separator + "ImageMagick.template.txt"; static final String X_11_PTHREADS = "TestFiles" + File.separator + "x-11-pthreads.txt"; + static final String ECOS_EXCEPTION = "TestFiles" + File.separator + "eCos-exception-2.0.txt"; IModelStore modelStore; IModelCopyManager copyManager; @@ -572,6 +573,27 @@ public void regressionTestMatchingGpl20Only() throws IOException, InvalidSPDXAna assertFalse(result.isDifferenceFound()); } + public void testListAllListedLicenseIdsMatched() throws IOException, InvalidSPDXAnalysisException, SpdxCompareException { + if (UnitTestHelper.runSlowTests()) { + String compareText = UnitTestHelper.fileToText(GPL_2_TEXT); + List result = LicenseCompareHelper.listAllListedLicenseIdsMatched(compareText); + assertEquals(4,result.size()); + assertTrue(result.get(0).startsWith("GPL-2")); + assertTrue(result.get(1).startsWith("GPL-2")); + assertTrue(result.get(2).startsWith("GPL-2")); + assertTrue(result.get(3).startsWith("GPL-2")); + } + } + + public void testListAllListedExceptionIdsMatched() throws IOException, InvalidSPDXAnalysisException, SpdxCompareException { + if (UnitTestHelper.runSlowTests()) { + String compareText = UnitTestHelper.fileToText(ECOS_EXCEPTION); + List result = LicenseCompareHelper.listAllListedExceptionIdsMatched(compareText); + assertEquals(1,result.size()); + assertEquals("eCos-exception-2.0", result.get(0)); + } + } + public void testMatchingStandardLicenseIds() throws IOException, InvalidSPDXAnalysisException, SpdxCompareException { if (UnitTestHelper.runSlowTests()) { String compareText = UnitTestHelper.fileToText(GPL_2_TEXT); @@ -1015,8 +1037,8 @@ public void testAPIConsistency() throws InvalidSPDXAnalysisException, SpdxCompar public void testX11Pthreads() throws InvalidSPDXAnalysisException, SpdxCompareException, IOException { String licText = UnitTestHelper.fileToText(X_11_PTHREADS); - String[] result = LicenseCompareHelper.matchingStandardLicenseIds(licText); - assertEquals(0, result.length); + List result = LicenseCompareHelper.listAllListedLicenseIdsMatched(licText); + assertEquals(0, result.size()); ListedLicense license = ListedLicenses.getListedLicenses().getListedLicenseById("X11-distribute-modifications-variant"); assertTrue(LicenseCompareHelper.isTextStandardLicense(license, licText).isDifferenceFound()); } diff --git a/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTestV2.java b/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTestV2.java index de882abaf..81321fe5e 100644 --- a/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTestV2.java +++ b/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTestV2.java @@ -466,18 +466,6 @@ public void regressionTestMatchingGpl20Only() throws IOException, InvalidSPDXAna assertFalse(result.isDifferenceFound()); } - public void testMatchingStandardLicenseIds() throws IOException, InvalidSPDXAnalysisException, SpdxCompareException { - if (UnitTestHelper.runSlowTests()) { - String compareText = UnitTestHelper.fileToText(GPL_2_TEXT); - String[] result = LicenseCompareHelper.matchingStandardLicenseIds(compareText); - assertEquals(4,result.length); - assertTrue(result[0].startsWith("GPL-2")); - assertTrue(result[1].startsWith("GPL-2")); - assertTrue(result[2].startsWith("GPL-2")); - assertTrue(result[3].startsWith("GPL-2")); - } - } - public void testFirstLicenseToken() { assertEquals("first", LicenseCompareHelper.getFirstLicenseToken(" first,token that is needed\nnext")); }