Class TemplateRegexMatcher
java.lang.Object
org.spdx.utility.compare.TemplateRegexMatcher
- All Implemented Interfaces:
org.spdx.licenseTemplate.ILicenseTemplateOutputHandler
public class TemplateRegexMatcher
extends Object
implements org.spdx.licenseTemplate.ILicenseTemplateOutputHandler
Constructs a regular expression from a license or exception template and provide a matching method
to see if code matching the template exists within the text provided
Note that the regular expression assumes a fully normalized text string to match
isTemplateMatchWithinText(String text) will return true if the text matches the template
getQuickMatchRegex() will return a regular expression with limited backtracking which can be used for a quick search
getCompleteRegex() will return a regular expression for the entire license where
getStartRegex(int wordLimit) will return a regular expression to match the beginning of a license
and getEndRegex(int wordLimit) will return a regular expression to match the end of a license
- Author:
- Gary O'Neall
-
Constructor Summary
ConstructorsConstructorDescriptionTemplateRegexMatcher(String template) Generates regular expressions from a license or exception template -
Method Summary
Modifier and TypeMethodDescriptionvoidbeginOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule) voidvoidendOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule) getEndRegex(int wordLimit) getQuickMatchRegex(int wordLimit) getStartRegex(int wordLimit) booleannormalizeText(String text) Normalizes text for use in the template matchervoidvoidvariableRule(org.spdx.licenseTemplate.LicenseTemplateRule rule)
-
Constructor Details
-
TemplateRegexMatcher
Generates regular expressions from a license or exception template- Throws:
SpdxCompareException- on compare errors
-
-
Method Details
-
getCompleteRegex
- Returns:
- the complete regular expression for the template
-
getQuickMatchRegex
- Parameters:
wordLimit- maximum number of contiguous words to match- Returns:
- a regular expression to match the template with minimum backtracking - avoiding optional and var tags
-
getStartRegex
- Parameters:
wordLimit- number of non-optional words to include in the pattern- Returns:
- a regex to match the start of the license per the template
-
getEndRegex
- Parameters:
wordLimit- number of non-optional words to include in the pattern- Returns:
- a regex to match the end of the license per the template
-
isTemplateMatchWithinText
public boolean isTemplateMatchWithinText(String text) throws SpdxCompareException, org.spdx.core.InvalidSPDXAnalysisException - Parameters:
text- text to search for a match- Returns:
- true if a match is found, otherwise false
- Throws:
SpdxCompareExceptionorg.spdx.core.InvalidSPDXAnalysisException
-
normalizeText
-
text
- Specified by:
textin interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
variableRule
public void variableRule(org.spdx.licenseTemplate.LicenseTemplateRule rule) - Specified by:
variableRulein interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
beginOptional
public void beginOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule) - Specified by:
beginOptionalin interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
endOptional
public void endOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule) - Specified by:
endOptionalin interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
completeParsing
public void completeParsing()- Specified by:
completeParsingin interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-