Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions TestFiles/eCos-exception-2.0.txt
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion src/main/java/org/spdx/library/LicenseInfoFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
52 changes: 42 additions & 10 deletions src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> listAllListedExceptionIdsMatched(String exceptionText) throws InvalidSPDXAnalysisException, SpdxCompareException {
List<String> listedExceptionIds = ListedLicenses.getListedLicenses().getSpdxListedExceptionIds();
List<String> 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<String> stdLicenseIds = ListedLicenses.getListedLicenses().getSpdxListedLicenseIds();
public static List<String> listAllListedLicenseIdsMatched(String licenseText) throws InvalidSPDXAnalysisException, SpdxCompareException {
List<String> listedLicenseIds = ListedLicenses.getListedLicenses().getSpdxListedLicenseIds();
List<String> 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 <code>listAllListedLicenseIdsMatched(String licenseText)</code>
* @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
Expand All @@ -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<String> matchingStandardLicenseIdsWithinText(String text, List<String> licenseIds) throws InvalidSPDXAnalysisException {
List<String> result = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> matchingStandardLicenseIds = Arrays.asList(LicenseCompareHelper.matchingStandardLicenseIds(text));
final List<String> matchingStandardLicenseIds = LicenseCompareHelper.listAllListedLicenseIdsMatched(text);
final List<String> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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<String> 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);
Expand Down Expand Up @@ -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<String> result = LicenseCompareHelper.listAllListedLicenseIdsMatched(licText);
assertEquals(0, result.size());
ListedLicense license = ListedLicenses.getListedLicenses().getListedLicenseById("X11-distribute-modifications-variant");
assertTrue(LicenseCompareHelper.isTextStandardLicense(license, licText).isDifferenceFound());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
Loading