File tree Expand file tree Collapse file tree
docs/java-custom-rules-example
main/java/org/sonar/samples/java/checks
test/java/org/sonar/samples/java/checks Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424 <dependency >
2525 <groupId >org.sonarsource.api.plugin</groupId >
2626 <artifactId >sonar-plugin-api</artifactId >
27+ <version >9.9.0.229</version >
2728 <scope >provided</scope >
2829 </dependency >
2930 <dependency >
3031 <groupId >org.slf4j</groupId >
3132 <artifactId >slf4j-api</artifactId >
3233 <scope >provided</scope >
3334 </dependency >
34- <dependency >
35- <groupId >org.sonarsource.api.plugin</groupId >
36- <artifactId >sonar-plugin-api-test-fixtures</artifactId >
37- <scope >test</scope >
38- </dependency >
3935 <dependency >
4036 <groupId >org.sonarsource.java</groupId >
4137 <artifactId >sonar-java-plugin</artifactId >
6359 <scope >test</scope >
6460 </dependency >
6561
62+ <dependency >
63+ <groupId >org.junit.jupiter</groupId >
64+ <artifactId >junit-jupiter-migrationsupport</artifactId >
65+ <scope >test</scope >
66+ </dependency >
67+
6668 <dependency >
6769 <groupId >org.assertj</groupId >
6870 <artifactId >assertj-core</artifactId >
Original file line number Diff line number Diff line change 55package org .sonar .samples .java .checks ;
66
77import java .util .Locale ;
8- import org .slf4j .Logger ;
9- import org .slf4j . LoggerFactory ;
8+ import org .sonar . api . utils . log .Logger ;
9+ import org .sonar . api . utils . log . Loggers ;
1010import org .sonar .check .Rule ;
1111import org .sonar .plugins .java .api .JavaFileScanner ;
1212import org .sonar .plugins .java .api .JavaFileScannerContext ;
1717@ Rule (key = "AvoidBrandInMethodNames" )
1818public class AvoidBrandInMethodNamesRule extends BaseTreeVisitor implements JavaFileScanner {
1919
20- private static final Logger LOGGER = LoggerFactory . getLogger (AvoidBrandInMethodNamesRule .class );
20+ private static final Logger LOGGER = Loggers . get (AvoidBrandInMethodNamesRule .class );
2121
2222 private JavaFileScannerContext context ;
2323
Original file line number Diff line number Diff line change 55package org .sonar .samples .java .checks ;
66
77import java .util .List ;
8- import org .slf4j .Logger ;
9- import org .slf4j . LoggerFactory ;
8+ import org .sonar . api . utils . log .Logger ;
9+ import org .sonar . api . utils . log . Loggers ;
1010import org .sonar .check .Rule ;
1111import org .sonar .check .RuleProperty ;
1212import org .sonar .plugins .java .api .JavaFileScanner ;
2626@ Rule (key = "SecurityAnnotationMandatory" )
2727public class SecurityAnnotationMandatoryRule extends BaseTreeVisitor implements JavaFileScanner {
2828
29- private static final Logger LOGGER = LoggerFactory . getLogger (SecurityAnnotationMandatoryRule .class );
29+ private static final Logger LOGGER = Loggers . get (SecurityAnnotationMandatoryRule .class );
3030
3131 private static final String DEFAULT_VALUE = "MySecurityAnnotation" ;
3232
Original file line number Diff line number Diff line change 44 */
55package org .sonar .samples .java .checks ;
66
7+ import org .junit .Rule ;
78import org .junit .jupiter .api .Test ;
8- import org .junit .jupiter .api . extension . RegisterExtension ;
9- import org .slf4j . event . Level ;
10- import org .sonar .api .testfixtures .log .LogTesterJUnit5 ;
9+ import org .junit .jupiter .migrationsupport . rules . EnableRuleMigrationSupport ;
10+ import org .sonar . api . utils . log . LogTester ;
11+ import org .sonar .api .utils .log .LoggerLevel ;
1112import org .sonar .java .checks .verifier .CheckVerifier ;
1213
14+ @ EnableRuleMigrationSupport
1315class AvoidBrandInMethodNamesRuleTest {
1416
1517 // Set a LogTester to see the Syntax Tree when running tests and executing the rule
16- @ RegisterExtension
17- public LogTesterJUnit5 logTester = new LogTesterJUnit5 ().setLevel (Level .DEBUG );
18+ @ Rule
19+ public LogTester logTester = new LogTester ().setLevel (LoggerLevel .DEBUG );
1820
1921 @ Test
2022 void detected () {
Original file line number Diff line number Diff line change 44 */
55package org .sonar .samples .java .checks ;
66
7+ import org .junit .Rule ;
78import org .junit .jupiter .api .Test ;
8- import org .junit .jupiter .api . extension . RegisterExtension ;
9- import org .slf4j . event . Level ;
10- import org .sonar .api .testfixtures .log .LogTesterJUnit5 ;
9+ import org .junit .jupiter .migrationsupport . rules . EnableRuleMigrationSupport ;
10+ import org .sonar . api . utils . log . LogTester ;
11+ import org .sonar .api .utils .log .LoggerLevel ;
1112import org .sonar .java .checks .verifier .CheckVerifier ;
1213
14+ @ EnableRuleMigrationSupport
1315class SecurityAnnotationMandatoryRuleTest {
1416
1517 // Set a LogTester to see the Syntax Tree when running tests and executing the rule
16- @ RegisterExtension
17- public LogTesterJUnit5 logTester = new LogTesterJUnit5 ().setLevel (Level .DEBUG );
18+ @ Rule
19+ public LogTester logTester = new LogTester ().setLevel (LoggerLevel .DEBUG );
1820
1921 @ Test
2022 void detected () {
You can’t perform that action at this time.
0 commit comments