From d0b10f55b1ea1990587c9c714f13acd555ec2ebf Mon Sep 17 00:00:00 2001 From: Alban Auzeill Date: Tue, 22 Oct 2024 18:36:33 +0200 Subject: [PATCH] [NO JIRA] Update dependencies after the release --- docs/java-custom-rules-example/pom.xml | 8 +- .../checks/AvoidBrandInMethodNamesRule.java | 6 +- .../SecurityAnnotationMandatoryRule.java | 6 +- .../AvoidBrandInMethodNamesRuleTest.java | 6 +- .../SecurityAnnotationMandatoryRuleTest.java | 6 +- .../java/externalreport/CheckstyleSensor.java | 32 ++++-- .../sonar/java/externalreport/PmdSensor.java | 28 +++-- .../java/externalreport/SpotBugsSensor.java | 66 +++++++---- .../externalreport/CheckstyleSensorTest.java | 5 +- .../ExternalRulesDefinitionTest.java | 10 +- .../java/externalreport/PmdSensorTest.java | 7 +- .../externalreport/SpotBugsSensorTest.java | 9 +- its/autoscan/pom.xml | 2 +- .../java/org/sonar/java/it/AutoScanTest.java | 8 +- .../org/sonar/java/it/ProfileGenerator.java | 12 +- .../resources/autoscan/diffs/diff_S1874.json | 4 +- its/plugin/tests/pom.xml | 2 +- .../test/java/com/sonar/it/java/JspTest.java | 10 +- .../sonar/it/java/suite/CacheEnabledTest.java | 8 +- .../sonar/it/java/suite/DuplicationTest.java | 4 +- .../it/java/suite/ExternalReportTest.java | 4 +- .../it/java/suite/JavaClasspathTest.java | 4 +- .../it/java/suite/JavaComplexityTest.java | 5 +- .../it/java/suite/JavaExtensionsTest.java | 4 +- .../com/sonar/it/java/suite/JavaTest.java | 4 +- .../sonar/it/java/suite/JavaTestSuite.java | 8 +- .../sonar/it/java/suite/JavaTutorialTest.java | 4 +- .../sonar/it/java/suite/PackageInfoTest.java | 4 +- .../sonar/it/java/suite/Struts139Test.java | 4 +- .../it/java/suite/SuppressWarningTest.java | 4 +- .../com/sonar/it/java/suite/TestUtils.java | 10 +- .../sonar/it/java/suite/UnitTestsTest.java | 4 +- its/ruling/pom.xml | 2 +- .../org/sonar/java/it/JavaRulingTest.java | 12 +- .../org/sonar/java/it/ProfileGenerator.java | 10 +- .../internal/InternalSensorContext.java | 5 + .../java/org/sonar/java/JavaFrontendTest.java | 41 ++----- .../org/sonar/java/ProgressMonitorTest.java | 87 ++++---------- .../sonar/java/ast/JavaAstScannerTest.java | 17 ++- .../java/caching/CacheContextImplTest.java | 11 +- .../java/caching/ContentHashCacheTest.java | 33 ++---- .../test/java/org/sonar/java/cfg/CFGTest.java | 4 +- .../org/sonar/java/cfg/LiveVariablesTest.java | 2 +- .../java/classpath/ClasspathForMainTest.java | 12 +- .../java/classpath/ClasspathForTestTest.java | 6 +- .../sonar/java/model/GeneratedFileTest.java | 6 +- .../sonar/java/model/JParserConfigTest.java | 15 +-- .../org/sonar/java/model/JParserTest.java | 4 +- .../java/org/sonar/java/model/JTypeTest.java | 6 +- .../org/sonar/java/model/SmapFileTest.java | 4 +- .../sonar/java/model/VisitorsBridgeTest.java | 33 +++--- .../InternalJavaIssueBuilderTest.java | 4 +- .../java/testing/ThreadLocalLogTester.java | 107 ++++++++++++++++++ java-jsp/pom.xml | 2 +- .../RelationalSymbolicValueTest.java | 5 +- override-dep-licenses.properties | 10 -- pom.xml | 26 ++--- .../java/ExternalReportExtensions.java | 19 ++-- 58 files changed, 428 insertions(+), 353 deletions(-) create mode 100644 java-frontend/src/test/java/org/sonar/java/testing/ThreadLocalLogTester.java diff --git a/docs/java-custom-rules-example/pom.xml b/docs/java-custom-rules-example/pom.xml index 5371649f6d5..ef7e34d0f92 100644 --- a/docs/java-custom-rules-example/pom.xml +++ b/docs/java-custom-rules-example/pom.xml @@ -24,7 +24,7 @@ org.sonarsource.api.plugin sonar-plugin-api - 9.9.0.229 + 10.12.0.2522 provided @@ -46,6 +46,12 @@ + + org.sonarsource.api.plugin + sonar-plugin-api-test-fixtures + test + + org.sonarsource.java java-checks-testkit diff --git a/docs/java-custom-rules-example/src/main/java/org/sonar/samples/java/checks/AvoidBrandInMethodNamesRule.java b/docs/java-custom-rules-example/src/main/java/org/sonar/samples/java/checks/AvoidBrandInMethodNamesRule.java index 95b43317e8e..d5fbc7c0c0c 100644 --- a/docs/java-custom-rules-example/src/main/java/org/sonar/samples/java/checks/AvoidBrandInMethodNamesRule.java +++ b/docs/java-custom-rules-example/src/main/java/org/sonar/samples/java/checks/AvoidBrandInMethodNamesRule.java @@ -5,8 +5,8 @@ package org.sonar.samples.java.checks; import java.util.Locale; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.sonar.check.Rule; import org.sonar.plugins.java.api.JavaFileScanner; import org.sonar.plugins.java.api.JavaFileScannerContext; @@ -17,7 +17,7 @@ @Rule(key = "AvoidBrandInMethodNames") public class AvoidBrandInMethodNamesRule extends BaseTreeVisitor implements JavaFileScanner { - private static final Logger LOGGER = Loggers.get(AvoidBrandInMethodNamesRule.class); + private static final Logger LOGGER = LoggerFactory.getLogger(AvoidBrandInMethodNamesRule.class); private JavaFileScannerContext context; diff --git a/docs/java-custom-rules-example/src/main/java/org/sonar/samples/java/checks/SecurityAnnotationMandatoryRule.java b/docs/java-custom-rules-example/src/main/java/org/sonar/samples/java/checks/SecurityAnnotationMandatoryRule.java index d38d7b1defd..572761e1a63 100644 --- a/docs/java-custom-rules-example/src/main/java/org/sonar/samples/java/checks/SecurityAnnotationMandatoryRule.java +++ b/docs/java-custom-rules-example/src/main/java/org/sonar/samples/java/checks/SecurityAnnotationMandatoryRule.java @@ -5,8 +5,8 @@ package org.sonar.samples.java.checks; import java.util.List; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.sonar.check.Rule; import org.sonar.check.RuleProperty; import org.sonar.plugins.java.api.JavaFileScanner; @@ -26,7 +26,7 @@ @Rule(key = "SecurityAnnotationMandatory") public class SecurityAnnotationMandatoryRule extends BaseTreeVisitor implements JavaFileScanner { - private static final Logger LOGGER = Loggers.get(SecurityAnnotationMandatoryRule.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SecurityAnnotationMandatoryRule.class); private static final String DEFAULT_VALUE = "MySecurityAnnotation"; diff --git a/docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/AvoidBrandInMethodNamesRuleTest.java b/docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/AvoidBrandInMethodNamesRuleTest.java index 2009f5124d8..19e8f48246f 100644 --- a/docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/AvoidBrandInMethodNamesRuleTest.java +++ b/docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/AvoidBrandInMethodNamesRuleTest.java @@ -7,8 +7,8 @@ import org.junit.Rule; import org.junit.jupiter.api.Test; import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; -import org.sonar.api.utils.log.LogTester; -import org.sonar.api.utils.log.LoggerLevel; +import org.slf4j.event.Level; +import org.sonar.api.testfixtures.log.LogTester; import org.sonar.java.checks.verifier.CheckVerifier; @EnableRuleMigrationSupport @@ -16,7 +16,7 @@ class AvoidBrandInMethodNamesRuleTest { // Set a LogTester to see the Syntax Tree when running tests and executing the rule @Rule - public LogTester logTester = new LogTester().setLevel(LoggerLevel.DEBUG); + public LogTester logTester = new LogTester().setLevel(Level.DEBUG); @Test void detected() { diff --git a/docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/SecurityAnnotationMandatoryRuleTest.java b/docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/SecurityAnnotationMandatoryRuleTest.java index 6c051d7e6de..f9ebfff2fe4 100644 --- a/docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/SecurityAnnotationMandatoryRuleTest.java +++ b/docs/java-custom-rules-example/src/test/java/org/sonar/samples/java/checks/SecurityAnnotationMandatoryRuleTest.java @@ -7,8 +7,8 @@ import org.junit.Rule; import org.junit.jupiter.api.Test; import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; -import org.sonar.api.utils.log.LogTester; -import org.sonar.api.utils.log.LoggerLevel; +import org.slf4j.event.Level; +import org.sonar.api.testfixtures.log.LogTester; import org.sonar.java.checks.verifier.CheckVerifier; @EnableRuleMigrationSupport @@ -16,7 +16,7 @@ class SecurityAnnotationMandatoryRuleTest { // Set a LogTester to see the Syntax Tree when running tests and executing the rule @Rule - public LogTester logTester = new LogTester().setLevel(LoggerLevel.DEBUG); + public LogTester logTester = new LogTester().setLevel(Level.DEBUG); @Test void detected() { diff --git a/external-reports/src/main/java/org/sonar/java/externalreport/CheckstyleSensor.java b/external-reports/src/main/java/org/sonar/java/externalreport/CheckstyleSensor.java index a27ceb2849e..4a522173008 100644 --- a/external-reports/src/main/java/org/sonar/java/externalreport/CheckstyleSensor.java +++ b/external-reports/src/main/java/org/sonar/java/externalreport/CheckstyleSensor.java @@ -25,6 +25,7 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.api.SonarRuntime; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; @@ -43,11 +44,20 @@ public class CheckstyleSensor implements Sensor { public static final String REPORT_PROPERTY_KEY = "sonar.java.checkstyle.reportPaths"; public static final String LINTER_KEY = "checkstyle"; - public static final ExternalRuleLoader RULE_LOADER = new ExternalRuleLoader( - CheckstyleSensor.LINTER_KEY, - CheckstyleSensor.LINTER_NAME, - "org/sonar/l10n/java/rules/checkstyle/rules.json", - CheckstyleSensor.LANGUAGE_KEY); + private final ExternalRuleLoader ruleLoader; + + public CheckstyleSensor(SonarRuntime sonarRuntime) { + ruleLoader = new ExternalRuleLoader( + CheckstyleSensor.LINTER_KEY, + CheckstyleSensor.LINTER_NAME, + "org/sonar/l10n/java/rules/checkstyle/rules.json", + CheckstyleSensor.LANGUAGE_KEY, + sonarRuntime); + } + + public ExternalRuleLoader ruleLoader() { + return ruleLoader; + } @Override public void describe(SensorDescriptor descriptor) { @@ -60,20 +70,20 @@ public void describe(SensorDescriptor descriptor) { @Override public void execute(SensorContext context) { List reportFiles = ExternalReportProvider.getReportFiles(context, REPORT_PROPERTY_KEY); - reportFiles.forEach(report -> importIfExist(LINTER_NAME, context, report, CheckstyleSensor::importReport)); + reportFiles.forEach(report -> importIfExist(LINTER_NAME, context, report, this::importReport)); } - private static void importReport(File reportPath, SensorContext context) { + private void importReport(File reportPath, SensorContext context) { try (InputStream in = new FileInputStream(reportPath)) { LOG.info("Importing {}", reportPath); - CheckstyleXmlReportReader.read(context, in, CheckstyleSensor::saveIssue); + CheckstyleXmlReportReader.read(context, in, this::saveIssue); } catch (Exception e) { - LOG.error("Failed to import external issues report: " + reportPath, e); + LOG.error("Failed to import external issues report: {}", reportPath, e); } } - private static void saveIssue(SensorContext context, InputFile inputFile, String key, String line, String message) { - ExternalIssueUtils.saveIssue(context, RULE_LOADER, inputFile, CheckstyleSensor.LINTER_KEY, key, line, message); + private void saveIssue(SensorContext context, InputFile inputFile, String key, String line, String message) { + ExternalIssueUtils.saveIssue(context, ruleLoader, inputFile, CheckstyleSensor.LINTER_KEY, key, line, message); } } diff --git a/external-reports/src/main/java/org/sonar/java/externalreport/PmdSensor.java b/external-reports/src/main/java/org/sonar/java/externalreport/PmdSensor.java index 905e3fcbbeb..f2f99d5a2e8 100644 --- a/external-reports/src/main/java/org/sonar/java/externalreport/PmdSensor.java +++ b/external-reports/src/main/java/org/sonar/java/externalreport/PmdSensor.java @@ -23,6 +23,7 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.api.SonarRuntime; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; @@ -41,11 +42,20 @@ public class PmdSensor implements Sensor { private static final String LINTER_NAME = "PMD"; private static final String LANGUAGE_KEY = "java"; - public static final ExternalRuleLoader RULE_LOADER = new ExternalRuleLoader( - PmdSensor.LINTER_KEY, - PmdSensor.LINTER_NAME, - "org/sonar/l10n/java/rules/pmd/rules.json", - PmdSensor.LANGUAGE_KEY); + private final ExternalRuleLoader ruleLoader; + + public PmdSensor(SonarRuntime sonarRuntime) { + ruleLoader = new ExternalRuleLoader( + PmdSensor.LINTER_KEY, + PmdSensor.LINTER_NAME, + "org/sonar/l10n/java/rules/pmd/rules.json", + PmdSensor.LANGUAGE_KEY, + sonarRuntime); + } + + public ExternalRuleLoader ruleLoader() { + return ruleLoader; + } @Override public void describe(SensorDescriptor descriptor) { @@ -58,15 +68,15 @@ public void describe(SensorDescriptor descriptor) { @Override public void execute(SensorContext context) { List reportFiles = ExternalReportProvider.getReportFiles(context, REPORT_PROPERTY_KEY); - reportFiles.forEach(report -> importIfExist(LINTER_NAME, context, report, PmdSensor::importReport)); + reportFiles.forEach(report -> importIfExist(LINTER_NAME, context, report, this::importReport)); } - private static void importReport(File reportFile, SensorContext context) { + private void importReport(File reportFile, SensorContext context) { try { LOG.info("Importing {}", reportFile); - PmdXmlReportReader.read(context, reportFile, RULE_LOADER); + PmdXmlReportReader.read(context, reportFile, ruleLoader); } catch (Exception e) { - LOG.error("Failed to import external issues report: " + reportFile.getAbsolutePath(), e); + LOG.error("Failed to import external issues report: {}", reportFile.getAbsolutePath(), e); } } diff --git a/external-reports/src/main/java/org/sonar/java/externalreport/SpotBugsSensor.java b/external-reports/src/main/java/org/sonar/java/externalreport/SpotBugsSensor.java index 11211179d62..7c4d98f7766 100644 --- a/external-reports/src/main/java/org/sonar/java/externalreport/SpotBugsSensor.java +++ b/external-reports/src/main/java/org/sonar/java/externalreport/SpotBugsSensor.java @@ -27,6 +27,7 @@ import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.api.SonarRuntime; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; @@ -49,23 +50,46 @@ public class SpotBugsSensor implements Sensor { private static final String LANGUAGE_KEY = "java"; public static final String REPORT_PROPERTY_KEY = "sonar.java.spotbugs.reportPaths"; - public static final ExternalRuleLoader RULE_LOADER = new ExternalRuleLoader( - SpotBugsSensor.SPOTBUGS_KEY, - SpotBugsSensor.SPOTBUGS_NAME, - "org/sonar/l10n/java/rules/spotbugs/spotbugs-rules.json", - SpotBugsSensor.LANGUAGE_KEY); + private final ExternalRuleLoader ruleLoader; - public static final ExternalRuleLoader FINDSECBUGS_LOADER = new ExternalRuleLoader( - SpotBugsSensor.FINDSECBUGS_KEY, - SpotBugsSensor.FINDSECBUGS_NAME, - "org/sonar/l10n/java/rules/spotbugs/findsecbugs-rules.json", - SpotBugsSensor.LANGUAGE_KEY); + private final ExternalRuleLoader findSecBugsLoader; - public static final ExternalRuleLoader FBCONTRIB_LOADER = new ExternalRuleLoader( - SpotBugsSensor.FBCONTRIB_KEY, - SpotBugsSensor.FBCONTRIB_NAME, - "org/sonar/l10n/java/rules/spotbugs/fbcontrib-rules.json", - SpotBugsSensor.LANGUAGE_KEY); + private final ExternalRuleLoader fbContribLoader; + + public SpotBugsSensor(SonarRuntime sonarRuntime) { + ruleLoader = new ExternalRuleLoader( + SpotBugsSensor.SPOTBUGS_KEY, + SpotBugsSensor.SPOTBUGS_NAME, + "org/sonar/l10n/java/rules/spotbugs/spotbugs-rules.json", + SpotBugsSensor.LANGUAGE_KEY, + sonarRuntime); + + findSecBugsLoader = new ExternalRuleLoader( + SpotBugsSensor.FINDSECBUGS_KEY, + SpotBugsSensor.FINDSECBUGS_NAME, + "org/sonar/l10n/java/rules/spotbugs/findsecbugs-rules.json", + SpotBugsSensor.LANGUAGE_KEY, + sonarRuntime); + + fbContribLoader = new ExternalRuleLoader( + SpotBugsSensor.FBCONTRIB_KEY, + SpotBugsSensor.FBCONTRIB_NAME, + "org/sonar/l10n/java/rules/spotbugs/fbcontrib-rules.json", + SpotBugsSensor.LANGUAGE_KEY, + sonarRuntime); + } + + public ExternalRuleLoader ruleLoader() { + return ruleLoader; + } + + public ExternalRuleLoader findSecBugsLoader() { + return findSecBugsLoader; + } + + public ExternalRuleLoader fbContribLoader() { + return fbContribLoader; + } @Override public void describe(SensorDescriptor descriptor) { @@ -78,19 +102,19 @@ public void describe(SensorDescriptor descriptor) { @Override public void execute(SensorContext context) { List reportFiles = ExternalReportProvider.getReportFiles(context, REPORT_PROPERTY_KEY); - reportFiles.forEach(report -> importIfExist(SPOTBUGS_NAME, context, report, SpotBugsSensor::importReport)); + reportFiles.forEach(report -> importIfExist(SPOTBUGS_NAME, context, report, this::importReport)); } - private static void importReport(File reportPath, SensorContext context) { + private void importReport(File reportPath, SensorContext context) { try (InputStream in = new FileInputStream(reportPath)) { LOG.info("Importing {}", reportPath); Map otherLoaders = new HashMap<>(); - otherLoaders.put(FINDSECBUGS_KEY, FINDSECBUGS_LOADER); - otherLoaders.put(FBCONTRIB_KEY, FBCONTRIB_LOADER); - SpotBugsXmlReportReader.read(context, in, RULE_LOADER, otherLoaders); + otherLoaders.put(FINDSECBUGS_KEY, findSecBugsLoader); + otherLoaders.put(FBCONTRIB_KEY, fbContribLoader); + SpotBugsXmlReportReader.read(context, in, ruleLoader, otherLoaders); } catch (Exception e) { - LOG.error("Failed to import external issues report: " + reportPath, e); + LOG.error("Failed to import external issues report: {}", reportPath, e); } } diff --git a/external-reports/src/test/java/org/sonar/java/externalreport/CheckstyleSensorTest.java b/external-reports/src/test/java/org/sonar/java/externalreport/CheckstyleSensorTest.java index d857d5e115c..c808b610a9b 100644 --- a/external-reports/src/test/java/org/sonar/java/externalreport/CheckstyleSensorTest.java +++ b/external-reports/src/test/java/org/sonar/java/externalreport/CheckstyleSensorTest.java @@ -51,7 +51,8 @@ class CheckstyleSensorTest { private static final Path PROJECT_DIR = Paths.get("src", "test", "resources", "checkstyle") .toAbsolutePath().normalize(); - private static CheckstyleSensor checkstyleSensor = new CheckstyleSensor(); + private static SensorContextTester sensorContext = SensorContextTester.create(PROJECT_DIR); + private static CheckstyleSensor checkstyleSensor = new CheckstyleSensor(sensorContext.runtime()); @Rule public final TemporaryFolder tmp = new TemporaryFolder(); @@ -62,7 +63,7 @@ class CheckstyleSensorTest { @Test void checkstyle_rules_definition() { RulesDefinition.Context context = new RulesDefinition.Context(); - new ExternalRulesDefinition(CheckstyleSensor.RULE_LOADER, CheckstyleSensor.LINTER_KEY).define(context); + new ExternalRulesDefinition(checkstyleSensor.ruleLoader(), CheckstyleSensor.LINTER_KEY).define(context); assertThat(context.repositories()).hasSize(1); RulesDefinition.Repository repository = context.repository("external_checkstyle"); diff --git a/external-reports/src/test/java/org/sonar/java/externalreport/ExternalRulesDefinitionTest.java b/external-reports/src/test/java/org/sonar/java/externalreport/ExternalRulesDefinitionTest.java index b07428eaeee..afb6375f450 100644 --- a/external-reports/src/test/java/org/sonar/java/externalreport/ExternalRulesDefinitionTest.java +++ b/external-reports/src/test/java/org/sonar/java/externalreport/ExternalRulesDefinitionTest.java @@ -19,15 +19,23 @@ */ package org.sonar.java.externalreport; +import java.nio.file.Path; +import java.nio.file.Paths; import org.junit.jupiter.api.Test; +import org.sonar.api.batch.sensor.internal.SensorContextTester; import static org.assertj.core.api.Assertions.assertThat; class ExternalRulesDefinitionTest { + private static final Path PROJECT_DIR = Paths.get("src", "test", "resources", "spotbugs") + .toAbsolutePath().normalize(); + @Test void toString_should_exist_and_contains_linter_name() { // to string is used by compute engine logs and should return a unique key - assertThat(new ExternalRulesDefinition(SpotBugsSensor.RULE_LOADER, "someLinterKey")).hasToString("someLinterKey-rules-definition"); + SensorContextTester sensorContext = SensorContextTester.create(PROJECT_DIR); + var spotBugsSensor = new SpotBugsSensor(sensorContext.runtime()); + assertThat(new ExternalRulesDefinition(spotBugsSensor.ruleLoader(), "someLinterKey")).hasToString("someLinterKey-rules-definition"); } } diff --git a/external-reports/src/test/java/org/sonar/java/externalreport/PmdSensorTest.java b/external-reports/src/test/java/org/sonar/java/externalreport/PmdSensorTest.java index 879481f84ac..69ce5830647 100644 --- a/external-reports/src/test/java/org/sonar/java/externalreport/PmdSensorTest.java +++ b/external-reports/src/test/java/org/sonar/java/externalreport/PmdSensorTest.java @@ -52,7 +52,8 @@ class PmdSensorTest { private static final Path PROJECT_DIR = Paths.get("src", "test", "resources", "pmd"); private static final String PROJECT_ID = "pmd-test"; - private static final PmdSensor sensor = new PmdSensor(); + private static final SensorContextTester sensorContext = SensorContextTester.create(PROJECT_DIR); + private static final PmdSensor sensor = new PmdSensor(sensorContext.runtime()); @RegisterExtension public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); @@ -72,7 +73,7 @@ void test_descriptor() { @Test void pmd_rules_definition() { RulesDefinition.Context context = new RulesDefinition.Context(); - new ExternalRulesDefinition(PmdSensor.RULE_LOADER, PmdSensor.LINTER_KEY).define(context); + new ExternalRulesDefinition(sensor.ruleLoader(), PmdSensor.LINTER_KEY).define(context); assertThat(context.repositories()).hasSize(1); RulesDefinition.Repository repository = context.repository("external_pmd"); @@ -210,7 +211,7 @@ private static void addFileToContext(SensorContextTester context, Path projectDi context.fileSystem().add(TestInputFileBuilder.create(PROJECT_ID, projectDir.toFile(), file.toFile()) .setCharset(UTF_8) .setLanguage(language(file)) - .setContents(new String(Files.readAllBytes(file), UTF_8)) + .setContents(Files.readString(file)) .setType(InputFile.Type.MAIN) .build()); } catch (IOException e) { diff --git a/external-reports/src/test/java/org/sonar/java/externalreport/SpotBugsSensorTest.java b/external-reports/src/test/java/org/sonar/java/externalreport/SpotBugsSensorTest.java index 956a7d0c6fd..6bb36c7540a 100644 --- a/external-reports/src/test/java/org/sonar/java/externalreport/SpotBugsSensorTest.java +++ b/external-reports/src/test/java/org/sonar/java/externalreport/SpotBugsSensorTest.java @@ -52,7 +52,8 @@ class SpotBugsSensorTest { private static final Path PROJECT_DIR = Paths.get("src", "test", "resources", "spotbugs") .toAbsolutePath().normalize(); - private static SpotBugsSensor spotBugsSensor = new SpotBugsSensor(); + private static SensorContextTester sensorContext = SensorContextTester.create(PROJECT_DIR); + private static SpotBugsSensor spotBugsSensor = new SpotBugsSensor(sensorContext.runtime()); @Rule public final TemporaryFolder tmp = new TemporaryFolder(); @@ -63,9 +64,9 @@ class SpotBugsSensorTest { @Test void spotbugs_rules_definition() { RulesDefinition.Context context = new RulesDefinition.Context(); - new ExternalRulesDefinition(SpotBugsSensor.RULE_LOADER, SpotBugsSensor.SPOTBUGS_KEY).define(context); - new ExternalRulesDefinition(SpotBugsSensor.FINDSECBUGS_LOADER, SpotBugsSensor.FINDSECBUGS_KEY).define(context); - new ExternalRulesDefinition(SpotBugsSensor.FBCONTRIB_LOADER, SpotBugsSensor.FBCONTRIB_KEY).define(context); + new ExternalRulesDefinition(spotBugsSensor.ruleLoader(), SpotBugsSensor.SPOTBUGS_KEY).define(context); + new ExternalRulesDefinition(spotBugsSensor.findSecBugsLoader(), SpotBugsSensor.FINDSECBUGS_KEY).define(context); + new ExternalRulesDefinition(spotBugsSensor.fbContribLoader(), SpotBugsSensor.FBCONTRIB_KEY).define(context); assertThat(context.repositories()).hasSize(3); RulesDefinition.Repository repository = context.repository("external_spotbugs"); diff --git a/its/autoscan/pom.xml b/its/autoscan/pom.xml index f9fb7f554ac..b5215693e9e 100644 --- a/its/autoscan/pom.xml +++ b/its/autoscan/pom.xml @@ -52,7 +52,7 @@ org.sonarsource.orchestrator - sonar-orchestrator + sonar-orchestrator-junit4 ${orchestrator.version} test diff --git a/its/autoscan/src/test/java/org/sonar/java/it/AutoScanTest.java b/its/autoscan/src/test/java/org/sonar/java/it/AutoScanTest.java index fe86c4fdfd2..8e8bc4ba87c 100644 --- a/its/autoscan/src/test/java/org/sonar/java/it/AutoScanTest.java +++ b/its/autoscan/src/test/java/org/sonar/java/it/AutoScanTest.java @@ -23,9 +23,9 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.MavenBuild; import com.sonar.orchestrator.build.SonarScanner; +import com.sonar.orchestrator.junit4.OrchestratorRule; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.locator.MavenLocation; import java.lang.reflect.Type; @@ -65,7 +65,7 @@ public class AutoScanTest { public static TemporaryFolder tmpDumpOldFolder = new TemporaryFolder(); @ClassRule - public static Orchestrator orchestrator = Orchestrator.builderEnv() + public static OrchestratorRule orchestrator = OrchestratorRule.builderEnv() .useDefaultAdminCredentialsForBuilds(true) .setSonarVersion(System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE")) .addPlugin(FileLocation.of(TestClasspathUtils.findModuleJarPath("../../sonar-java-plugin").toFile())) @@ -198,7 +198,7 @@ public void javaCheckTestSources() throws Exception { SoftAssertions softly = new SoftAssertions(); softly.assertThat(newDiffs).containsExactlyInAnyOrderElementsOf(knownDiffs.values()); softly.assertThat(newTotal).isEqualTo(knownTotal); - softly.assertThat(rulesCausingFPs).hasSize(10); + softly.assertThat(rulesCausingFPs).hasSize(11); softly.assertThat(rulesNotReporting).hasSize(10); /** @@ -226,7 +226,7 @@ private static String absolutePathFor(String path) { return FileLocation.of(path).getFile().getAbsolutePath(); } - private static List generateSonarWay(Orchestrator orchestrator) { + private static List generateSonarWay(OrchestratorRule orchestrator) { Set results = new TreeSet<>(RULE_KEY_COMPARATOR); ProfileGenerator.generate(orchestrator, "Sonar Way", ImmutableMap.of(), Collections.emptySet(), Collections.emptySet(), results); return new ArrayList<>(results); diff --git a/its/autoscan/src/test/java/org/sonar/java/it/ProfileGenerator.java b/its/autoscan/src/test/java/org/sonar/java/it/ProfileGenerator.java index ff104c0fa0b..af45f656e61 100644 --- a/its/autoscan/src/test/java/org/sonar/java/it/ProfileGenerator.java +++ b/its/autoscan/src/test/java/org/sonar/java/it/ProfileGenerator.java @@ -21,8 +21,8 @@ import com.google.common.collect.ImmutableMap; import com.google.common.io.Files; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.container.Server; +import com.sonar.orchestrator.junit4.OrchestratorRule; import com.sonar.orchestrator.locator.FileLocation; import java.io.File; import java.io.IOException; @@ -50,7 +50,7 @@ public class ProfileGenerator { private static final Logger LOG = LoggerFactory.getLogger(ProfileGenerator.class); - static void generate(Orchestrator orchestrator, ImmutableMap> rulesParameters, + static void generate(OrchestratorRule orchestrator, ImmutableMap> rulesParameters, Set excluded, Set subsetOfEnabledRules, Set activatedRuleKeys) { generate(orchestrator, null, rulesParameters, excluded, subsetOfEnabledRules, activatedRuleKeys); } @@ -58,7 +58,7 @@ static void generate(Orchestrator orchestrator, ImmutableMap> rulesParameters, + static void generate(OrchestratorRule orchestrator, @Nullable String qualityProfile, ImmutableMap> rulesParameters, Set excluded, Set subsetOfEnabledRules, Set activatedRuleKeys) { try { LOG.info("Generating profile containing all the rules"); @@ -103,7 +103,7 @@ static void generate(Orchestrator orchestrator, @Nullable String qualityProfile, } } - private static List getRuleKeys(Orchestrator orchestrator, @Nullable String qualityProfile) { + private static List getRuleKeys(OrchestratorRule orchestrator, @Nullable String qualityProfile) { List ruleKeys = new ArrayList<>(); // pages are 1-based int currentPage = 1; @@ -137,7 +137,7 @@ private static List getRuleKeys(Orchestrator orchestrator, @Nullable Str return ruleKeys; } - private static Optional getQualityProfileName(Orchestrator orchestrator, @Nullable String qualityProfile) { + private static Optional getQualityProfileName(OrchestratorRule orchestrator, @Nullable String qualityProfile) { if (qualityProfile == null || qualityProfile.isEmpty()) { return Optional.empty(); } @@ -149,7 +149,7 @@ private static Optional getQualityProfileName(Orchestrator orchestrator, .findFirst(); } - static WsClient newAdminWsClient(Orchestrator orchestrator) { + static WsClient newAdminWsClient(OrchestratorRule orchestrator) { return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder() .credentials(Server.ADMIN_LOGIN, Server.ADMIN_PASSWORD) .url(orchestrator.getServer().getUrl()) diff --git a/its/autoscan/src/test/resources/autoscan/diffs/diff_S1874.json b/its/autoscan/src/test/resources/autoscan/diffs/diff_S1874.json index f8861aadfeb..3f8c8ab4714 100644 --- a/its/autoscan/src/test/resources/autoscan/diffs/diff_S1874.json +++ b/its/autoscan/src/test/resources/autoscan/diffs/diff_S1874.json @@ -2,5 +2,5 @@ "ruleKey": "S1874", "hasTruePositives": true, "falseNegatives": 246, - "falsePositives": 0 -} \ No newline at end of file + "falsePositives": 1 +} diff --git a/its/plugin/tests/pom.xml b/its/plugin/tests/pom.xml index 32d4206c307..48b517cf1b0 100644 --- a/its/plugin/tests/pom.xml +++ b/its/plugin/tests/pom.xml @@ -21,7 +21,7 @@ org.sonarsource.orchestrator - sonar-orchestrator + sonar-orchestrator-junit4 ${orchestrator.version} test diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/JspTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/JspTest.java index 1ee11d7a69d..27a8775b916 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/JspTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/JspTest.java @@ -21,10 +21,10 @@ import com.sonar.it.java.suite.JavaTestSuite; import com.sonar.it.java.suite.TestUtils; -import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.OrchestratorBuilder; import com.sonar.orchestrator.build.MavenBuild; import com.sonar.orchestrator.container.Edition; +import com.sonar.orchestrator.junit4.OrchestratorRule; +import com.sonar.orchestrator.junit4.OrchestratorRuleBuilder; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.locator.MavenLocation; import java.nio.file.Files; @@ -44,13 +44,13 @@ public static boolean isCommunityEditionTestsOnly() { } @ClassRule - public static final Orchestrator ENTERPRISE_ORCHESTRATOR_OR_NULL = getEnterpriseOrchestratorOrNull(); + public static final OrchestratorRule ENTERPRISE_ORCHESTRATOR_OR_NULL = getEnterpriseOrchestratorOrNull(); - private static Orchestrator getEnterpriseOrchestratorOrNull() { + private static OrchestratorRule getEnterpriseOrchestratorOrNull() { if (isCommunityEditionTestsOnly()) { return null; } - OrchestratorBuilder orchestratorBuilder = Orchestrator.builderEnv() + OrchestratorRuleBuilder orchestratorBuilder = OrchestratorRule.builderEnv() .useDefaultAdminCredentialsForBuilds(true) .setSonarVersion(System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE")) .setEdition(Edition.ENTERPRISE) diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/CacheEnabledTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/CacheEnabledTest.java index 36bce7007b3..af0b727bd3e 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/CacheEnabledTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/CacheEnabledTest.java @@ -19,9 +19,9 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.SonarScanner; +import com.sonar.orchestrator.junit4.OrchestratorRule; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.locator.MavenLocation; import org.junit.Rule; @@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class CacheEnabledTest { - @Rule public Orchestrator orchestrator = initServer(); + @Rule public OrchestratorRule orchestrator = initServer(); @Test public void test_cache_is_enabled() { @@ -64,8 +64,8 @@ public void test_cache_is_disabled() { - private static Orchestrator initServer() { - return Orchestrator.builderEnv() + private static OrchestratorRule initServer() { + return OrchestratorRule.builderEnv() .useDefaultAdminCredentialsForBuilds(true) .setSonarVersion(System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE")) .addPlugin(JavaTestSuite.JAVA_PLUGIN_LOCATION) diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/DuplicationTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/DuplicationTest.java index c992b286683..290b8878c58 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/DuplicationTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/DuplicationTest.java @@ -19,8 +19,8 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.MavenBuild; +import com.sonar.orchestrator.junit4.OrchestratorRule; import org.junit.ClassRule; import org.junit.Test; @@ -33,7 +33,7 @@ public class DuplicationTest { private static final String DUPLICATION_PROJECT_KEY = "org.sonarsource.it.projects:test-duplications"; @ClassRule - public static Orchestrator orchestrator = JavaTestSuite.ORCHESTRATOR; + public static OrchestratorRule orchestrator = JavaTestSuite.ORCHESTRATOR; @Test public void duplication_should_be_computed_by_SQ() { diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/ExternalReportTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/ExternalReportTest.java index 3ac9278f258..597ef5b72fe 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/ExternalReportTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/ExternalReportTest.java @@ -19,8 +19,8 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.MavenBuild; +import com.sonar.orchestrator.junit4.OrchestratorRule; import java.io.File; import java.util.List; import org.junit.ClassRule; @@ -34,7 +34,7 @@ public class ExternalReportTest { @ClassRule - public static Orchestrator orchestrator = JavaTestSuite.ORCHESTRATOR; + public static OrchestratorRule orchestrator = JavaTestSuite.ORCHESTRATOR; @Test public void checkstyle() { diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaClasspathTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaClasspathTest.java index 7cd7b787353..5f9683283c6 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaClasspathTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaClasspathTest.java @@ -19,10 +19,10 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.MavenBuild; import com.sonar.orchestrator.build.SonarScanner; +import com.sonar.orchestrator.junit4.OrchestratorRule; import com.sonar.orchestrator.locator.MavenLocation; import java.io.File; import java.nio.file.Path; @@ -50,7 +50,7 @@ public class JavaClasspathTest { private static final String PROJECT_KEY_AAR = "org.example:using-aar-dep"; @ClassRule - public static final Orchestrator ORCHESTRATOR = JavaTestSuite.ORCHESTRATOR; + public static final OrchestratorRule ORCHESTRATOR = JavaTestSuite.ORCHESTRATOR; @Rule public final TemporaryFolder tmp = new TemporaryFolder(); diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaComplexityTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaComplexityTest.java index 0a08db6b936..f5670fc52ad 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaComplexityTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaComplexityTest.java @@ -19,9 +19,8 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.MavenBuild; - +import com.sonar.orchestrator.junit4.OrchestratorRule; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -39,7 +38,7 @@ public class JavaComplexityTest { public static final String PROJECT = "org.sonarsource.it.projects:java-complexity"; @ClassRule - public static Orchestrator orchestrator = JavaTestSuite.ORCHESTRATOR; + public static OrchestratorRule orchestrator = JavaTestSuite.ORCHESTRATOR; @BeforeClass public static void analyzeProject() { diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaExtensionsTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaExtensionsTest.java index 8fffa78fa6a..7a763ce2019 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaExtensionsTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaExtensionsTest.java @@ -19,8 +19,8 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.MavenBuild; +import com.sonar.orchestrator.junit4.OrchestratorRule; import java.util.List; import org.junit.ClassRule; import org.junit.Test; @@ -31,7 +31,7 @@ public class JavaExtensionsTest { @ClassRule - public static Orchestrator orchestrator = JavaTestSuite.ORCHESTRATOR; + public static OrchestratorRule orchestrator = JavaTestSuite.ORCHESTRATOR; @Test public void test() { diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTest.java index 6fc466831d3..a461b26a445 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTest.java @@ -19,10 +19,10 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.MavenBuild; import com.sonar.orchestrator.build.SonarScanner; +import com.sonar.orchestrator.junit4.OrchestratorRule; import com.sonar.orchestrator.locator.MavenLocation; import java.io.File; import java.util.List; @@ -40,7 +40,7 @@ public class JavaTest { @ClassRule - public static Orchestrator orchestrator = JavaTestSuite.ORCHESTRATOR; + public static OrchestratorRule orchestrator = JavaTestSuite.ORCHESTRATOR; @Rule public final TemporaryFolder tmp = new TemporaryFolder(); diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTestSuite.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTestSuite.java index 457093d2c5d..61a6ff42a70 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTestSuite.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTestSuite.java @@ -19,8 +19,8 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.OrchestratorBuilder; +import com.sonar.orchestrator.junit4.OrchestratorRule; +import com.sonar.orchestrator.junit4.OrchestratorRuleBuilder; import com.sonar.orchestrator.locator.FileLocation; import java.util.List; import java.util.Map; @@ -61,10 +61,10 @@ public class JavaTestSuite { public static final FileLocation TUTORIAL_EXAMPLE_PLUGIN_LOCATION = FileLocation.of(TestClasspathUtils.findModuleJarPath("../../../docs/java-custom-rules-example").toFile()); @ClassRule - public static final Orchestrator ORCHESTRATOR; + public static final OrchestratorRule ORCHESTRATOR; static { - OrchestratorBuilder orchestratorBuilder = Orchestrator.builderEnv() + OrchestratorRuleBuilder orchestratorBuilder = OrchestratorRule.builderEnv() .useDefaultAdminCredentialsForBuilds(true) .setSonarVersion(System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE")) .addPlugin(JAVA_PLUGIN_LOCATION) diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTutorialTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTutorialTest.java index 65ac14df3f6..04726a14b8c 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTutorialTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/JavaTutorialTest.java @@ -19,8 +19,8 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.MavenBuild; +import com.sonar.orchestrator.junit4.OrchestratorRule; import java.util.List; import java.util.stream.Stream; import org.junit.ClassRule; @@ -32,7 +32,7 @@ public class JavaTutorialTest { @ClassRule - public static Orchestrator orchestrator = JavaTestSuite.ORCHESTRATOR; + public static OrchestratorRule orchestrator = JavaTestSuite.ORCHESTRATOR; @Test public void test() { diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/PackageInfoTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/PackageInfoTest.java index 1bf102dc649..acd2733f88b 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/PackageInfoTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/PackageInfoTest.java @@ -19,8 +19,8 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.MavenBuild; +import com.sonar.orchestrator.junit4.OrchestratorRule; import java.util.List; import java.util.regex.Pattern; import org.junit.ClassRule; @@ -33,7 +33,7 @@ public class PackageInfoTest { @ClassRule - public static Orchestrator orchestrator = JavaTestSuite.ORCHESTRATOR; + public static OrchestratorRule orchestrator = JavaTestSuite.ORCHESTRATOR; @Test public void should_detect_package_info_issues() { diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/Struts139Test.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/Struts139Test.java index ed24ff5884e..cb6c57e13d4 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/Struts139Test.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/Struts139Test.java @@ -19,8 +19,8 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.MavenBuild; +import com.sonar.orchestrator.junit4.OrchestratorRule; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; @@ -33,7 +33,7 @@ public class Struts139Test { @ClassRule - public static Orchestrator orchestrator = JavaTestSuite.ORCHESTRATOR; + public static OrchestratorRule orchestrator = JavaTestSuite.ORCHESTRATOR; private static final String PROJECT_STRUTS = "org.apache.struts:struts-parent"; private static final String MODULE_CORE_PHYSICAL_NAME = "core"; diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/SuppressWarningTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/SuppressWarningTest.java index 58739d8b056..95d68068a6c 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/SuppressWarningTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/SuppressWarningTest.java @@ -19,8 +19,8 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.MavenBuild; +import com.sonar.orchestrator.junit4.OrchestratorRule; import java.util.List; import javax.annotation.CheckForNull; import org.junit.ClassRule; @@ -36,7 +36,7 @@ public class SuppressWarningTest { @ClassRule - public static final Orchestrator ORCHESTRATOR = JavaTestSuite.ORCHESTRATOR; + public static final OrchestratorRule ORCHESTRATOR = JavaTestSuite.ORCHESTRATOR; @Test public void suppressWarnings_nosonar() { diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/TestUtils.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/TestUtils.java index e85ae34d1a9..35a65461a02 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/TestUtils.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/TestUtils.java @@ -20,8 +20,8 @@ package com.sonar.it.java.suite; import com.google.common.collect.Iterables; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.container.Server; +import com.sonar.orchestrator.junit4.OrchestratorRule; import java.io.File; import java.io.FilenameFilter; import java.util.Arrays; @@ -70,27 +70,27 @@ public static File projectPom(String projectName) { return new File(homeDir(), "projects/" + projectName + "/pom.xml"); } - public static List issuesForComponent(Orchestrator orchestrator, String componentKey) { + public static List issuesForComponent(OrchestratorRule orchestrator, String componentKey) { return newWsClient(orchestrator) .issues() .search(new SearchRequest().setComponentKeys(Collections.singletonList(componentKey))) .getIssuesList(); } - static WsClient newWsClient(Orchestrator orchestrator) { + static WsClient newWsClient(OrchestratorRule orchestrator) { return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder() .url(orchestrator.getServer().getUrl()) .build()); } - static WsClient newAdminWsClient(Orchestrator orchestrator) { + static WsClient newAdminWsClient(OrchestratorRule orchestrator) { return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder() .credentials(ADMIN_LOGIN, ADMIN_PASSWORD) .url(orchestrator.getServer().getUrl()) .build()); } - public static void provisionProject(Orchestrator orchestrator, String projectKey, String projectName, String languageKey, String profileName) { + public static void provisionProject(OrchestratorRule orchestrator, String projectKey, String projectName, String languageKey, String profileName) { Server server = orchestrator.getServer(); server.provisionProject(projectKey, projectName); server.associateProjectToQualityProfile(projectKey, languageKey, profileName); diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/UnitTestsTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/UnitTestsTest.java index b44c42bac83..1c72e96a65a 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/UnitTestsTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/UnitTestsTest.java @@ -19,8 +19,8 @@ */ package com.sonar.it.java.suite; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.MavenBuild; +import com.sonar.orchestrator.junit4.OrchestratorRule; import java.util.Map; import org.junit.ClassRule; import org.junit.Test; @@ -34,7 +34,7 @@ public class UnitTestsTest { @ClassRule - public static Orchestrator orchestrator = JavaTestSuite.ORCHESTRATOR; + public static OrchestratorRule orchestrator = JavaTestSuite.ORCHESTRATOR; @Test public void tests_without_main_code() { diff --git a/its/ruling/pom.xml b/its/ruling/pom.xml index c43dc4f041a..f64a333f527 100644 --- a/its/ruling/pom.xml +++ b/its/ruling/pom.xml @@ -31,7 +31,7 @@ org.sonarsource.orchestrator - sonar-orchestrator + sonar-orchestrator-junit4 ${orchestrator.version} test diff --git a/its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java b/its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java index 0d8ce2c6e84..e95b5813867 100644 --- a/its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java +++ b/its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java @@ -22,14 +22,14 @@ import com.google.common.base.Splitter; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.OrchestratorBuilder; import com.sonar.orchestrator.build.Build; import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.MavenBuild; import com.sonar.orchestrator.build.SonarScanner; import com.sonar.orchestrator.container.Edition; import com.sonar.orchestrator.container.Server; +import com.sonar.orchestrator.junit4.OrchestratorRule; +import com.sonar.orchestrator.junit4.OrchestratorRuleBuilder; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.locator.MavenLocation; import java.io.File; @@ -91,10 +91,10 @@ public static boolean isCommunityEditionTestsOnly() { return "true".equals(System.getProperty("communityEditionTestsOnly")); } @ClassRule - public static final Orchestrator ORCHESTRATOR = createOrchestrator(); + public static final OrchestratorRule ORCHESTRATOR = createOrchestrator(); - private static Orchestrator createOrchestrator() { - OrchestratorBuilder orchestratorBuilder = Orchestrator.builderEnv() + private static OrchestratorRule createOrchestrator() { + OrchestratorRuleBuilder orchestratorBuilder = OrchestratorRule.builderEnv() .useDefaultAdminCredentialsForBuilds(true) .setSonarVersion(System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE")) .addPlugin(FileLocation.of(TestClasspathUtils.findModuleJarPath("../../sonar-java-plugin").toFile())) @@ -495,7 +495,7 @@ private static void instantiateTemplateRule(String ruleTemplateKey, String insta } } - static WsClient newAdminWsClient(Orchestrator orchestrator) { + static WsClient newAdminWsClient(OrchestratorRule orchestrator) { return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder() .credentials(Server.ADMIN_LOGIN, Server.ADMIN_PASSWORD) .url(orchestrator.getServer().getUrl()) diff --git a/its/ruling/src/test/java/org/sonar/java/it/ProfileGenerator.java b/its/ruling/src/test/java/org/sonar/java/it/ProfileGenerator.java index dcd7a418fd6..1dc1e6f4a11 100644 --- a/its/ruling/src/test/java/org/sonar/java/it/ProfileGenerator.java +++ b/its/ruling/src/test/java/org/sonar/java/it/ProfileGenerator.java @@ -21,7 +21,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.io.Files; -import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.junit4.OrchestratorRule; import com.sonar.orchestrator.locator.FileLocation; import java.io.File; import java.io.IOException; @@ -48,7 +48,7 @@ public class ProfileGenerator { private static final Logger LOG = LoggerFactory.getLogger(ProfileGenerator.class); - static void generate(Orchestrator orchestrator, ImmutableMap> rulesParameters, + static void generate(OrchestratorRule orchestrator, ImmutableMap> rulesParameters, Set excluded, Set subsetOfEnabledRules, Set activatedRuleKeys) { generate(orchestrator, null, rulesParameters, excluded, subsetOfEnabledRules, activatedRuleKeys); } @@ -56,7 +56,7 @@ static void generate(Orchestrator orchestrator, ImmutableMap> rulesParameters, + static void generate(OrchestratorRule orchestrator, @Nullable String qualityProfile, ImmutableMap> rulesParameters, Set excluded, Set subsetOfEnabledRules, Set activatedRuleKeys) { try { LOG.info("Generating profile containing all the rules"); @@ -101,7 +101,7 @@ static void generate(Orchestrator orchestrator, @Nullable String qualityProfile, } } - private static List getRuleKeys(Orchestrator orchestrator, @Nullable String qualityProfile) { + private static List getRuleKeys(OrchestratorRule orchestrator, @Nullable String qualityProfile) { List ruleKeys = new ArrayList<>(); // pages are 1-based int currentPage = 1; @@ -135,7 +135,7 @@ private static List getRuleKeys(Orchestrator orchestrator, @Nullable Str return ruleKeys; } - private static Optional getQualityProfileName(Orchestrator orchestrator, @Nullable String qualityProfile) { + private static Optional getQualityProfileName(OrchestratorRule orchestrator, @Nullable String qualityProfile) { if (qualityProfile == null || qualityProfile.isEmpty()) { return Optional.empty(); } diff --git a/java-checks-testkit/src/main/java/org/sonar/java/checks/verifier/internal/InternalSensorContext.java b/java-checks-testkit/src/main/java/org/sonar/java/checks/verifier/internal/InternalSensorContext.java index f69d5ea5f69..8f477ddb586 100644 --- a/java-checks-testkit/src/main/java/org/sonar/java/checks/verifier/internal/InternalSensorContext.java +++ b/java-checks-testkit/src/main/java/org/sonar/java/checks/verifier/internal/InternalSensorContext.java @@ -199,4 +199,9 @@ public NewSymbolTable newSymbolTable() { public Settings settings() { throw notSupportedException("settings()"); } + + @Override + public void addTelemetryProperty(String s, String s1) { + throw notSupportedException("addTelemetryProperty(String,String)"); + } } diff --git a/java-frontend/src/test/java/org/sonar/java/JavaFrontendTest.java b/java-frontend/src/test/java/org/sonar/java/JavaFrontendTest.java index 0560a8a21ee..7eea8225e82 100644 --- a/java-frontend/src/test/java/org/sonar/java/JavaFrontendTest.java +++ b/java-frontend/src/test/java/org/sonar/java/JavaFrontendTest.java @@ -56,7 +56,6 @@ import org.sonar.api.measures.FileLinesContextFactory; import org.sonar.api.scan.issue.filter.FilterableIssue; import org.sonar.api.scan.issue.filter.IssueFilterChain; -import org.sonar.api.testfixtures.log.LogAndArguments; import org.sonar.api.testfixtures.log.LogTesterJUnit5; import org.sonar.api.utils.Version; import org.sonar.java.classpath.ClasspathForMain; @@ -230,10 +229,7 @@ void test_scan_logs_when_caching_is_enabled_and_can_skip_unchanged_files() throw ); frontend.scan(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); - List logs = logTester.getLogs(Level.INFO).stream() - .map(LogAndArguments::getFormattedMsg) - .toList(); - assertThat(logs) + assertThat(logTester.logs(Level.INFO)) .isNotEmpty() .containsExactly( "Server-side caching is enabled. The Java analyzer was able to leverage cached data from previous analyses for 0 out of 0 files. These files will not be parsed.", @@ -266,10 +262,7 @@ void test_scan_logs_when_caching_is_enabled_and_cannot_skip_unchanged_files() th ); frontend.scan(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); - List logs = logTester.getLogs(Level.INFO).stream() - .map(LogAndArguments::getFormattedMsg) - .toList(); - assertThat(logs) + assertThat(logTester.logs(Level.INFO)) .isNotEmpty() .containsExactly( "Server-side caching is enabled. The Java analyzer will not try to leverage data from a previous analysis.", @@ -302,10 +295,7 @@ void test_scan_logs_when_caching_is_enabled_and_cannot_determine_if_unchanged_fi ); frontend.scan(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); - List logs = logTester.getLogs(Level.INFO).stream() - .map(LogAndArguments::getFormattedMsg) - .toList(); - assertThat(logs) + assertThat(logTester.logs(Level.INFO)) .isNotEmpty() .containsExactly( "Server-side caching is enabled. The Java analyzer will not try to leverage data from a previous analysis.", @@ -337,10 +327,7 @@ void test_scan_logs_when_caching_is_disabled_and_can_skip_unchanged_files() thro ); frontend.scan(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); - List logs = logTester.getLogs(Level.INFO).stream() - .map(LogAndArguments::getFormattedMsg) - .toList(); - assertThat(logs) + assertThat(logTester.logs(Level.INFO)) .isNotEmpty() .containsExactly( "Server-side caching is not enabled. The Java analyzer will not try to leverage data from a previous analysis.", @@ -372,10 +359,7 @@ void test_scan_logs_when_caching_is_disabled_and_cannot_skip_unchanged_files() t ); frontend.scan(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); - List logs = logTester.getLogs(Level.INFO).stream() - .map(LogAndArguments::getFormattedMsg) - .toList(); - assertThat(logs) + assertThat(logTester.logs(Level.INFO)) .isNotEmpty() .containsExactly( "Server-side caching is not enabled. The Java analyzer will not try to leverage data from a previous analysis.", @@ -400,10 +384,7 @@ void test_scan_logs_when_caching_is_disabled_when_sonar_components_is_null() { ); frontend.scan(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); - List logs = logTester.getLogs(Level.INFO).stream() - .map(LogAndArguments::getFormattedMsg) - .toList(); - assertThat(logs) + assertThat(logTester.logs(Level.INFO)) .isNotEmpty() .containsExactly( "Server-side caching is not enabled. The Java analyzer will not try to leverage data from a previous analysis.", @@ -804,18 +785,12 @@ void sonar_java_ignoreUnnamedModuleForSplitPackage_is_logged_at_debug_level_when MapSettings settings = new MapSettings(); settings.setProperty("sonar.java.ignoreUnnamedModuleForSplitPackage", "false"); scan(settings, SONARQUBE_RUNTIME, "package com.acme; class Anvil {}"); - List formattedLogs = logTester.getLogs().stream() - .map(LogAndArguments::getFormattedMsg) - .toList(); - assertThat(formattedLogs).doesNotContain("The Java analyzer will ignore the unnamed module for split packages."); + assertThat(logTester.logs()).doesNotContain("The Java analyzer will ignore the unnamed module for split packages."); settings.setProperty("sonar.java.ignoreUnnamedModuleForSplitPackage", "true"); scan(settings, SONARQUBE_RUNTIME, "package com.acme; class Dynamite {}"); - formattedLogs = logTester.getLogs().stream() - .map(LogAndArguments::getFormattedMsg) - .toList(); - assertThat(formattedLogs).contains("The Java analyzer will ignore the unnamed module for split packages."); + assertThat(logTester.logs()).contains("The Java analyzer will ignore the unnamed module for split packages."); } private List scan(SonarRuntime sonarRuntime, String... codeList) throws IOException { diff --git a/java-frontend/src/test/java/org/sonar/java/ProgressMonitorTest.java b/java-frontend/src/test/java/org/sonar/java/ProgressMonitorTest.java index e78a36714d8..455b590dbcd 100644 --- a/java-frontend/src/test/java/org/sonar/java/ProgressMonitorTest.java +++ b/java-frontend/src/test/java/org/sonar/java/ProgressMonitorTest.java @@ -19,23 +19,28 @@ */ package org.sonar.java; -import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import org.eclipse.core.runtime.IProgressMonitor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; -import org.mockito.ArgumentCaptor; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.event.Level; +import org.sonar.api.testfixtures.log.LogTesterJUnit5; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; class ProgressMonitorTest { + @RegisterExtension + public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + + private static AtomicInteger threadSafeLoggerId = new AtomicInteger(0); + private final Logger logger = LoggerFactory.getLogger("ProgressMonitorTest#" + threadSafeLoggerId.incrementAndGet()); + @Test void test_set_cancel_does_nothing() { AnalysisProgress analysisProgress = new AnalysisProgress(10); @@ -49,7 +54,6 @@ void test_set_cancel_does_nothing() { @Test void methods_do_nothing() { - Logger logger = mock(Logger.class); AnalysisProgress analysisProgress = new AnalysisProgress(10); ProgressMonitor report = new ProgressMonitor(() -> false, logger, TimeUnit.MILLISECONDS.toMillis(500), analysisProgress); @@ -59,13 +63,12 @@ void methods_do_nothing() { report.done(); - verifyNoInteractions(logger); + assertThat(logTester.logs()).isEmpty(); } @Timeout(3) @Test void test_simple_report_progress() throws Exception { - Logger logger = mock(Logger.class); AnalysisProgress analysisProgress = new AnalysisProgress(50); analysisProgress.startBatch(50); ProgressMonitor report = new ProgressMonitor(() -> false, logger, TimeUnit.MILLISECONDS.toMillis(250), analysisProgress); @@ -76,11 +79,7 @@ void test_simple_report_progress() throws Exception { report.worked(100); report.done(); - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(logger, atLeast(4)).info(captor.capture()); - - List messages = captor.getAllValues(); - assertThat(messages).hasSizeGreaterThanOrEqualTo(4).contains( + assertThat(logTester.logs()).hasSizeGreaterThanOrEqualTo(4).contains( "Starting batch processing.", "0% analyzed", "100% analyzed", @@ -91,7 +90,6 @@ void test_simple_report_progress() throws Exception { @Timeout(3) @Test void test_empty_batch() throws Exception { - Logger logger = mock(Logger.class); AnalysisProgress analysisProgress = new AnalysisProgress(0); analysisProgress.startBatch(0); ProgressMonitor report = new ProgressMonitor(() -> false, logger, TimeUnit.MILLISECONDS.toMillis(250), analysisProgress); @@ -102,11 +100,7 @@ void test_empty_batch() throws Exception { report.worked(2); report.done(); - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(logger, atLeast(2)).info(captor.capture()); - - List messages = captor.getAllValues(); - assertThat(messages).hasSizeGreaterThanOrEqualTo(4).contains( + assertThat(logTester.logs()).hasSizeGreaterThanOrEqualTo(4).contains( "Starting batch processing.", "100% analyzed", "Batch processing: Done." @@ -116,7 +110,6 @@ void test_empty_batch() throws Exception { @Timeout(3) @Test void test_report_progress_first_batch() throws Exception { - Logger logger = mock(Logger.class); AnalysisProgress analysisProgress = new AnalysisProgress(50); analysisProgress.startBatch(10); ProgressMonitor report = new ProgressMonitor(() -> false, logger, TimeUnit.MILLISECONDS.toMillis(250), analysisProgress); @@ -130,10 +123,7 @@ void test_report_progress_first_batch() throws Exception { waitForMessage(logger); report.done(); - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(logger, atLeast(4)).info(captor.capture()); - List messages = captor.getAllValues(); - assertThat(messages).contains( + assertThat(logTester.logs()).contains( "Starting batch processing.", "0% analyzed", "10% analyzed", @@ -144,7 +134,6 @@ void test_report_progress_first_batch() throws Exception { @Timeout(3) @Test void test_report_progress_second_batch() throws Exception { - Logger logger = mock(Logger.class); AnalysisProgress analysisProgress = new AnalysisProgress(50); analysisProgress.startBatch(10); analysisProgress.endBatch(); @@ -160,10 +149,7 @@ void test_report_progress_second_batch() throws Exception { waitForMessage(logger); report.done(); - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(logger, atLeast(3)).info(captor.capture()); - List messages = captor.getAllValues(); - assertThat(messages).contains( + assertThat(logTester.logs()).contains( "20% analyzed", "30% analyzed", "40% analyzed" @@ -173,7 +159,6 @@ void test_report_progress_second_batch() throws Exception { @Timeout(3) @Test void test_report_progress_last_batch() throws Exception { - Logger logger = mock(Logger.class); AnalysisProgress analysisProgress = new AnalysisProgress(50); analysisProgress.startBatch(40); analysisProgress.endBatch(); @@ -189,10 +174,7 @@ void test_report_progress_last_batch() throws Exception { waitForMessage(logger); report.done(); - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(logger, atLeast(3)).info(captor.capture()); - List messages = captor.getAllValues(); - assertThat(messages).contains( + assertThat(logTester.logs()).contains( "80% analyzed", "90% analyzed", "100% analyzed", @@ -203,7 +185,6 @@ void test_report_progress_last_batch() throws Exception { @Timeout(3) @Test void test_report_progress() throws Exception { - Logger logger = mock(Logger.class); AnalysisProgress analysisProgress = new AnalysisProgress(500); analysisProgress.startBatch(500); ProgressMonitor report = new ProgressMonitor(() -> false, logger, TimeUnit.MILLISECONDS.toMillis(250), analysisProgress); @@ -221,11 +202,7 @@ void test_report_progress() throws Exception { waitForMessage(logger); report.done(); - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(logger, atLeast(7)).info(captor.capture()); - - List messages = captor.getAllValues(); - assertThat(messages).hasSizeGreaterThanOrEqualTo(7).contains( + assertThat(logTester.logs()).hasSizeGreaterThanOrEqualTo(7).contains( "Starting batch processing.", "0% analyzed", "25% analyzed", @@ -240,8 +217,6 @@ void test_report_progress() throws Exception { @Timeout(3) @Test void test_unknown_total_work() throws Exception { - Logger logger = mock(Logger.class); - AnalysisProgress analysisProgress = new AnalysisProgress(125); analysisProgress.startBatch(125); ProgressMonitor report = new ProgressMonitor(() -> false, logger, TimeUnit.MILLISECONDS.toMillis(250), analysisProgress); @@ -253,11 +228,7 @@ void test_unknown_total_work() throws Exception { waitForMessage(logger); report.done(); - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(logger, atLeast(3)).info(captor.capture()); - - List messages = captor.getAllValues(); - assertThat(messages).hasSizeGreaterThanOrEqualTo(3).contains( + assertThat(logTester.logs()).hasSizeGreaterThanOrEqualTo(3).contains( "Starting batch processing.", "0/UNKNOWN unit(s) analyzed", "250/UNKNOWN unit(s) analyzed" @@ -267,8 +238,6 @@ void test_unknown_total_work() throws Exception { @Timeout(3) @Test void test_is_cancelled() throws Exception { - Logger logger = mock(Logger.class); - AnalysisProgress analysisProgress = new AnalysisProgress(50); analysisProgress.startBatch(50); ProgressMonitor report = new ProgressMonitor(() -> true, logger, TimeUnit.MILLISECONDS.toMillis(250), analysisProgress); @@ -280,11 +249,7 @@ void test_is_cancelled() throws Exception { waitForMessage(logger); report.isCanceled(); - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(logger, atLeast(4)).info(captor.capture()); - - List messages = captor.getAllValues(); - assertThat(messages).hasSizeGreaterThanOrEqualTo(4).contains( + assertThat(logTester.logs()).hasSizeGreaterThanOrEqualTo(4).contains( "Starting batch processing.", "0% analyzed", "50% analyzed", @@ -295,8 +260,6 @@ void test_is_cancelled() throws Exception { @Timeout(3) @Test void test_done_without_success() throws Exception { - Logger logger = mock(Logger.class); - AnalysisProgress analysisProgress = new AnalysisProgress(50); analysisProgress.startBatch(50); ProgressMonitor report = new ProgressMonitor(() -> true, logger, TimeUnit.MILLISECONDS.toMillis(250), analysisProgress); @@ -307,11 +270,7 @@ void test_done_without_success() throws Exception { report.worked(50); report.done(); - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(logger, atLeast(2)).info(captor.capture()); - - List messages = captor.getAllValues(); - assertThat(messages).hasSizeGreaterThanOrEqualTo(2).contains( + assertThat(logTester.logs()).hasSizeGreaterThanOrEqualTo(2).contains( "Starting batch processing.", "0% analyzed" ); @@ -320,8 +279,6 @@ void test_done_without_success() throws Exception { @Timeout(2) @Test void interrupting_the_thread_should_never_create_a_deadlock() { - Logger logger = mock(Logger.class); - AnalysisProgress analysisProgress = new AnalysisProgress(50); ProgressMonitor report = new ProgressMonitor(() -> true, logger, TimeUnit.MILLISECONDS.toMillis(500), analysisProgress); @@ -340,8 +297,6 @@ void interrupting_the_thread_should_never_create_a_deadlock() { @Timeout(1) @Test void interrupted_thread_should_exit_immediately() throws InterruptedException { - Logger logger = mock(Logger.class); - AnalysisProgress analysisProgress = new AnalysisProgress(50); ProgressMonitor report = new ProgressMonitor(() -> true, logger, TimeUnit.MILLISECONDS.toMillis(500), analysisProgress); AtomicLong time = new AtomicLong(10000); diff --git a/java-frontend/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java b/java-frontend/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java index cde3326eac2..9a702b9fa41 100644 --- a/java-frontend/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java +++ b/java-frontend/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java @@ -53,6 +53,7 @@ import org.sonar.java.model.JavaVersionImpl; import org.sonar.java.model.VisitorsBridge; import org.sonar.java.notchecks.VisitorNotInChecksPackage; +import org.sonar.java.testing.ThreadLocalLogTester; import org.sonar.plugins.java.api.JavaFileScanner; import org.sonar.plugins.java.api.JavaFileScannerContext; import org.sonar.plugins.java.api.ModuleScannerContext; @@ -68,14 +69,18 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; class JavaAstScannerTest { @RegisterExtension - public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + public ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.DEBUG); + + @RegisterExtension + public LogTesterJUnit5 globalLogTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + private SensorContextTester context; @BeforeEach @@ -189,7 +194,7 @@ void test_should_log_fail_parsing_with_incorrect_version() { void should_interrupt_analysis_when_specific_exception_are_thrown(Class exceptionClass) throws Exception { List inputFiles = Collections.singletonList(TestUtils.inputFile("src/test/files/metrics/NoSonar.java")); List visitors = Collections.singletonList(new CheckThrowingException( - new RecognitionException(42, "interrupted", exceptionClass.newInstance()))); + new RecognitionException(42, "interrupted", exceptionClass.getDeclaredConstructor().newInstance()))); AnalysisException e = assertThrows(AnalysisException.class, () -> scanFilesWithVisitors(inputFiles, visitors, -1, false, false)); @@ -207,7 +212,7 @@ void should_interrupt_analysis_when_specific_exception_are_thrown(Class exceptionClass) throws Exception { List inputFiles = Collections.singletonList(TestUtils.inputFile("src/test/files/metrics/NoSonar.java")); List visitors = Collections.singletonList(new CheckThrowingException( - new RecognitionException(42, "interrupted", exceptionClass.newInstance()))); + new RecognitionException(42, "interrupted", exceptionClass.getDeclaredConstructor().newInstance()))); AnalysisException e = assertThrows(AnalysisException.class, () -> scanFilesWithVisitors(inputFiles, visitors, -1, false, true)); @@ -277,7 +282,7 @@ void module_info_should_not_be_analyzed_or_change_the_version() { TestUtils.inputFile("src/test/resources/module-info.java") )); - assertThat(logTester.logs(Level.INFO)).hasSize(3) + assertThat(globalLogTester.logs(Level.INFO)).hasSize(3) .contains("1/1 source file has been analyzed"); assertThat(logTester.logs(Level.ERROR)).containsExactly( "Unable to parse source file : 'src/test/files/metrics/Java15SwitchExpression.java'", @@ -340,7 +345,7 @@ void should_report_analysis_error_in_sonarLint_context_withSQ_6_0() { scanner.setVisitorBridge(new VisitorsBridge(Collections.singletonList(listener), new ArrayList<>(), sonarComponents)); scanner.scan(Collections.singletonList(TestUtils.inputFile("src/test/resources/AstScannerParseError.txt"))); verify(sonarComponents).reportAnalysisError(any(RecognitionException.class), any(InputFile.class)); - verifyZeroInteractions(listener); + verifyNoInteractions(listener); } @Test diff --git a/java-frontend/src/test/java/org/sonar/java/caching/CacheContextImplTest.java b/java-frontend/src/test/java/org/sonar/java/caching/CacheContextImplTest.java index cc43d869075..8039ce7d858 100644 --- a/java-frontend/src/test/java/org/sonar/java/caching/CacheContextImplTest.java +++ b/java-frontend/src/test/java/org/sonar/java/caching/CacheContextImplTest.java @@ -19,7 +19,6 @@ */ package org.sonar.java.caching; -import java.util.List; import java.util.Optional; import javax.annotation.Nullable; import org.junit.jupiter.api.Test; @@ -29,9 +28,8 @@ import org.sonar.api.batch.sensor.cache.ReadCache; import org.sonar.api.batch.sensor.cache.WriteCache; import org.sonar.api.config.Configuration; -import org.sonar.api.testfixtures.log.LogAndArguments; -import org.sonar.api.testfixtures.log.LogTesterJUnit5; import org.sonar.java.SonarComponents; +import org.sonar.java.testing.ThreadLocalLogTester; import org.sonar.plugins.java.api.caching.CacheContext; import org.sonar.plugins.java.api.caching.SonarLintCache; @@ -44,7 +42,7 @@ class CacheContextImplTest { @RegisterExtension - LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.DEBUG); @Test void should_use_dummy_cache_if_sonarcomponents_is_unavailable() { @@ -111,10 +109,7 @@ void of_logs_at_debug_level_when_the_api_is_not_supported() { var sonarComponents = mockSonarComponents(sensorContext, null); CacheContextImpl.of(sonarComponents); - List logs = logTester.getLogs(Level.DEBUG).stream() - .map(LogAndArguments::getFormattedMsg) - .toList(); - assertThat(logs) + assertThat(logTester.logs(Level.DEBUG)) .hasSize(1) .contains("Missing cache related method from sonar-plugin-api: bim."); } diff --git a/java-frontend/src/test/java/org/sonar/java/caching/ContentHashCacheTest.java b/java-frontend/src/test/java/org/sonar/java/caching/ContentHashCacheTest.java index 9bfa03f5f7b..55a2ffd9dac 100644 --- a/java-frontend/src/test/java/org/sonar/java/caching/ContentHashCacheTest.java +++ b/java-frontend/src/test/java/org/sonar/java/caching/ContentHashCacheTest.java @@ -33,10 +33,9 @@ import org.sonar.api.batch.sensor.cache.ReadCache; import org.sonar.api.batch.sensor.cache.WriteCache; import org.sonar.api.batch.sensor.internal.SensorContextTester; -import org.sonar.api.testfixtures.log.LogAndArguments; -import org.sonar.api.testfixtures.log.LogTesterJUnit5; import org.sonar.java.SonarComponents; import org.sonar.java.TestUtils; +import org.sonar.java.testing.ThreadLocalLogTester; import org.sonar.plugins.java.api.caching.SonarLintCache; import static org.assertj.core.api.Assertions.assertThat; @@ -48,7 +47,7 @@ class ContentHashCacheTest { @RegisterExtension - LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.DEBUG); private final File file = new File("src/test/files/api/JavaFileScannerContext.java"); private final InputFile inputFile = TestUtils.inputFile(file.getAbsoluteFile().getAbsolutePath(), file, InputFile.Type.TEST); @@ -59,8 +58,7 @@ void hasSameHashCached_returns_true_when_content_hash_file_is_in_read_cache() th ContentHashCache contentHashCache = new ContentHashCache(mockSonarComponents(getSonarComponentsTester())); Assertions.assertTrue(contentHashCache.hasSameHashCached(inputFile)); - List logs = logTester.getLogs(Level.TRACE).stream().map(LogAndArguments::getFormattedMsg).toList(); - assertThat(logs). + assertThat(logTester.logs(Level.TRACE)). contains("Reading cache for the file " + inputFile.key(), "Copying cache from previous for file " + inputFile.key()); } @@ -80,7 +78,7 @@ private List hasSameHashCached_returns_false_when_content_hash_file_is_n logTester.setLevel(level); ContentHashCache contentHashCache = new ContentHashCache(mockSonarComponents(getSensorContextTesterWithEmptyCache(true))); Assertions.assertFalse(contentHashCache.hasSameHashCached(inputFile)); - return logTester.getLogs(level).stream().map(LogAndArguments::getFormattedMsg).toList(); + return logTester.logs(level); } @Test @@ -92,8 +90,7 @@ void hasSameHashCached_returns_false_when_cache_is_disabled_and_input_file_statu ContentHashCache contentHashCache = new ContentHashCache(mockSonarComponents(getSensorContextTesterWithEmptyCache(false))); Assertions.assertTrue(contentHashCache.hasSameHashCached(inputFile1)); - List logs = logTester.getLogs(Level.TRACE).stream().map(LogAndArguments::getFormattedMsg).toList(); - assertThat(logs). + assertThat(logTester.logs(Level.TRACE)). contains("Cache is disabled. File status is: " + inputFile1.status() + ". File can be skipped."); } @@ -105,8 +102,7 @@ void hasSameHashCached_returns_false_cache_is_disabled_and_input_file_status_is_ ContentHashCache contentHashCache = new ContentHashCache(mockSonarComponents(getSensorContextTesterWithEmptyCache(false))); Assertions.assertFalse(contentHashCache.hasSameHashCached(inputFile1)); - List logs = logTester.getLogs(Level.TRACE).stream().map(LogAndArguments::getFormattedMsg).toList(); - assertThat(logs). + assertThat(logTester.logs(Level.TRACE)). contains("Cache is disabled. File status is: " + inputFile1.status() + ". File can't be skipped."); } @@ -117,8 +113,7 @@ void hasSameHashCached_writesToCache_when_key_is_not_present() { contentHashCache.hasSameHashCached(inputFile); Assertions.assertTrue(contentHashCache.writeToCache(inputFile)); - List logs = logTester.getLogs(Level.TRACE).stream().map(LogAndArguments::getFormattedMsg).toList(); - assertThat(logs). + assertThat(logTester.logs(Level.TRACE)). contains("Writing to the cache for file " + inputFile.key()); } @@ -136,8 +131,7 @@ void hasSameHashCached_returns_false_when_content_hash_file_is_not_same_as_one_i ContentHashCache contentHashCache = new ContentHashCache(mockSonarComponents(sensorContext)); Assertions.assertFalse(contentHashCache.hasSameHashCached(inputFile)); - List logs = logTester.getLogs(Level.TRACE).stream().map(LogAndArguments::getFormattedMsg).toList(); - assertThat(logs). + assertThat(logTester.logs(Level.TRACE)). contains("Reading cache for the file " + inputFile.key(), "Writing to the cache for file " + inputFile.key()); } @@ -161,8 +155,7 @@ void hasSameHashCached_returns_false_when_FileHashingUtils_throws_exception() th ContentHashCache contentHashCache = new ContentHashCache(mockSonarComponents(sensorContext)); Assertions.assertFalse(contentHashCache.hasSameHashCached(inputFile1)); - List logs = logTester.getLogs(Level.WARN).stream().map(LogAndArguments::getFormattedMsg).toList(); - assertThat(logs). + assertThat(logTester.logs(Level.WARN)). contains("Failed to compute content hash for file " + inputFile1.key()); } @@ -204,7 +197,7 @@ private List writeToCache_returns_false_when_writing_to_cache_throws_exc FileHashingUtils.inputFileContentHash(file.getPath())); ContentHashCache contentHashCache = new ContentHashCache(mockSonarComponents(sensorContext)); Assertions.assertFalse(contentHashCache.writeToCache(inputFile)); - return logTester.getLogs(level).stream().map(LogAndArguments::getFormattedMsg).toList(); + return logTester.logs(level); } @Test @@ -222,8 +215,7 @@ void writeToCache_returns_false_when_FileHashingUtils_throws_exception() throws ContentHashCache contentHashCache = new ContentHashCache(mockSonarComponents(sensorContext)); Assertions.assertFalse(contentHashCache.writeToCache(inputFile1)); - List logs = logTester.getLogs(Level.WARN).stream().map(LogAndArguments::getFormattedMsg).toList(); - assertThat(logs). + assertThat(logTester.logs(Level.WARN)). contains("Failed to compute content hash for file " + inputFile1.key()); } @@ -242,8 +234,7 @@ void should_not_enable_content_hash_cache_when_using_sonarlint_cache() { InputFile inputFile1 = mock(InputFile.class); assertThat(contentHashCache.contains(inputFile1)).isFalse(); - List logs = logTester.getLogs(Level.TRACE).stream().map(LogAndArguments::getFormattedMsg).toList(); - assertThat(logs). + assertThat(logTester.logs(Level.TRACE)). contains("Cannot lookup cached hashes when the cache is disabled (null)."); } diff --git a/java-frontend/src/test/java/org/sonar/java/cfg/CFGTest.java b/java-frontend/src/test/java/org/sonar/java/cfg/CFGTest.java index abd10f43837..9a774acba97 100644 --- a/java-frontend/src/test/java/org/sonar/java/cfg/CFGTest.java +++ b/java-frontend/src/test/java/org/sonar/java/cfg/CFGTest.java @@ -29,10 +29,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.event.Level; -import org.sonar.api.testfixtures.log.LogTesterJUnit5; import org.sonar.java.cfg.CFG.Block; import org.sonar.java.model.JParserTestUtils; import org.sonar.java.model.LiteralUtils; +import org.sonar.java.testing.ThreadLocalLogTester; import org.sonar.plugins.java.api.tree.ClassTree; import org.sonar.plugins.java.api.tree.CompilationUnitTree; import org.sonar.plugins.java.api.tree.IdentifierTree; @@ -105,7 +105,7 @@ class CFGTest { @RegisterExtension - public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + public ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.DEBUG); static CFGChecker checker(BlockChecker... checkers) { return new CFGChecker(checkers); diff --git a/java-frontend/src/test/java/org/sonar/java/cfg/LiveVariablesTest.java b/java-frontend/src/test/java/org/sonar/java/cfg/LiveVariablesTest.java index 43503d6d4e5..bd2235f38dc 100644 --- a/java-frontend/src/test/java/org/sonar/java/cfg/LiveVariablesTest.java +++ b/java-frontend/src/test/java/org/sonar/java/cfg/LiveVariablesTest.java @@ -140,7 +140,7 @@ void test_fields_live() { assertFieldsByMethodEntry("void foo(int a) { B that = new B(); foo(that.field1); }"); } - private void assertFieldsByMethodEntry(String methodCode, String ...inEntryNames) { + private void assertFieldsByMethodEntry(String methodCode, Object... inEntryNames) { CFG cfg = buildCFG(methodCode); LiveVariables liveVariables = LiveVariables.analyzeWithFields(cfg); assertThat(liveVariables.getOut(cfg.entryBlock())).isEmpty(); diff --git a/java-frontend/src/test/java/org/sonar/java/classpath/ClasspathForMainTest.java b/java-frontend/src/test/java/org/sonar/java/classpath/ClasspathForMainTest.java index a72a14c032d..cd36481c79d 100644 --- a/java-frontend/src/test/java/org/sonar/java/classpath/ClasspathForMainTest.java +++ b/java-frontend/src/test/java/org/sonar/java/classpath/ClasspathForMainTest.java @@ -35,18 +35,18 @@ import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.config.internal.MultivalueProperty; -import org.sonar.api.testfixtures.log.LogTesterJUnit5; import org.sonar.api.utils.System2; import org.sonar.java.AnalysisException; import org.sonar.java.AnalysisWarningsWrapper; import org.sonar.java.TestUtils; +import org.sonar.java.testing.ThreadLocalLogTester; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; class ClasspathForMainTest { @@ -57,7 +57,7 @@ class ClasspathForMainTest { private ClasspathForMain javaClasspath; @RegisterExtension - public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + public ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.DEBUG); @BeforeEach void setup() { @@ -88,8 +88,8 @@ public String[] getStringArray(String key) { void no_interaction_with_FileSystem_at_initialization() { fs = Mockito.spy(new DefaultFileSystem(new File("src/test/files/classpath/"))); javaClasspath = createJavaClasspath(); - Mockito.verifyZeroInteractions(fs); - Mockito.verifyZeroInteractions(analysisWarnings); + verifyNoInteractions(fs); + verifyNoInteractions(analysisWarnings); } @Test @@ -154,7 +154,7 @@ void do_not_register_warning_for_missing_bytecode_when_wrapper_not_injected() { javaClasspath.init(); assertThat(javaClasspath.getFilesFromProperty(ClasspathProperties.SONAR_JAVA_LIBRARIES)).isEmpty(); assertThat(javaClasspath.hasJavaSources()).isTrue(); - verifyZeroInteractions(analysisWarnings); + verifyNoInteractions(analysisWarnings); } @Test diff --git a/java-frontend/src/test/java/org/sonar/java/classpath/ClasspathForTestTest.java b/java-frontend/src/test/java/org/sonar/java/classpath/ClasspathForTestTest.java index bf72fccb113..a9a9e621467 100644 --- a/java-frontend/src/test/java/org/sonar/java/classpath/ClasspathForTestTest.java +++ b/java-frontend/src/test/java/org/sonar/java/classpath/ClasspathForTestTest.java @@ -28,8 +28,8 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.config.internal.MapSettings; -import org.sonar.api.testfixtures.log.LogTesterJUnit5; import org.sonar.java.TestUtils; +import org.sonar.java.testing.ThreadLocalLogTester; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.fail; @@ -41,7 +41,7 @@ class ClasspathForTestTest { private ClasspathForTest javaTestClasspath; @RegisterExtension - public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + public ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.DEBUG); @BeforeEach public void setUp() { @@ -59,7 +59,7 @@ public void setUp() { void no_interaction_with_FileSystem_at_initialization() { fs = Mockito.spy(new DefaultFileSystem(new File("src/test/files/classpath/"))); javaTestClasspath = new ClasspathForTest(settings.asConfig(), fs); - Mockito.verifyZeroInteractions(fs); + Mockito.verifyNoInteractions(fs); } @Test diff --git a/java-frontend/src/test/java/org/sonar/java/model/GeneratedFileTest.java b/java-frontend/src/test/java/org/sonar/java/model/GeneratedFileTest.java index 3f3ca3e2788..202336c4488 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/GeneratedFileTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/GeneratedFileTest.java @@ -33,7 +33,7 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.testfixtures.log.LogTesterJUnit5; +import org.sonar.java.testing.ThreadLocalLogTester; import org.sonar.plugins.java.api.SourceMap; import static java.nio.charset.StandardCharsets.UTF_8; @@ -52,7 +52,7 @@ class GeneratedFileTest { private GeneratedFile actual; @RegisterExtension - public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + public ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.DEBUG); private DefaultFileSystem fs; @BeforeEach @@ -81,7 +81,7 @@ void test() throws Exception { assertEquals("9a0364b9e99bb480dd25e1f0284c8555", computedMd5Hash); assertSame(computedMd5Hash, cachedMd5Hash); try (InputStream is = actual.inputStream()) { - assertEquals("content", IOUtils.toString(is)); + assertEquals("content", IOUtils.toString(is, UTF_8)); } assertFalse(actual.isEmpty()); assertEquals(UTF_8, actual.charset()); diff --git a/java-frontend/src/test/java/org/sonar/java/model/JParserConfigTest.java b/java-frontend/src/test/java/org/sonar/java/model/JParserConfigTest.java index f933414a73a..d7f9b7710e1 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/JParserConfigTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/JParserConfigTest.java @@ -20,19 +20,17 @@ package org.sonar.java.model; import java.util.Collections; -import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.event.Level; -import org.sonar.api.testfixtures.log.LogAndArguments; -import org.sonar.api.testfixtures.log.LogTesterJUnit5; +import org.sonar.java.testing.ThreadLocalLogTester; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.java.model.JParserConfig.shouldEnablePreviewFlag; class JParserConfigTest { @RegisterExtension - public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.INFO); + public ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.INFO); @Test void should_enable_preview() { @@ -54,13 +52,10 @@ void should_enable_preview() { @Test void a_debug_message_is_logged_when_shouldIgnoreUnnamedModuleForSplitPackage_is_set() { JParserConfig.Mode.BATCH.create(new JavaVersionImpl(17), Collections.emptyList()); - assertThat(logTester.getLogs()).isEmpty(); + assertThat(logTester.logs()).isEmpty(); JParserConfig.Mode.BATCH.create(new JavaVersionImpl(17), Collections.emptyList(), false); - assertThat(logTester.getLogs()).isEmpty(); + assertThat(logTester.logs()).isEmpty(); JParserConfig.Mode.BATCH.create(new JavaVersionImpl(17), Collections.emptyList(), true); - List logs = logTester.getLogs().stream() - .map(LogAndArguments::getFormattedMsg) - .toList(); - assertThat(logs).containsExactly("The Java analyzer will ignore the unnamed module for split packages."); + assertThat(logTester.logs()).containsExactly("The Java analyzer will ignore the unnamed module for split packages."); } } diff --git a/java-frontend/src/test/java/org/sonar/java/model/JParserTest.java b/java-frontend/src/test/java/org/sonar/java/model/JParserTest.java index d842c245a5b..83a62942ddb 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/JParserTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/JParserTest.java @@ -57,11 +57,11 @@ import org.mockito.Mockito; import org.slf4j.event.Level; import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.testfixtures.log.LogTesterJUnit5; import org.sonar.java.AnalysisProgress; import org.sonar.java.TestUtils; import org.sonar.java.model.JavaTree.CompilationUnitTreeImpl; import org.sonar.java.model.declaration.ClassTreeImpl; +import org.sonar.java.testing.ThreadLocalLogTester; import org.sonar.plugins.java.api.location.Range; import org.sonar.plugins.java.api.tree.ArrayTypeTree; import org.sonar.plugins.java.api.tree.BlockTree; @@ -102,7 +102,7 @@ class JParserTest { @RegisterExtension - public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + public ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.DEBUG); @Test void should_throw_RecognitionException_in_case_of_syntax_error() { diff --git a/java-frontend/src/test/java/org/sonar/java/model/JTypeTest.java b/java-frontend/src/test/java/org/sonar/java/model/JTypeTest.java index 4f33bdeda9c..9f76f1bb65b 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/JTypeTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/JTypeTest.java @@ -31,13 +31,13 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.event.Level; -import org.sonar.api.testfixtures.log.LogTesterJUnit5; import org.sonar.java.model.JavaTree.CompilationUnitTreeImpl; import org.sonar.java.model.declaration.ClassTreeImpl; import org.sonar.java.model.declaration.MethodTreeImpl; import org.sonar.java.model.declaration.VariableTreeImpl; import org.sonar.java.model.statement.ExpressionStatementTreeImpl; import org.sonar.java.model.statement.ReturnStatementTreeImpl; +import org.sonar.java.testing.ThreadLocalLogTester; import org.sonar.plugins.java.api.semantic.Type; import static org.assertj.core.api.Assertions.assertThat; @@ -50,7 +50,7 @@ class JTypeTest { @RegisterExtension - public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + public ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.DEBUG); @Test void isArray() { @@ -329,7 +329,7 @@ private JType type(String name) { @BeforeEach void setup() { - ASTParser astParser = ASTParser.newParser(AST.JLS14); + ASTParser astParser = ASTParser.newParser(AST.getJLSLatest()); astParser.setEnvironment( new String[]{}, new String[]{}, diff --git a/java-frontend/src/test/java/org/sonar/java/model/SmapFileTest.java b/java-frontend/src/test/java/org/sonar/java/model/SmapFileTest.java index c41ccfcd42c..4855c3671ed 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/SmapFileTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/SmapFileTest.java @@ -30,7 +30,7 @@ import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.testfixtures.log.LogTesterJUnit5; +import org.sonar.java.testing.ThreadLocalLogTester; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -39,7 +39,7 @@ class SmapFileTest { @RegisterExtension - public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + public ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.DEBUG); @TempDir public Path temporaryFolder; diff --git a/java-frontend/src/test/java/org/sonar/java/model/VisitorsBridgeTest.java b/java-frontend/src/test/java/org/sonar/java/model/VisitorsBridgeTest.java index 6a5dcf991d3..9dec78433a8 100644 --- a/java-frontend/src/test/java/org/sonar/java/model/VisitorsBridgeTest.java +++ b/java-frontend/src/test/java/org/sonar/java/model/VisitorsBridgeTest.java @@ -35,8 +35,6 @@ import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.internal.SensorContextTester; import org.sonar.api.config.internal.MapSettings; -import org.sonar.api.testfixtures.log.LogAndArguments; -import org.sonar.api.testfixtures.log.LogTesterJUnit5; import org.sonar.java.AnalysisException; import org.sonar.java.CheckFailureException; import org.sonar.java.SonarComponents; @@ -46,6 +44,7 @@ import org.sonar.java.checks.VisitorThatCanBeSkipped; import org.sonar.java.exceptions.ApiMismatchException; import org.sonar.java.notchecks.VisitorNotInChecksPackage; +import org.sonar.java.testing.ThreadLocalLogTester; import org.sonar.plugins.java.api.InputFileScannerContext; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.JavaFileScanner; @@ -75,7 +74,7 @@ class VisitorsBridgeTest { @RegisterExtension - public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + public ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.DEBUG); private SonarComponents sonarComponents = null; @@ -374,9 +373,9 @@ void endOfAnalysis_logs_nothing_when_no_file_has_been_analyzed() { Collections.emptyList(), null ); - assertThat(logTester.getLogs(Level.INFO)).isEmpty(); + assertThat(logTester.logs(Level.INFO)).isEmpty(); visitorsBridge.endOfAnalysis(); - assertThat(logTester.getLogs(Level.INFO)).isEmpty(); + assertThat(logTester.logs(Level.INFO)).isEmpty(); } @Test @@ -389,14 +388,12 @@ void endOfAnalysis_logs_when_no_file_has_been_optimized() throws ApiMismatchExce specificSonarComponents ); - assertThat(logTester.getLogs(Level.INFO)).isEmpty(); + assertThat(logTester.logs(Level.INFO)).isEmpty(); visitorsBridge.visitFile(null, false); - assertThat(logTester.getLogs(Level.INFO)).isEmpty(); + assertThat(logTester.logs(Level.INFO)).isEmpty(); visitorsBridge.endOfAnalysis(); - List logsAfterEndOfAnalysis = logTester.getLogs(Level.INFO); - assertThat(logsAfterEndOfAnalysis).hasSize(1); - assertThat(logsAfterEndOfAnalysis.get(0).getFormattedMsg()) - .isEqualTo("Did not optimize analysis for any files, performed a full analysis for all 1 files."); + assertThat(logTester.logs(Level.INFO)) + .containsExactly("Did not optimize analysis for any files, performed a full analysis for all 1 files."); } @Test @@ -409,14 +406,12 @@ void endOfAnalysis_logs_when_at_least_one_file_has_been_optimized() throws ApiMi specificSonarComponents ); - assertThat(logTester.getLogs(Level.INFO)).isEmpty(); + assertThat(logTester.logs(Level.INFO)).isEmpty(); visitorsBridge.visitFile(null, true); - assertThat(logTester.getLogs(Level.INFO)).isEmpty(); + assertThat(logTester.logs(Level.INFO)).isEmpty(); visitorsBridge.endOfAnalysis(); - List logsAfterEndOfAnalysis = logTester.getLogs(Level.INFO); - assertThat(logsAfterEndOfAnalysis).hasSize(1); - assertThat(logsAfterEndOfAnalysis.get(0).getFormattedMsg()) - .isEqualTo("Optimized analysis for 1 of 1 files."); + assertThat(logTester.logs(Level.INFO)) + .containsExactly("Optimized analysis for 1 of 1 files."); } @Nested @@ -550,9 +545,7 @@ private void triggers_an_AnalysisException_when_a_scanner_throws_while_scanning_ scanner.getClass().getCanonicalName() ); - List warningLogs = logTester.getLogs(Level.WARN); - assertThat(warningLogs).hasSize(1); - assertThat(warningLogs.get(0).getFormattedMsg()).isEqualTo(expectedLogMessage); + assertThat(logTester.logs(Level.WARN)).containsExactly(expectedLogMessage); } private boolean scan_without_parsing(JavaFileScanner scanner) throws ApiMismatchException { diff --git a/java-frontend/src/test/java/org/sonar/java/reporting/InternalJavaIssueBuilderTest.java b/java-frontend/src/test/java/org/sonar/java/reporting/InternalJavaIssueBuilderTest.java index 1062e01aed1..b82001f294d 100644 --- a/java-frontend/src/test/java/org/sonar/java/reporting/InternalJavaIssueBuilderTest.java +++ b/java-frontend/src/test/java/org/sonar/java/reporting/InternalJavaIssueBuilderTest.java @@ -56,10 +56,10 @@ import org.sonar.api.batch.sensor.issue.internal.DefaultIssue; import org.sonar.api.issue.impact.SoftwareQuality; import org.sonar.api.rule.RuleKey; -import org.sonar.api.testfixtures.log.LogTesterJUnit5; import org.sonar.java.SonarComponents; import org.sonar.java.TestUtils; import org.sonar.java.model.JParserTestUtils; +import org.sonar.java.testing.ThreadLocalLogTester; import org.sonar.plugins.java.api.JavaCheck; import org.sonar.plugins.java.api.JavaFileScannerContext; import org.sonar.plugins.java.api.tree.ClassTree; @@ -81,7 +81,7 @@ class InternalJavaIssueBuilderTest { @RegisterExtension - public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG); + public ThreadLocalLogTester logTester = new ThreadLocalLogTester().setLevel(Level.DEBUG); private static final File JAVA_FILE = new File("src/test/files/api/JavaFileInternalJavaIssueBuilderTest.java"); private static final JavaCheck CHECK = new JavaCheck() { diff --git a/java-frontend/src/test/java/org/sonar/java/testing/ThreadLocalLogTester.java b/java-frontend/src/test/java/org/sonar/java/testing/ThreadLocalLogTester.java new file mode 100644 index 00000000000..f995c2f7226 --- /dev/null +++ b/java-frontend/src/test/java/org/sonar/java/testing/ThreadLocalLogTester.java @@ -0,0 +1,107 @@ +/* + * SonarQube Java + * Copyright (C) 2012-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.java.testing; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; +import java.util.List; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.slf4j.LoggerFactory; +import org.slf4j.event.Level; + +/** + * Only collect logs written on the same thead as the one used for the constructor of ThreadLocalLogTester + */ +public class ThreadLocalLogTester implements AfterEachCallback, BeforeEachCallback { + + private final ThreadLocalAppender appender = new ThreadLocalAppender(Thread.currentThread()); + private Level slf4jLevel = Level.DEBUG; + + @Override + public void beforeEach(ExtensionContext context) { + setLevel(slf4jLevel); + appender.start(); + getRootLogger().addAppender(appender); + } + + @Override + public void afterEach(ExtensionContext context) { + getRootLogger().detachAppender(appender); + appender.list.clear(); + appender.stop(); + } + + public Level getLevel() { + return slf4jLevel; + } + + public ThreadLocalLogTester setLevel(Level level) { + this.slf4jLevel = level; + this.appender.setLevel(level); + return this; + } + + public List logs() { + return appender.list.stream() + .map(ILoggingEvent::getFormattedMessage) + .toList(); + } + + public List logs(Level level) { + ch.qos.logback.classic.Level logBackLevel = ch.qos.logback.classic.Level.toLevel(level.toString()); + return appender.list.stream() + .filter(event -> event.getLevel().toInt() == logBackLevel.toInt()) + .map(ILoggingEvent::getFormattedMessage) + .toList(); + } + + public ThreadLocalLogTester clear() { + appender.list.clear(); + return this; + } + + private static ch.qos.logback.classic.Logger getRootLogger() { + return (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); + } + + public static class ThreadLocalAppender extends ListAppender { + private final Thread filteringThread; + private ch.qos.logback.classic.Level logBackLevel; + public ThreadLocalAppender(Thread filteringThread) { + this.filteringThread = filteringThread; + } + + public void setLevel(Level level) { + this.logBackLevel = ch.qos.logback.classic.Level.toLevel(level.toString()); + if (!logBackLevel.isGreaterOrEqual(getRootLogger().getLevel())) { + getRootLogger().setLevel(logBackLevel); + } + } + + @Override + protected void append(ILoggingEvent e) { + if (Thread.currentThread() == filteringThread && e.getLevel().isGreaterOrEqual(logBackLevel)) { + super.append(e); + } + } + } +} diff --git a/java-jsp/pom.xml b/java-jsp/pom.xml index 59161c34d05..47c87d188ee 100644 --- a/java-jsp/pom.xml +++ b/java-jsp/pom.xml @@ -31,7 +31,7 @@ org.apache.tomcat.embed tomcat-embed-jasper - 9.0.90 + 9.0.96 org.eclipse.jdt diff --git a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/symbolicvalues/RelationalSymbolicValueTest.java b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/symbolicvalues/RelationalSymbolicValueTest.java index 1a0217752fc..dac30403130 100644 --- a/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/symbolicvalues/RelationalSymbolicValueTest.java +++ b/java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/symbolicvalues/RelationalSymbolicValueTest.java @@ -50,6 +50,7 @@ import org.sonarsource.analyzer.commons.collections.ListUtils; import org.sonarsource.analyzer.commons.collections.SetUtils; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; @@ -149,7 +150,7 @@ void test_direct_deduction() { RelationalSymbolicValue eqAB = new RelationalSymbolicValue(RelationalSymbolicValue.Kind.METHOD_EQUALS, a, b); RelationalSymbolicValue eqBA = new RelationalSymbolicValue(RelationalSymbolicValue.Kind.METHOD_EQUALS, b, a); Stream.of(eqAB, eqBA, eqAB.inverse(), eqBA.inverse()).forEach(rel -> actual.addAll(resolveRelationStateForAllKinds(rel, rel::toString))); - List expected = IOUtils.readLines(getClass().getResourceAsStream("/relations/direct.txt")); + List expected = IOUtils.readLines(getClass().getResourceAsStream("/relations/direct.txt"), UTF_8); assertThat(actual).isEqualTo(expected); } @@ -327,7 +328,7 @@ void test_transitive_deduction() { RelationalSymbolicValue neqAB = eqAB.inverse(); actual.addAll(combineWithAll(neqAB, neqAB::toString)); - List expected = IOUtils.readLines(getClass().getResourceAsStream("/relations/transitive.txt")); + List expected = IOUtils.readLines(getClass().getResourceAsStream("/relations/transitive.txt"), UTF_8); assertThat(actual).isEqualTo(expected); } diff --git a/override-dep-licenses.properties b/override-dep-licenses.properties index b9f8a1904fe..f9d5c686c6b 100644 --- a/override-dep-licenses.properties +++ b/override-dep-licenses.properties @@ -6,13 +6,3 @@ org.ow2.asm--asm-analysis--8.0.1=bsd org.ow2.asm--asm-commons--8.0.1=bsd org.ow2.asm--asm-tree--8.0.1=bsd org.ow2.asm--asm-util--8.0.1=bsd - -# tomcat uses both apache v2 and cddl, however in the POM it is defined in a way that license plugin fails to recognize it properly -# that's why we override to Apache license -org.apache.tomcat--tomcat-servlet-api--9.0.30=apache_v2 - -com.google.code.gson--gson--2.8.9=apache_v2 - -# It looks like the check does not understand 'Apache-2.0' to be apache_v2 for the two following dependencies -org.osgi--org.osgi.service.prefs--1.1.2=apache_v2 -org.osgi--osgi.annotation--8.0.1=apache_v2 diff --git a/pom.xml b/pom.xml index 79da6e5ef18..baffa26a854 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.sonarsource.parent parent - 79.0.0.2165 + 80.0.0.2205 org.sonarsource.java @@ -87,15 +87,15 @@ true - 10.4.1.88267 + 10.7.0.96327 - 10.2.0.1908 + 10.12.0.2522 9.8.0.76914 2.14.0.3087 - 3.40.0.183 + 5.0.0.2065 1.24.0.633 -Xmx512m sonar-java @@ -199,7 +199,7 @@ com.google.guava guava - 33.1.0-jre + 33.3.1-jre com.google.code.findbugs @@ -227,7 +227,7 @@ org.junit junit-bom - 5.10.2 + 5.11.2 pom import @@ -240,19 +240,19 @@ org.mockito mockito-core - 3.9.0 + 5.14.2 test org.mockito mockito-junit-jupiter - 3.9.0 + 5.14.2 test org.assertj assertj-core - 3.25.3 + 3.26.3 test @@ -271,22 +271,22 @@ org.apache.commons commons-lang3 - 3.12.0 + 3.17.0 org.springframework spring-expression - 6.1.5 + 6.1.13 commons-io commons-io - 2.15.1 + 2.17.0 com.google.code.gson gson - 2.8.9 + 2.11.0 compile diff --git a/sonar-java-plugin/src/main/java/org/sonar/plugins/java/ExternalReportExtensions.java b/sonar-java-plugin/src/main/java/org/sonar/plugins/java/ExternalReportExtensions.java index 1d2c133b37e..cac614f465c 100644 --- a/sonar-java-plugin/src/main/java/org/sonar/plugins/java/ExternalReportExtensions.java +++ b/sonar-java-plugin/src/main/java/org/sonar/plugins/java/ExternalReportExtensions.java @@ -37,11 +37,14 @@ private ExternalReportExtensions() { } public static void define(Context context) { - context.addExtension(CheckstyleSensor.class); - context.addExtension(PmdSensor.class); - context.addExtension(SpotBugsSensor.class); + var checkstyleSensor = new CheckstyleSensor(context.getRuntime()); + var pmdSensor = new PmdSensor(context.getRuntime()); + var spotBugsSensor = new SpotBugsSensor(context.getRuntime()); + context.addExtension(checkstyleSensor); + context.addExtension(pmdSensor); + context.addExtension(spotBugsSensor); - context.addExtension(new ExternalRulesDefinition(CheckstyleSensor.RULE_LOADER, CheckstyleSensor.LINTER_KEY)); + context.addExtension(new ExternalRulesDefinition(checkstyleSensor.ruleLoader(), CheckstyleSensor.LINTER_KEY)); context.addExtension( PropertyDefinition.builder(CheckstyleSensor.REPORT_PROPERTY_KEY) .name("Checkstyle Report Files") @@ -52,7 +55,7 @@ public static void define(Context context) { .multiValues(true) .build()); - context.addExtension(new ExternalRulesDefinition(PmdSensor.RULE_LOADER, PmdSensor.LINTER_KEY)); + context.addExtension(new ExternalRulesDefinition(pmdSensor.ruleLoader(), PmdSensor.LINTER_KEY)); context.addExtension( PropertyDefinition.builder(PmdSensor.REPORT_PROPERTY_KEY) .name("PMD Report Files") @@ -63,9 +66,9 @@ public static void define(Context context) { .multiValues(true) .build()); - context.addExtension(new ExternalRulesDefinition(SpotBugsSensor.RULE_LOADER, SpotBugsSensor.SPOTBUGS_KEY)); - context.addExtension(new ExternalRulesDefinition(SpotBugsSensor.FINDSECBUGS_LOADER, SpotBugsSensor.FINDSECBUGS_KEY)); - context.addExtension(new ExternalRulesDefinition(SpotBugsSensor.FBCONTRIB_LOADER, SpotBugsSensor.FBCONTRIB_KEY)); + context.addExtension(new ExternalRulesDefinition(spotBugsSensor.ruleLoader(), SpotBugsSensor.SPOTBUGS_KEY)); + context.addExtension(new ExternalRulesDefinition(spotBugsSensor.findSecBugsLoader(), SpotBugsSensor.FINDSECBUGS_KEY)); + context.addExtension(new ExternalRulesDefinition(spotBugsSensor.fbContribLoader(), SpotBugsSensor.FBCONTRIB_KEY)); context.addExtension( PropertyDefinition.builder(SpotBugsSensor.REPORT_PROPERTY_KEY) .name("SpotBugs Report Files")