@@ -37,6 +37,7 @@ plugins {
37
37
// Verification
38
38
checkstyle
39
39
calcite.buildext
40
+ id(" org.checkerframework" ) apply false
40
41
id(" com.github.autostyle" )
41
42
id(" org.nosphere.apache.rat" )
42
43
id(" com.github.spotbugs" )
@@ -65,6 +66,7 @@ val lastEditYear by extra(lastEditYear())
65
66
66
67
// Do not enable spotbugs by default. Execute it only when -Pspotbugs is present
67
68
val enableSpotBugs = props.bool(" spotbugs" )
69
+ val enableCheckerframework by props()
68
70
val enableErrorprone by props()
69
71
val skipCheckstyle by props()
70
72
val skipAutostyle by props()
@@ -454,6 +456,8 @@ allprojects {
454
456
replace(" junit5: Assert.fail" , " org.junit.Assert.fail" , " org.junit.jupiter.api.Assertions.fail" )
455
457
}
456
458
replaceRegex(" side by side comments" , " (\n\\ s*+[*]*+/\n )(/[/*])" , " \$ 1\n \$ 2" )
459
+ replaceRegex(" jsr305 nullable -> checkerframework" , " javax\\ .annotation\\ .Nullable" , " org.checkerframework.checker.nullness.qual.Nullable" )
460
+ replaceRegex(" jsr305 nonnull -> checkerframework" , " javax\\ .annotation\\ .Nonnull" , " org.checkerframework.checker.nullness.qual.NonNull" )
457
461
importOrder(
458
462
" org.apache.calcite." ,
459
463
" org.apache." ,
@@ -552,6 +556,43 @@ allprojects {
552
556
}
553
557
}
554
558
}
559
+ if (enableCheckerframework) {
560
+ apply (plugin = " org.checkerframework" )
561
+ dependencies {
562
+ " checkerFramework" (" org.checkerframework:checker:${" checkerframework" .v} " )
563
+ // CheckerFramework annotations might be used in the code as follows:
564
+ // dependencies {
565
+ // "compileOnly"("org.checkerframework:checker-qual")
566
+ // "testCompileOnly"("org.checkerframework:checker-qual")
567
+ // }
568
+ if (JavaVersion .current() == JavaVersion .VERSION_1_8 ) {
569
+ // only needed for JDK 8
570
+ " checkerFrameworkAnnotatedJDK" (" org.checkerframework:jdk8" )
571
+ }
572
+ }
573
+ configure< org.checkerframework.gradle.plugin.CheckerFrameworkExtension > {
574
+ skipVersionCheck = true
575
+ // See https://checkerframework.org/manual/#introduction
576
+ checkers.add(" org.checkerframework.checker.nullness.NullnessChecker" )
577
+ // Below checkers take significant time and they do not provide much value :-/
578
+ // checkers.add("org.checkerframework.checker.optional.OptionalChecker")
579
+ // checkers.add("org.checkerframework.checker.regex.RegexChecker")
580
+ // https://checkerframework.org/manual/#creating-debugging-options-progress
581
+ // extraJavacArgs.add("-Afilenames")
582
+ extraJavacArgs.addAll(listOf (" -Xmaxerrs" , " 10000" ))
583
+ // Consider Java assert statements for nullness and other checks
584
+ extraJavacArgs.add(" -AassumeAssertionsAreEnabled" )
585
+ // https://checkerframework.org/manual/#stub-using
586
+ extraJavacArgs.add(" -Astubs=" +
587
+ fileTree(" $rootDir /src/main/config/checkerframework" ) {
588
+ include(" **/*.astub" )
589
+ }.asPath
590
+ )
591
+ if (project.path == " :core" ) {
592
+ extraJavacArgs.add(" -AskipDefs=^org\\ .apache\\ .calcite\\ .sql\\ .parser\\ .impl\\ ." )
593
+ }
594
+ }
595
+ }
555
596
556
597
tasks {
557
598
configureEach<Jar > {
@@ -585,6 +626,9 @@ allprojects {
585
626
if (werror) {
586
627
options.compilerArgs.add(" -Werror" )
587
628
}
629
+ if (enableCheckerframework) {
630
+ options.forkOptions.memoryMaximumSize = " 2g"
631
+ }
588
632
}
589
633
configureEach<Test > {
590
634
outputs.cacheIf(" test results depend on the database configuration, so we souldn't cache it" ) {
0 commit comments