mirror of https://github.com/apache/lucene.git
LUCENE-10419: add debugging code.
This commit is contained in:
parent
69d3a1d6af
commit
1f1da12c89
|
@ -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()) {
|
||||
|
|
Loading…
Reference in New Issue