LUCENE-10419: add debugging code.

This commit is contained in:
Dawid Weiss 2022-02-10 12:03:54 +01:00
parent 69d3a1d6af
commit 1f1da12c89
1 changed files with 51 additions and 45 deletions

View File

@ -203,58 +203,64 @@ class ValidateSourcePatternsTask extends DefaultTask {
ProgressLogger progress = progressLoggerFactory.newOperation(this.class)
progress.start(this.name, this.name)
sourceFiles.each{ f ->
progress.progress("Scanning ${f.name}")
logger.debug('Scanning source file: {}', f);
sourceFiles.each { f ->
try {
progress.progress("Scanning ${f.name}")
logger.debug('Scanning source file: {}', f);
def text = f.getText('UTF-8');
invalidPatterns.each { pattern, name ->
if (pattern.matcher(text).find()) {
reportViolation(f, name);
}
}
def javadocsMatcher = javadocsPattern.matcher(text);
def ratDocument = new FileDocument(f);
while (javadocsMatcher.find()) {
if (isLicense(javadocsMatcher, ratDocument)) {
reportViolation(f, String.format(Locale.ENGLISH, 'javadoc-style license header [%s]',
ratDocument.getMetaData().value(MetaData.RAT_URL_LICENSE_FAMILY_NAME)));
}
}
if (f.name.endsWith('.java')) {
if (text.contains('org.slf4j.LoggerFactory')) {
if (!validLoggerPattern.matcher(text).find()) {
reportViolation(f, 'invalid logging pattern [not private static final, uses static class name]');
}
if (!validLoggerNamePattern.matcher(text).find()) {
reportViolation(f, 'invalid logger name [log, uses static class name, not specialized logger]')
}
}
// make sure that SPI names of all tokenizers/charfilters/tokenfilters are documented
if (!f.name.contains("Test") && !f.name.contains("Mock") && !f.name.contains("Fake") && !text.contains("abstract class") &&
!f.name.equals("TokenizerFactory.java") && !f.name.equals("CharFilterFactory.java") && !f.name.equals("TokenFilterFactory.java") &&
(f.name.contains("TokenizerFactory") && text.contains("extends TokenizerFactory") ||
f.name.contains("CharFilterFactory") && text.contains("extends CharFilterFactory") ||
f.name.contains("FilterFactory") && text.contains("extends TokenFilterFactory"))) {
if (!validSPINameJavadocTag.matcher(text).find()) {
reportViolation(f, 'invalid spi name documentation')
}
}
checkLicenseHeaderPrecedes(f, 'package', packagePattern, javaCommentPattern, text, ratDocument);
if (f.name.contains("Test")) {
checkMockitoAssume(f, text);
}
invalidJavaOnlyPatterns.each { pattern,name ->
def text = f.getText('UTF-8');
invalidPatterns.each { pattern, name ->
if (pattern.matcher(text).find()) {
reportViolation(f, name);
}
}
}
if (f.name.endsWith('.xml')) {
checkLicenseHeaderPrecedes(f, '<tag>', xmlTagPattern, xmlCommentPattern, text, ratDocument);
def javadocsMatcher = javadocsPattern.matcher(text);
def ratDocument = new FileDocument(f);
while (javadocsMatcher.find()) {
if (isLicense(javadocsMatcher, ratDocument)) {
reportViolation(f, String.format(Locale.ENGLISH, 'javadoc-style license header [%s]',
ratDocument.getMetaData().value(MetaData.RAT_URL_LICENSE_FAMILY_NAME)));
}
}
if (f.name.endsWith('.java')) {
if (text.contains('org.slf4j.LoggerFactory')) {
if (!validLoggerPattern.matcher(text).find()) {
reportViolation(f, 'invalid logging pattern [not private static final, uses static class name]');
}
if (!validLoggerNamePattern.matcher(text).find()) {
reportViolation(f, 'invalid logger name [log, uses static class name, not specialized logger]')
}
}
// make sure that SPI names of all tokenizers/charfilters/tokenfilters are documented
if (!f.name.contains("Test") && !f.name.contains("Mock") && !f.name.contains("Fake") && !text.contains("abstract class") &&
!f.name.equals("TokenizerFactory.java") && !f.name.equals("CharFilterFactory.java") && !f.name.equals("TokenFilterFactory.java") &&
(f.name.contains("TokenizerFactory") && text.contains("extends TokenizerFactory") ||
f.name.contains("CharFilterFactory") && text.contains("extends CharFilterFactory") ||
f.name.contains("FilterFactory") && text.contains("extends TokenFilterFactory"))) {
if (!validSPINameJavadocTag.matcher(text).find()) {
reportViolation(f, 'invalid spi name documentation')
}
}
checkLicenseHeaderPrecedes(f, 'package', packagePattern, javaCommentPattern, text, ratDocument);
if (f.name.contains("Test")) {
checkMockitoAssume(f, text);
}
invalidJavaOnlyPatterns.each { pattern,name ->
if (pattern.matcher(text).find()) {
reportViolation(f, name);
}
}
}
if (f.name.endsWith('.xml')) {
checkLicenseHeaderPrecedes(f, '<tag>', xmlTagPattern, xmlCommentPattern, text, ratDocument);
}
} catch (e) {
e.printStackTrace()
throw new GradleException("Unhandled exception while validating patterns on file: " + f, e)
}
}
progress.completed()
if (!violations.isEmpty()) {