Class LicenseCompareHelper
java.lang.Object
org.spdx.utility.compare.LicenseCompareHelper
Primarily a static class of helper functions for comparing two SPDX licenses
- Author:
- Gary O'Neall
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetFirstLicenseToken(String text) Return the first license token found in the given textgetNonOptionalLicenseText(String licenseTemplate, FilterTemplateOutputHandler.VarTextHandling varTextHandling) Get the text of a license minus any optional text - note: this includes the default variable textgetNonOptionalLicenseText(String licenseTemplate, FilterTemplateOutputHandler.VarTextHandling varTextHandling, FilterTemplateOutputHandler.OptionalTextHandling optionalTextHandling) Get the text of a license converting variable and optional text according to the optionsstatic booleanisLicenseEqual(org.spdx.library.model.v2.license.AnyLicenseInfo license1, org.spdx.library.model.v2.license.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 booleanisLicenseEqual(org.spdx.library.model.v3_0_1.simplelicensing.AnyLicenseInfo license1, org.spdx.library.model.v3_0_1.simplelicensing.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 booleanisLicensePassBlackList(org.spdx.library.model.v2.license.AnyLicenseInfo license, String... blackList) Detect if a license pass black listsstatic booleanisLicensePassBlackList(org.spdx.library.model.v3_0_1.simplelicensing.AnyLicenseInfo license, String... blackList) Detect if a license pass black listsstatic booleanisLicensePassWhiteList(org.spdx.library.model.v2.license.AnyLicenseInfo license, String... whiteList) Detect if a license pass white listsstatic booleanisLicensePassWhiteList(org.spdx.library.model.v3_0_1.simplelicensing.AnyLicenseInfo license, String... whiteList) Detect if a license pass white listsstatic booleanisSingleTokenString(String text) Check whether the given text contains only a single tokenstatic booleanisStandardLicenseExceptionWithinText(String text, org.spdx.library.model.v2.license.ListedLicenseException exception) Detect if a text contains the standard license exception (perhaps along with other text before and/or after)static booleanisStandardLicenseExceptionWithinText(String text, org.spdx.library.model.v3_0_1.expandedlicensing.ListedLicenseException exception) Detect if a text contains the standard license exception (perhaps along with other text before and/or after)static booleanisStandardLicenseWithinText(String text, org.spdx.library.model.v2.license.SpdxListedLicense license) Detect if a text contains the standard license (perhaps along with other text before and/or after)static booleanisStandardLicenseWithinText(String text, org.spdx.library.model.v3_0_1.expandedlicensing.ListedLicense license) Detect if a text contains the standard license (perhaps along with other text before and/or after)isTextMatchingTemplate(String template, String compareText) Compare the provided text against a license template using SPDX matching guidelinesisTextStandardException(org.spdx.library.model.v2.license.LicenseException exception, String compareText) Compares exception text to the exception text of an SPDX Standard exceptionisTextStandardException(org.spdx.library.model.v3_0_1.expandedlicensing.ListedLicenseException exception, String compareText) Compares exception text to the exception text of an SPDX Standard exceptionisTextStandardLicense(org.spdx.library.model.v2.license.License license, String compareText) Compares license text to the license text of an SPDX Standard LicenseisTextStandardLicense(org.spdx.library.model.v3_0_1.expandedlicensing.License license, String compareText) Compares license text to the license text of an SPDX Standard Licensestatic StringlicenseUriToLicenseId(String objectUri) Convert a license object URI to its corresponding License IDstatic StringlocateOriginalText(String fullLicenseText, int startToken, int endToken, Map<Integer, org.spdx.licenseTemplate.LineColumn> tokenToLocation, String[] tokens) Locate the original text starting with the start token and ending with the end tokenReturns a list of SPDX Standard License Exception ID's that were found within the text, using the SPDX matching guidelines.matchingStandardLicenseExceptionIdsWithinText(String text, List<String> licenseExceptionIds) Returns a list of SPDX Standard License Exception ID's from the provided list that were found within the text, using the SPDX matching guidelines.static String[]matchingStandardLicenseIds(String licenseText) Returns a list of SPDX Standard License ID's that match the text provided using the SPDX matching guidelines.Returns a list of SPDX Standard License ID's that were found within the text, using the SPDX matching guidelines.matchingStandardLicenseIdsWithinText(String text, List<String> licenseIds) Returns a list of SPDX Standard License ID's from the provided list that were found within the text, using the SPDX matching guidelines.static StringRemove common comment characters from either a template or license text strings
-
Field Details
-
CROSS_REF_NUM_WORDS_MATCH
-
REGEX_QUANTIFIER_PATTERN
-
-
Constructor Details
-
LicenseCompareHelper
public LicenseCompareHelper()
-
-
Method Details
-
licenseUriToLicenseId
-
removeCommentChars
-
locateOriginalText
public static String locateOriginalText(String fullLicenseText, int startToken, int endToken, Map<Integer, org.spdx.licenseTemplate.LineColumn> tokenToLocation, String[] tokens) Locate the original text starting with the start token and ending with the end token- Parameters:
fullLicenseText- entire license textstartToken- starting tokenendToken- ending tokentokenToLocation- token location- Returns:
- original text starting with the start token and ending with the end token
-
getFirstLicenseToken
Return the first license token found in the given textThe method normalizes the input text, removes comment characters, and splits it into tokens using
LicenseTextHelper.TOKEN_SPLIT_PATTERN. It returns the first non-empty token found, ornullif no such token exists.- Parameters:
text- The license text to extract the first token from.- Returns:
- The first non-empty token as a
String, ornullif none is found.
-
isSingleTokenString
Check whether the given text contains only a single tokenA single token string is a string that contains exactly one token, as identified by the
LicenseTextHelper.TOKEN_SPLIT_PATTERN. Whitespace and punctuation such as dots, commas, question marks, and quotation marks are ignored.- Parameters:
text- The text to test.- Returns:
trueif the text contains exactly one token,falseotherwise.
-
isLicenseEqual
public static boolean isLicenseEqual(org.spdx.library.model.v3_0_1.simplelicensing.AnyLicenseInfo license1, org.spdx.library.model.v3_0_1.simplelicensing.AnyLicenseInfo license2, Map<String, String> xlationMap) throws SpdxCompareException, org.spdx.core.InvalidSPDXAnalysisExceptionCompares two licenses from potentially two different documents which may have different license ID's for the same license- Parameters:
license1- first license to comparelicense2- second license to comparexlationMap- Mapping the license ID's from license 1 to license 2- Returns:
- true if the licenses equal
- Throws:
SpdxCompareException- on comparison errorsorg.spdx.core.InvalidSPDXAnalysisException- on errors reading reading properties from the SPDX model
-
getNonOptionalLicenseText
public static List<String> getNonOptionalLicenseText(String licenseTemplate, FilterTemplateOutputHandler.VarTextHandling varTextHandling) throws SpdxCompareException Get the text of a license minus any optional text - note: this includes the default variable text- Parameters:
licenseTemplate- license template containing optional and var tagsvarTextHandling- include original, exclude, or include the regex (enclosed with "~~~") for "var" text- Returns:
- list of strings for all non-optional license text.
- Throws:
SpdxCompareException- on comparison errors
-
getNonOptionalLicenseText
public static List<String> getNonOptionalLicenseText(String licenseTemplate, FilterTemplateOutputHandler.VarTextHandling varTextHandling, FilterTemplateOutputHandler.OptionalTextHandling optionalTextHandling) throws SpdxCompareException Get the text of a license converting variable and optional text according to the options- Parameters:
licenseTemplate- license template containing optional and var tagsvarTextHandling- include original, exclude, or include the regex (enclosed with "~~~") for "var" textoptionalTextHandling- include optional text, exclude, or include a regex for the optional text- Returns:
- list of strings for all non-optional license text.
- Throws:
SpdxCompareException- on comparison errors
-
isTextMatchingTemplate
public static CompareTemplateOutputHandler.DifferenceDescription isTextMatchingTemplate(String template, String compareText) throws SpdxCompareException Compare the provided text against a license template using SPDX matching guidelines- Parameters:
template- Template in the standard template format used for comparisoncompareText- Text to compare using the template- Returns:
- Any differences found
- Throws:
SpdxCompareException- on comparison errors
-
isTextStandardLicense
public static CompareTemplateOutputHandler.DifferenceDescription isTextStandardLicense(org.spdx.library.model.v3_0_1.expandedlicensing.License license, String compareText) throws SpdxCompareException, org.spdx.core.InvalidSPDXAnalysisException Compares 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:
SpdxCompareException- on comparison errorsorg.spdx.core.InvalidSPDXAnalysisException- on errors reading reading properties from the SPDX model
-
isTextStandardException
public static CompareTemplateOutputHandler.DifferenceDescription isTextStandardException(org.spdx.library.model.v3_0_1.expandedlicensing.ListedLicenseException exception, String compareText) throws SpdxCompareException, org.spdx.core.InvalidSPDXAnalysisException Compares 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:
SpdxCompareException- on comparison errorsorg.spdx.core.InvalidSPDXAnalysisException- on errors reading reading properties from the SPDX model
-
isStandardLicenseWithinText
public static boolean isStandardLicenseWithinText(String text, org.spdx.library.model.v3_0_1.expandedlicensing.ListedLicense license) Detect if a text contains the standard license (perhaps along with other text before and/or after)- Parameters:
text- The text to search within (should not be null)license- The standard SPDX license to search for (should not be null)- Returns:
- True if the license is found within the text, false otherwise (or if either argument is null)
-
isStandardLicenseExceptionWithinText
public static boolean isStandardLicenseExceptionWithinText(String text, org.spdx.library.model.v3_0_1.expandedlicensing.ListedLicenseException exception) Detect if a text contains the standard license exception (perhaps along with other text before and/or after)- Parameters:
text- The text to search within (should not be null)exception- The standard SPDX license exception to search for (should not be null)- Returns:
- True if the license exception is found within the text, false otherwise (or if either argument is null)
-
matchingStandardLicenseIds
public static String[] matchingStandardLicenseIds(String licenseText) throws org.spdx.core.InvalidSPDXAnalysisException, SpdxCompareException Returns 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:
org.spdx.core.InvalidSPDXAnalysisException- If an error occurs accessing the standard licensesSpdxCompareException- If an error occurs in the comparison
-
matchingStandardLicenseIdsWithinText
public static List<String> matchingStandardLicenseIdsWithinText(String text, List<String> licenseIds) throws org.spdx.core.InvalidSPDXAnalysisException Returns a list of SPDX Standard License ID's from the provided list that were found within the text, using the SPDX matching guidelines.- Parameters:
text- Text to compare tolicenseIds- License ids to compare against- Returns:
- List of SPDX standard license IDs from licenseIds that match
- Throws:
org.spdx.core.InvalidSPDXAnalysisException- If an error occurs accessing the standard licenses
-
matchingStandardLicenseIdsWithinText
public static List<String> matchingStandardLicenseIdsWithinText(String text) throws org.spdx.core.InvalidSPDXAnalysisException Returns a list of SPDX Standard License ID's that were found within the text, using the SPDX matching guidelines.- Parameters:
text- Text to compare to all the standard licenses- Returns:
- List of SPDX standard license IDs that match
- Throws:
org.spdx.core.InvalidSPDXAnalysisException- If an error occurs accessing the standard licenses
-
matchingStandardLicenseExceptionIdsWithinText
public static List<String> matchingStandardLicenseExceptionIdsWithinText(String text, List<String> licenseExceptionIds) throws org.spdx.core.InvalidSPDXAnalysisException Returns a list of SPDX Standard License Exception ID's from the provided list that were found within the text, using the SPDX matching guidelines.- Parameters:
text- Text to compare tolicenseExceptionIds- License Exceptions Ids to compare against- Returns:
- List of SPDX standard license exception IDs from licenseExceptionIds that match
- Throws:
org.spdx.core.InvalidSPDXAnalysisException- If an error occurs accessing the standard license exceptions
-
matchingStandardLicenseExceptionIdsWithinText
public static List<String> matchingStandardLicenseExceptionIdsWithinText(String text) throws org.spdx.core.InvalidSPDXAnalysisException Returns a list of SPDX Standard License Exception ID's that were found within the text, using the SPDX matching guidelines.- Parameters:
text- Text to compare to all the standard license exceptions- Returns:
- List of SPDX standard license exception IDs that match
- Throws:
org.spdx.core.InvalidSPDXAnalysisException- If an error occurs accessing the standard license exceptions
-
isLicensePassBlackList
public static boolean isLicensePassBlackList(org.spdx.library.model.v3_0_1.simplelicensing.AnyLicenseInfo license, String... blackList) Detect if a license pass black lists- Parameters:
license- licenseblackList- license black list- Returns:
- if the license pass black lists
-
isLicensePassWhiteList
public static boolean isLicensePassWhiteList(org.spdx.library.model.v3_0_1.simplelicensing.AnyLicenseInfo license, String... whiteList) Detect if a license pass white lists- Parameters:
license- licensewhiteList- license white list- Returns:
- if the license pass white lists
-
isLicenseEqual
public static boolean isLicenseEqual(org.spdx.library.model.v2.license.AnyLicenseInfo license1, org.spdx.library.model.v2.license.AnyLicenseInfo license2, Map<String, String> xlationMap) throws SpdxCompareException, org.spdx.core.InvalidSPDXAnalysisExceptionCompares two licenses from potentially two different documents which may have different license ID's for the same license- Parameters:
license1- first license to comparelicense2- second license to comparexlationMap- Mapping the license URIs from license 1 to license 2- Returns:
- true if the 2 licenses are equal
- Throws:
org.spdx.core.InvalidSPDXAnalysisException- If an error occurs accessing the standard license exceptionsSpdxCompareException- If an error occurs in the comparison
-
isTextStandardLicense
public static CompareTemplateOutputHandler.DifferenceDescription isTextStandardLicense(org.spdx.library.model.v2.license.License license, String compareText) throws SpdxCompareException, org.spdx.core.InvalidSPDXAnalysisException Compares 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:
org.spdx.core.InvalidSPDXAnalysisException- If an error occurs accessing the standard license exceptionsSpdxCompareException- If an error occurs in the comparison
-
isTextStandardException
public static CompareTemplateOutputHandler.DifferenceDescription isTextStandardException(org.spdx.library.model.v2.license.LicenseException exception, String compareText) throws SpdxCompareException, org.spdx.core.InvalidSPDXAnalysisException Compares 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:
org.spdx.core.InvalidSPDXAnalysisException- If an error occurs accessing the standard license exceptionsSpdxCompareException- If an error occurs in the comparison
-
isStandardLicenseWithinText
public static boolean isStandardLicenseWithinText(String text, org.spdx.library.model.v2.license.SpdxListedLicense license) Detect if a text contains the standard license (perhaps along with other text before and/or after)- Parameters:
text- The text to search within (should not be null)license- The standard SPDX license to search for (should not be null)- Returns:
- True if the license is found within the text, false otherwise (or if either argument is null)
-
isStandardLicenseExceptionWithinText
public static boolean isStandardLicenseExceptionWithinText(String text, org.spdx.library.model.v2.license.ListedLicenseException exception) Detect if a text contains the standard license exception (perhaps along with other text before and/or after)- Parameters:
text- The text to search within (should not be null)exception- The standard SPDX license exception to search for (should not be null)- Returns:
- True if the license exception is found within the text, false otherwise (or if either argument is null)
-
isLicensePassBlackList
public static boolean isLicensePassBlackList(org.spdx.library.model.v2.license.AnyLicenseInfo license, String... blackList) throws org.spdx.core.InvalidSPDXAnalysisException Detect if a license pass black lists- Parameters:
license- licenseblackList- license black list- Returns:
- if the license pass black lists
- Throws:
org.spdx.core.InvalidSPDXAnalysisException- If an error occurs accessing the standard license exceptions
-
isLicensePassWhiteList
public static boolean isLicensePassWhiteList(org.spdx.library.model.v2.license.AnyLicenseInfo license, String... whiteList) throws org.spdx.core.InvalidSPDXAnalysisException Detect if a license pass white lists- Parameters:
license- licensewhiteList- license white list- Returns:
- if the license pass white lists
- Throws:
org.spdx.core.InvalidSPDXAnalysisException- If an error occurs accessing the standard license exceptions
-