diff --git a/java-frontend/src/main/java/org/sonar/java/SonarComponents.java b/java-frontend/src/main/java/org/sonar/java/SonarComponents.java index 8cb2da7f07..73db258b20 100644 --- a/java-frontend/src/main/java/org/sonar/java/SonarComponents.java +++ b/java-frontend/src/main/java/org/sonar/java/SonarComponents.java @@ -341,6 +341,12 @@ private void registerCheckClasses(List destinationList, Checks classIndexes.getOrDefault(check.getClass(), Integer.MAX_VALUE))) .toList(); destinationList.addAll(orderedChecks); + if (LOG.isDebugEnabled()) { + LOG.debug("Registered check: [{}]", + orderedChecks.stream() + .map(c -> c.getClass().getSimpleName() + " (" + createdChecks.ruleKey(c) + ")") + .collect(Collectors.joining(", "))); + } jspChecks.addAll(orderedChecks.stream().filter(JspCodeVisitor.class::isInstance).toList()); } diff --git a/java-frontend/src/main/java/org/sonar/java/model/VisitorsBridge.java b/java-frontend/src/main/java/org/sonar/java/model/VisitorsBridge.java index 3e56970a3e..596c20a962 100644 --- a/java-frontend/src/main/java/org/sonar/java/model/VisitorsBridge.java +++ b/java-frontend/src/main/java/org/sonar/java/model/VisitorsBridge.java @@ -181,12 +181,21 @@ public boolean scanWithoutParsing(InputFile inputFile) { if (sonarComponents != null && sonarComponents.fileCanBeSkipped(inputFile)) { PerformanceMeasure.Duration duration = PerformanceMeasure.start("ScanWithoutParsing"); boolean allScansSucceeded = true; + + List scannersRequiringParsing = new ArrayList<>(); + List scannersNotRequiringParsing = new ArrayList<>(); + var fileScannerContext = createScannerContext(sonarComponents, inputFile, javaVersion, inAndroidContext, cacheContext); for (var scanner: scannersThatCannotBeSkipped) { boolean exceptionIsBlownUp = false; PerformanceMeasure.Duration scannerDuration = PerformanceMeasure.start(scanner); try { - allScansSucceeded &= scanner.scanWithoutParsing(fileScannerContext); + if (scanner.scanWithoutParsing(fileScannerContext)) { + scannersNotRequiringParsing.add(scanner); + } else { + scannersRequiringParsing.add(scanner); + allScansSucceeded = false; + } } catch (AnalysisException e) { // In the case where the IssuableSubscriptionVisitorsRunner throws an exception, the problem has already been // logged and the exception formatted. @@ -210,6 +219,10 @@ public boolean scanWithoutParsing(InputFile inputFile) { } } duration.stop(); + + LOG.trace("Scanners that do not require parsing of {}: {}", inputFile, scannersNotRequiringParsing); + LOG.debug("Scanners that require parsing of {}: {}", inputFile, scannersRequiringParsing); + return allScansSucceeded; } else { return false; diff --git a/java-frontend/src/test/java/org/sonar/java/SonarComponentsTest.java b/java-frontend/src/test/java/org/sonar/java/SonarComponentsTest.java index 87d999dec5..c7af71261a 100644 --- a/java-frontend/src/test/java/org/sonar/java/SonarComponentsTest.java +++ b/java-frontend/src/test/java/org/sonar/java/SonarComponentsTest.java @@ -226,6 +226,33 @@ void test_sonar_components() { assertThat(sonarComponents.getJavaClasspath()).isEqualTo(list); } + @Test + void verify_registration_logging_doesnt_trigger_on_info_level() { + logTester.setLevel(Level.INFO); + + JavaCheck expectedCheck = new CustomCheck(); + CheckRegistrar expectedRegistrar = getRegistrar(expectedCheck); + SonarComponents sonarComponents = new SonarComponents(this.fileLinesContextFactory, null, null, + null, this.checkFactory, context.activeRules(), new CheckRegistrar[]{expectedRegistrar}); + sonarComponents.setSensorContext(context); + + assertThat(logTester.getLogs()).isEmpty(); + } + + @Test + void verify_registration_logging() { + logTester.setLevel(Level.DEBUG); + + JavaCheck expectedCheck = new CustomCheck(); + CheckRegistrar expectedRegistrar = getRegistrar(expectedCheck); + SonarComponents sonarComponents = new SonarComponents(this.fileLinesContextFactory, null, null, + null, this.checkFactory, context.activeRules(), new CheckRegistrar[]{expectedRegistrar}); + sonarComponents.setSensorContext(context); + + assertThat(logTester.getLogs()).hasSize(2); + assertThat(logTester.getLogs().get(0).getRawMsg()).isEqualTo("Registered check: [{}]"); + } + @Test void creation_of_custom_checks() { JavaCheck expectedCheck = new CustomCheck();