Package org.spdx.utility.compare
Class LicenseCompareHelper
java.lang.Object
org.spdx.utility.compare.LicenseCompareHelper
public class LicenseCompareHelper extends Object
Primarily a static class of helper functions for comparing two SPDX licenses
- Author:
- Gary O'Neall
-
Field Summary
Fields Modifier and Type Field Description protected static Map<String,String>NORMALIZE_TOKENSprotected static Set<String>PUNCTUATIONprotected static Set<String>SKIPPABLE_TOKENSprotected static PatternTOKEN_SPLIT_PATTERNprotected static StringTOKEN_SPLIT_REGEX -
Constructor Summary
Constructors Constructor Description LicenseCompareHelper() -
Method Summary
Modifier and Type Method Description static StringgetFirstLicenseToken(String text)static List<String>getNonOptionalLicenseText(String licenseTemplate, boolean includeVarText)Get the text of a license minus any optional text - note: this include the default variable textstatic booleanisLicenseEqual(AnyLicenseInfo license1, AnyLicenseInfo license2, Map<String,String> xlationMap)Compares two licenses from potentially two different documents which may have different license ID's for the same licensestatic booleanisLicenseTextEquivalent(String licenseTextA, String licenseTextB)Returns true if two sets of license text is considered a match per the SPDX License matching guidelines documented at spdx.org (currently http://spdx.org/wiki/spdx-license-list-match-guidelines) There are 2 unimplemented features - bullets/numbering is not considered and comments with no whitespace between text is not skippedstatic booleanisSingleTokenString(String text)static CompareTemplateOutputHandler.DifferenceDescriptionisTextStandardException(LicenseException exception, String compareText)Compares exception text to the exception text of an SPDX Standard exceptionstatic CompareTemplateOutputHandler.DifferenceDescriptionisTextStandardLicense(License license, String compareText)Compares license text to the license text of an SPDX Standard Licensestatic StringlocateOriginalText(String fullLicenseText, int startToken, int endToken, Map<Integer,LineColumn> tokenToLocation, String[] tokens)Locate the original text starting with the start token and ending with the end tokenstatic String[]matchingStandardLicenseIds(String licenseText)Returns a list of SPDX Standard License ID's that match the text provided using the SPDX matching guidelines.static PatternnonOptionalTextToStartPattern(List<String> nonOptionalText, int numberOfWords)Creates a regular expression pattern to match the start of a license textstatic StringnormalizeText(String s)Normalize quotes and no-break spacesstatic String[]tokenizeLicenseText(String licenseText, Map<Integer,LineColumn> tokenToLocation)Tokenizes the license text, normalizes quotes, lowercases and converts multi-words for better equiv.
-
Field Details
-
Constructor Details
-
LicenseCompareHelper
public LicenseCompareHelper()
-
-
Method Details
-
isLicenseTextEquivalent
Returns true if two sets of license text is considered a match per the SPDX License matching guidelines documented at spdx.org (currently http://spdx.org/wiki/spdx-license-list-match-guidelines) There are 2 unimplemented features - bullets/numbering is not considered and comments with no whitespace between text is not skipped- Parameters:
licenseTextA-licenseTextB-- Returns:
-
normalizeText
Normalize quotes and no-break spaces- Parameters:
s-- Returns:
-
locateOriginalText
public static String locateOriginalText(String fullLicenseText, int startToken, int endToken, Map<Integer,LineColumn> tokenToLocation, String[] tokens)Locate the original text starting with the start token and ending with the end token- Parameters:
fullLicenseText-startToken-endToken-tokenToLocation-- Returns:
-
tokenizeLicenseText
public static String[] tokenizeLicenseText(String licenseText, Map<Integer,LineColumn> tokenToLocation)Tokenizes the license text, normalizes quotes, lowercases and converts multi-words for better equiv. comparisons- Parameters:
tokenLocations- location for all of the tokenslicenseText-- Returns:
- Throws:
IOException
-
getFirstLicenseToken
- Parameters:
text-- Returns:
- the first token in the license text
-
isSingleTokenString
- Parameters:
text-- Returns:
- true if the text contains a single token
-
isLicenseEqual
public static boolean isLicenseEqual(AnyLicenseInfo license1, AnyLicenseInfo license2, Map<String,String> xlationMap) throws SpdxCompareException, InvalidSPDXAnalysisExceptionCompares two licenses from potentially two different documents which may have different license ID's for the same license- Parameters:
license1-license2-xlationMap- Mapping the license ID's from license 1 to license 2- Returns:
- Throws:
SpdxCompareExceptionInvalidSPDXAnalysisException
-
getNonOptionalLicenseText
public static List<String> getNonOptionalLicenseText(String licenseTemplate, boolean includeVarText) throws SpdxCompareExceptionGet the text of a license minus any optional text - note: this include the default variable text- Parameters:
licenseTemplate- license template containing optional and var tagsincludeVarText- if true, include the default variable text; if false remove the variable text- Returns:
- list of strings for all non-optional license text.
- Throws:
SpdxCompareException
-
nonOptionalTextToStartPattern
public static Pattern nonOptionalTextToStartPattern(List<String> nonOptionalText, int numberOfWords)Creates a regular expression pattern to match the start of a license text- Parameters:
nonOptionalText- List of strings of non-optional text from the license template (seeList)getNonOptionalLicenseText numberOfWords- Number of words to use in the match- Returns:
- Pattern which will match the start of the license text
-
isTextStandardLicense
public static CompareTemplateOutputHandler.DifferenceDescription isTextStandardLicense(License license, String compareText) throws SpdxCompareException, InvalidSPDXAnalysisExceptionCompares license text to the license text of an SPDX Standard License- Parameters:
license- SPDX Standard License to comparecompareText- Text to compare to the standard license- Returns:
- any differences found
- Throws:
SpdxCompareExceptionInvalidSPDXAnalysisException
-
isTextStandardException
public static CompareTemplateOutputHandler.DifferenceDescription isTextStandardException(LicenseException exception, String compareText) throws SpdxCompareException, InvalidSPDXAnalysisExceptionCompares exception text to the exception text of an SPDX Standard exception- Parameters:
exception- SPDX Standard exception to comparecompareText- Text to compare to the standard exceptions- Returns:
- any differences found
- Throws:
SpdxCompareExceptionInvalidSPDXAnalysisException
-
matchingStandardLicenseIds
public static String[] matchingStandardLicenseIds(String licenseText) throws InvalidSPDXAnalysisException, SpdxCompareExceptionReturns a list of SPDX Standard License ID's that match the text provided using the SPDX matching guidelines.- Parameters:
licenseText- Text to compare to the standard license texts- Returns:
- Array of SPDX standard license IDs that match
- Throws:
InvalidSPDXAnalysisException- If an error occurs accessing the standard licensesSpdxCompareException- If an error occurs in the comparison
-