forked from typetools/checker-framework
-
Notifications
You must be signed in to change notification settings - Fork 18
/
build.gradle
1335 lines (1202 loc) · 57.7 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import de.undercouch.gradle.tasks.download.Download
buildscript {
dependencies {
if (JavaVersion.current() >= JavaVersion.VERSION_11) {
// Code formatting; defines targets "spotlessApply" and "spotlessCheck".
// https://github.com/diffplug/spotless/tags ; see tags starting "gradle/"
// Only works on JDK 11+.
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.25.0'
}
}
}
plugins {
// https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow
id 'com.github.johnrengelman.shadow' version '8.1.1'
// https://plugins.gradle.org/plugin/de.undercouch.download
id 'de.undercouch.download' version '5.6.0'
id 'java'
// https://github.com/tbroyer/gradle-errorprone-plugin
id 'net.ltgt.errorprone' version '4.1.0'
// https://docs.gradle.org/current/userguide/eclipse_plugin.html
id 'eclipse'
// To show task list as a tree, run: ./gradlew <taskname> taskTree
id 'com.dorongold.task-tree' version '4.0.0'
}
apply plugin: 'de.undercouch.download'
// There is another `repositories { ... }` block below; if you change this one, change that one as well.
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/'}
mavenCentral()
}
def majorVersionToInt(majorVersionString) {
if (majorVersionString.endsWith("-ea")) {
majorVersionString = majorVersionString.substring(0, majorVersionString.length() - 3)
}
return Integer.valueOf(majorVersionString)
}
ext {
release = false
// On a Java 8 JVM, use error-prone javac and source/target 8.
// On a Java 9+ JVM, use the host javac, default source/target, and required module flags.
isJava8 = JavaVersion.current() == JavaVersion.VERSION_1_8
// The int corresponding to the major version of the current JVM.
currentRuntimeJavaVersion = majorVersionToInt(JavaVersion.current().getMajorVersion())
// As of 2024-08-06, delombok doesn't yet support JDK 23; see https://projectlombok.org/changelog .
skipDelombok = currentRuntimeJavaVersion >= 23
parentDir = file("${rootDir}/../").absolutePath
// NO-AFU
// annotationTools = "${parentDir}/annotation-tools"
// afu = "${annotationTools}/annotation-file-utilities"
jtregHome = "${parentDir}/jtreg"
gitScriptsHome = "${project(':checker').projectDir}/bin-devel/.git-scripts"
plumeScriptsHome = "${project(':checker').projectDir}/bin-devel/.plume-scripts"
htmlToolsHome = "${project(':checker').projectDir}/bin-devel/.html-tools"
doLikeJavacHome = "${project(':checker').projectDir}/bin/.do-like-javac"
javadocMemberLevel = JavadocMemberLevel.PROTECTED
// The local git repository, typically in the .git directory, but not for worktrees.
// This value is always overwritten, but Gradle needs the variable to be initialized.
localRepo = '.git'
versions = [
autoValue : '1.11.0',
errorprone : '2.35.1',
hashmapUtil : '0.0.1',
junit : '4.13.2',
lombok : '1.18.34',
// plume-util includes a version of reflection-util. When updating ensure the versions are consistent.
plumeUtil : '1.9.0',
reflectionUtil : '1.1.3',
]
}
// Keep in sync with check in
// framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java .
switch (JavaVersion.current()) {
case JavaVersion.VERSION_1_8:
case JavaVersion.VERSION_11:
case JavaVersion.VERSION_17:
case JavaVersion.VERSION_21:
break; // Supported versions
default:
logger.info('The Checker Framework has only been tested with JDK 8, 11, 17, and 21.' +
' You are using JDK ' + JavaVersion.current().majorVersion + '.');
break;
}
task setLocalRepo(type:Exec) {
commandLine 'git', 'worktree', 'list'
standardOutput = new ByteArrayOutputStream()
doLast {
String worktreeList = standardOutput.toString()
localRepo = worktreeList.substring(0, worktreeList.indexOf(' ')) + '/.git'
}
}
// No group so it does not show up in the output of `gradlew tasks`
task installGitHooks(type: Copy, dependsOn: 'setLocalRepo') {
description 'Copies git hooks to .git directory'
from files('checker/bin-devel/git.post-merge', 'checker/bin-devel/git.pre-commit')
rename('git\\.(.*)', '$1')
into localRepo + '/hooks'
}
if (currentRuntimeJavaVersion >= 11) {
apply plugin: 'com.diffplug.spotless'
spotless {
// Resolve the Spotless plugin dependencies from the buildscript repositories rather than the
// project repositories. That way the spotless plugin does not use the locally built version of
// checker-qual as a dependency. Without this, errors like the follow are issued when running
// a spotless task without a locally-built version of checker-qual.jar:
// Could not determine the dependencies of task ':checker-qual:spotlessCheck'.
// > Could not create task ':checker-qual:spotlessJavaCheck'.
// > Could not create task ':checker-qual:spotlessJava'.
// > File signature can only be created for existing regular files, given:
// .../checker-framework/checker-qual/build/libs/checker-qual-3.25.1-SNAPSHOT.jar
predeclareDepsFromBuildscript()
}
spotlessPredeclare {
// Put all the formatters that have dependencies here. Without this, errors like the following
// will happen:
// Could not determine the dependencies of task ':spotlessCheck'.
// > Could not create task ':spotlessJavaCheck'.
// > Could not create task ':spotlessJava'.
// > Add a step with [com.google.googlejavaformat:google-java-format:1.15.0] into the `spotlessPredeclare` block in the root project.
java {
googleJavaFormat()
}
groovyGradle {
greclipse()
}
}
}
allprojects {
// Increment the minor version (second number) rather than just the patch
// level (third number) if:
// * any new checkers have been added, or
// * backward-incompatible changes have been made to APIs or elsewhere.
// To make a snapshot release: ./gradlew publish
version '3.42.0-eisop5-SNAPSHOT'
tasks.withType(JavaCompile).configureEach {
options.fork = true
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'de.undercouch.download'
apply plugin: 'net.ltgt.errorprone'
group 'io.github.eisop'
// Keep in sync with "repositories { ... }" block above.
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/'}
mavenCentral()
}
configurations {
// This is required to run the Checker Framework on JDK 8.
javacJar
// Holds the combined classpath of all subprojects including the subprojects themselves.
allProjects
// Exclude checker-qual dependency added by Error Prone to avoid a circular dependency.
annotationProcessor.exclude group:'org.checkerframework', module:'checker-qual'
}
dependencies {
javacJar group: 'com.google.errorprone', name: 'javac', version: "9+181-r4173-1"
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
allProjects subprojects
}
eclipse.classpath {
defaultOutputDir = file("build/default")
file.whenMerged { cp ->
cp.entries.forEach { cpe ->
if (cpe instanceof org.gradle.plugins.ide.eclipse.model.SourceFolder) {
cpe.output = cpe.output.replace "bin/", "build/classes/java/"
}
if (cpe instanceof org.gradle.plugins.ide.eclipse.model.Output) {
cpe.path = cpe.path.replace "bin/", "build/"
}
}
}
}
ext {
// A list of add-export and add-open arguments to be used when running the Checker Framework.
// Keep this list in sync with the lists in CheckerMain#getExecArguments,
// the sections with labels "javac-jdk11-non-modularized", "maven", and "sbt" in the manual
// and in the checker-framework-gradle-plugin, CheckerFrameworkPlugin#applyToProject
compilerArgsForRunningCF = [
// These are required in Java 16+ because the --illegal-access option is set to deny
// by default. None of these packages are accessed via reflection, so the module
// only needs to be exported, but not opened.
'--add-exports',
'jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
// Required because the Checker Framework reflectively accesses private members in com.sun.tools.javac.comp.
'--add-opens',
'jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
]
}
if (currentRuntimeJavaVersion >= 11) {
apply plugin: 'com.diffplug.spotless'
spotless {
// If you add any formatters to this block that require dependencies, then you must also
// add them to spotlessPredeclare block.
def doNotFormat = [
'checker/bin-devel/.git-scripts/**',
'checker/bin-devel/.plume-scripts/**',
'checker/tests/ainfer-*/annotated/*',
'dataflow/manual/examples/',
'**/nullness-javac-errors/*',
'**/calledmethods-delomboked/*',
'**/returnsreceiverdelomboked/*',
'**/build/**',
'*/dist/**',
]
if (currentRuntimeJavaVersion < 14) {
doNotFormat += ['**/*record*/']
}
if (currentRuntimeJavaVersion < 16) {
// TODO: directories should be renamed `-switchexpr` or some such,
// as they only contain examples for switch expressions, which were
// added in Java 14, not Java 17.
doNotFormat += ['**/java17/']
}
if (currentRuntimeJavaVersion < 21) {
doNotFormat += ['**/java21/']
}
format 'misc', {
// define the files to apply `misc` to
target '*.md', '*.tex', '.gitignore', 'Makefile'
targetExclude doNotFormat
// define the steps to apply to those files
indentWithSpaces(2)
trimTrailingWhitespace()
// endWithNewline() // Don't want to end empty files with a newline
}
java {
def targets = [
// add target folders here
'checker',
'checker-qual',
'checker-util',
'dataflow',
'docs/examples',
'docs/tutorial',
'framework',
'framework-test',
'javacutil',
]
targets = targets.collectMany {
[
// must call toString() to convert GString to String
"${it}/**/*.java".toString(),
"${it}/**/*.ajava".toString()
]
}
target targets
targetExclude doNotFormat
googleJavaFormat().aosp()
importOrder('com', 'jdk', 'lib', 'lombok', 'org', 'java', 'javax')
formatAnnotations().addTypeAnnotation("PolyInitialized").addTypeAnnotation("PolyVP").addTypeAnnotation("ReceiverDependentQual")
}
groovyGradle {
target '**/*.gradle'
targetExclude doNotFormat
greclipse() // which formatter Spotless should use to format .gradle files.
indentWithSpaces(4)
trimTrailingWhitespace()
// endWithNewline() // Don't want to end empty files with a newline
}
}
}
test {
minHeapSize = "256m" // initial heap size
maxHeapSize = "4g" // maximum heap size
}
// configurations.errorprone is no longer resolvable, work around this.
def errorproneProcessorCustom = configurations.resolvable("errorproneProcessorCustom") {
extendsFrom(configurations.errorprone)
}
// After all the tasks have been created, modify some of them.
afterEvaluate {
configurations {
checkerFatJar {
canBeConsumed = false
canBeResolved = true
}
}
dependencies {
checkerFatJar(project(path: ':checker', configuration: 'fatJar'))
}
// Add the fat checker.jar to the classpath of every Javadoc task. This allows Javadoc in
// any module to reference classes in any other module.
// Also, build and use ManualTaglet as a taglet.
tasks.withType(Javadoc) {
// Similar test in framework-test/build.gradle
def tagletVersion = isJava8 ? 'tagletJdk8' : 'taglet'
dependsOn(':checker:shadowJar')
dependsOn(":framework-test:${tagletVersion}Classes")
doFirst {
options.encoding = 'UTF-8'
if (!name.equals('javadocDoclintAll')) {
options.memberLevel = javadocMemberLevel
}
classpath += configurations.getByName('checkerFatJar').asFileTree
if (isJava8) {
classpath += configurations.javacJar
}
options.taglets 'org.checkerframework.taglet.ManualTaglet'
options.tagletPath(project(':framework-test').sourceSets."${tagletVersion}".output.classesDirs.getFiles() as File[])
// This file is looked for by Javadoc.
file("${destinationDir}/resources/fonts/").mkdirs()
ant.touch(file: "${destinationDir}/resources/fonts/dejavu.css")
if (!isJava8) {
options.addBooleanOption('-add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED', true)
options.addBooleanOption('-add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED', true)
options.addBooleanOption('-add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED', true)
options.addBooleanOption('-add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED', true)
options.addBooleanOption('-add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED', true)
options.addBooleanOption('-add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED', true)
options.addBooleanOption('-add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED', true)
options.addBooleanOption('-add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED', true)
options.addBooleanOption('-add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED', true)
}
// "-Xwerror" requires Javadoc everywhere. Currently, CI jobs require Javadoc only
// on changed lines. Enable -Xwerror in the future when all Javadoc exists.
// options.addBooleanOption('Xwerror', true)
options.addStringOption('Xmaxwarns', '99999')
}
}
// Add standard javac options
tasks.withType(JavaCompile) { compilationTask ->
dependsOn(':installGitHooks')
String useJdkCompilerProp = project.getProperties().get('useJdkCompiler')
int useJdkCompiler
if (useJdkCompilerProp == null) {
// If the property is not given, use the same version as the runtime.
useJdkCompiler = currentRuntimeJavaVersion
} else {
useJdkCompiler = majorVersionToInt(useJdkCompilerProp)
boolean useToolchains = (currentRuntimeJavaVersion != useJdkCompiler)
if (!isJava8 && useToolchains) {
// This uses the requested Java compiler to compile all code.
// CI test test-cftests-junit-jdk21 runs the JUnit tests on the different JDK versions,
// to ensure there is no version mismatch between compiled-against javac APIs and runtime APIs.
// https://docs.gradle.org/current/userguide/toolchains.html
// This property is final on Java 8, so don't set it then.
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(useJdkCompiler)
}
}
}
// Sorting is commented out because it disables incremental compilation.
// Uncomment when needed.
// // Put source files in deterministic order, for debugging.
// compilationTask.source = compilationTask.source.sort()
// This test is for whether the Checker Framework supports (runs under) Java 8.
// Currently, the Checker Framework does support Java 8.
if (true) {
// Using `options.release.set(8)` here leads to compilation
// errors such as "package com.sun.source.tree does not exist".
sourceCompatibility = 8
targetCompatibility = 8
// Because the target is 8, all of the public compiler classes are accessible, so
// --add-exports are not required (nor are they allowed with target 8). See
// https://openjdk.org/jeps/247 for details on compiling for older versions.
} else {
// This makes the class files Java 11, and then the Checker Framework would not run under Java 8.
options.release.set(11)
options.compilerArgs += [
'--add-exports',
'jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'--add-exports',
'jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
]
// This is equivalent to writing "exports jdk.compiler/... to ALL-UNNAMED" in the
// module-info.java of jdk.compiler, so corresponding --add-opens are only required for
// reflective access to private members.
//
// From https://openjdk.org/jeps/261, Section titled: "Breaking encapsulation"
// "The effect of each instance [of --add-exports] is to add a qualified export of the
// named package from the source module to the target module. This is, essentially, a
// command-line form of an exports clause in a module declaration[...].
// [...]
// The --add-exports option enables access to the public types of a specified package.
// It is sometimes necessary to go further and enable access to all non-public elements
// via the setAccessible method of the core reflection API. The --add-opens option can
// be used, at run time, to do this."
}
options.failOnError = true
options.deprecation = true
// -options: To not get a warning about missing bootstrap classpath (when using Java 9 and `-source 8`).
// -fallthrough: Don't check fallthroughs. Instead, use Error Prone. Its
// warnings are suppressible with a "// fall through" comment.
// -classfile: classgraph jar file and https://bugs.openjdk.org/browse/JDK-8190452
String lint = '-Xlint:-options,-fallthrough,-classfile'
// Java 8 uses the Error Prone javac, not what is requested with useJdkCompiler.
// So there is no need to set additional lint options.
if (!isJava8) {
if (useJdkCompiler >= 21) {
// TODO: Ignore this-escape for now, we may want to review and suppress each one later.
lint +=',-this-escape'
}
if (useJdkCompiler >= 23) {
// TODO: Ignore dangling-doc-comments for now, we may want to fix them later.
lint +=',-dangling-doc-comments'
}
}
options.compilerArgs += [
'-g',
'-Werror',
lint,
'-Xlint',
]
options.encoding = 'UTF-8'
options.fork = true
if (isJava8) {
options.forkOptions.jvmArgs += [
"-Xbootclasspath/p:${configurations.javacJar.asPath}".toString()
]
}
// Error Prone depends on checker-qual.jar, so don't run it on that project to avoid a circular dependency.
if ((compilationTask.name.equals('compileJava') || compilationTask.name.equals('compileTestJava')) && !project.name.startsWith('checker-qual')) {
// Error Prone must be available in the annotation processor path
options.annotationProcessorPath = errorproneProcessorCustom.get()
// Enable Error Prone
options.errorprone.enabled = (useJdkCompiler >= 17) && (useJdkCompiler <= 23)
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.errorproneArgs = [
// Many compiler classes are interned.
'-Xep:ReferenceEquality:OFF',
// These might be worth fixing.
'-Xep:DefaultCharset:OFF',
// Not useful to suggest Splitter; maybe clean up.
'-Xep:StringSplitter:OFF',
// Too broad, rejects seemingly-correct code.
'-Xep:EqualsGetClass:OFF',
// Not a real problem
'-Xep:MixedMutabilityReturnType:OFF',
// Don't want to add a dependency to ErrorProne.
'-Xep:AnnotateFormatMethod:OFF',
// Warns for every use of "@checker_framework.manual"
'-Xep:InvalidBlockTag:OFF',
// Recommends writing @InlineMe which is an Error-Prone-specific annotation
'-Xep:InlineMeSuggester:OFF',
// Recommends writing @CanIgnoreReturnValue which is an Error-Prone-specific annotation.
// It would be great if Error Prone recognized the @This annotation.
'-Xep:CanIgnoreReturnValueSuggester:OFF',
// Should be turned off when using the Checker Framework.
'-Xep:ExtendsObject:OFF',
// For Visitors it is convenient to just pass a Void parameter.
'-Xep:VoidUsed:OFF',
// -Werror halts the build if Error Prone issues a warning, which ensures that
// the errors get fixed. On the downside, Error Prone (or maybe the compiler?)
// stops as soon as it issues one warning, rather than outputting them all.
// https://github.com/google/error-prone/issues/436
'-Werror',
]
if (!isJava8) {
// Options needed for Error Prone on Java 16+, but don't hurt on Java 9+
options.forkOptions.jvmArgs += [
'--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
'--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
]
}
} else {
options.errorprone.enabled = false
}
}
} // end afterEvaluate
} // end allProjects
task version(group: 'Documentation') {
description 'Print Checker Framework version'
doLast {
println version
}
}
/**
* Creates a task that runs the checker on the main source set of each subproject. The task is named
* "check${taskName}", for example "checkPurity" or "checkNullness".
*
* @param projectName name of the project
* @param taskName short name (often the checker name) to use as part of the task name
* @param checker fully qualified name of the checker to run
* @param args list of arguments to pass to the checker
*/
def createCheckTypeTask(projectName, taskName, checker, args = []) {
project("${projectName}").tasks.create(name: "check${taskName}", type: JavaCompile, dependsOn: ':checker:shadowJar') {
description "Run the ${taskName} Checker on the main sources."
group 'Verification'
// Always run the task.
outputs.upToDateWhen { false }
source = project("${projectName}").sourceSets.main.java
classpath = files(project("${projectName}").compileJava.classpath,project(':checker-qual').sourceSets.main.output)
destinationDirectory = file("${buildDir}")
options.annotationProcessorPath = files(project(':checker').tasks.shadowJar.archiveFile)
options.compilerArgs += [
'-processor',
"${checker}",
'-proc:only',
'-Xlint:-processing',
'-Xmaxerrs',
'10000',
'-Xmaxwarns',
'10000',
'-ArequirePrefixInWarningSuppressions',
'-AwarnUnneededSuppressions',
'-AwarnRedundantAnnotations',
'-AnoJreVersionCheck',
]
options.compilerArgs += args
options.forkOptions.jvmArgs += ['-Xmx2g']
if (isJava8) {
options.compilerArgs += [
'-source',
'8',
'-target',
'8'
]
} else {
options.fork = true
options.forkOptions.jvmArgs += compilerArgsForRunningCF
}
}
}
task htmlValidate(type: Exec, group: 'Format') {
description 'Validate that HTML files are well-formed'
executable 'html5validator'
args = [
'--ignore',
'/api/',
'/build/',
'/docs/manual/manual.html',
'/docs/manual/plume-bib/docs/index.html',
'/checker/jdk/nullness/src/java/lang/ref/package.html'
]
}
def javadocDirs = [
project(':checker').sourceSets.main.allJava,
project(':checker').sourceSets.test.allJava,
project(':checker-qual').sourceSets.main.allJava,
project(':checker-util').sourceSets.main.allJava,
project(':checker-util').sourceSets.test.allJava,
project(':dataflow').sourceSets.main.allJava,
project(':dataflow').sourceSets.test.allJava,
project(':framework').sourceSets.main.allJava,
project(':framework').sourceSets.test.allJava,
project(':framework-test').sourceSets.main.allJava,
project(':framework-test').sourceSets.test.allJava,
project(':javacutil').sourceSets.main.allJava
]
def requireJavadocDirs = javadocDirs
project(':checker').afterEvaluate {
requireJavadocDirs += project(':checker').sourceSets.testannotations.allJava
}
project(':framework').afterEvaluate {
requireJavadocDirs += project(':framework').sourceSets.testannotations.allJava
}
// `gradle allJavadoc` builds the Javadoc for all modules in `docs/api`.
// This is what is published to checkerframework.org.
// `gradle javadoc` builds the Javadoc for each sub-project in <subproject>/build/docs/javadoc/ .
// It's needed to create the Javadoc jars that we release in Maven Central.
// To make javadoc for only one subproject, run `./gradlew javadoc`
// in the subproject or `./gradlew :checker:javadoc` at the top level.
task allJavadoc(type: Javadoc, group: 'Documentation') {
description = 'Generates API documentation that includes all the modules.'
dependsOn(':checker:shadowJar', 'getPlumeScripts', 'getHtmlTools')
destinationDir = file("${rootDir}/docs/api")
source javadocDirs
doFirst {
source(
project(':framework-test').sourceSets."${isJava8 ? 'tagletJdk8' : 'taglet'}".allJava
)
}
classpath = configurations.allProjects
if (isJava8) {
classpath += configurations.javacJar
}
doLast {
copy {
from 'docs/logo/Checkmark/CFCheckmark_favicon.png'
rename('CFCheckmark_favicon.png', 'favicon-checkerframework.png')
into "${rootDir}/docs/api"
}
exec {
workingDir "${rootDir}/docs/api"
executable "${htmlToolsHome}/html-add-favicon"
args += [
'.',
'favicon-checkerframework.png'
]
}
}
}
// See documentation for allJavadoc task.
javadoc.dependsOn(allJavadoc)
configurations {
requireJavadoc
}
dependencies {
requireJavadoc 'org.plumelib:require-javadoc:1.0.9'
}
task requireJavadoc(type: JavaExec, group: 'Documentation') {
description = 'Ensures that Javadoc documentation exists in source code.'
mainClass = 'org.plumelib.javadoc.RequireJavadoc'
classpath = configurations.requireJavadoc
// Convert each srcDir to its absolute path and flatten the list
args requireJavadocDirs.collect { it.srcDirs*.absolutePath }.flatten()
}
/**
* Creates a task named taskName that runs javadoc with the -Xdoclint:all option.
*
* @param taskName the name of the task to create
* @param taskDescription description of the task
* @param memberLevel the JavadocMemberLevel to use
* @return the new task
*/
def createJavadocTask(taskName, taskDescription, memberLevel) {
tasks.create(name: taskName, type: Javadoc) {
description = taskDescription
destinationDir = file("${rootDir}/docs/tmpapi")
destinationDir.mkdirs()
subprojects.forEach {
if (!it.name.startsWith('checker-qual-android')) {
source += it.sourceSets.main.allJava
}
}
classpath = configurations.allProjects
destinationDir.deleteDir()
options.memberLevel = memberLevel
options.addBooleanOption('Xdoclint:all', true)
options.addStringOption('Xmaxwarns', '99999')
// options.addStringOption('skip', 'ClassNotToCheck|OtherClass')
}
}
createJavadocTask('javadocDoclintAll', 'Runs javadoc with -Xdoclint:all option.', JavadocMemberLevel.PRIVATE)
task manual(group: 'Documentation') {
description 'Build the manual'
doLast {
exec {
commandLine 'make', '-C', 'docs/manual', 'all'
}
}
}
// No group so it does not show up in the output of `gradlew tasks`
task downloadJtreg(type: Download) {
description "Downloads and unpacks jtreg."
onlyIf { !(new File("${jtregHome}/lib/jtreg.jar").exists()) }
// src 'https://ci.adoptopenjdk.net/view/Dependencies/job/jtreg/lastSuccessfulBuild/artifact/jtreg-4.2.0-tip.tar.gz'
// If ci.adoptopenjdk.net is down, use this copy.
// src 'https://checkerframework.org/jtreg-4.2.0-tip.tar.gz'
// dest new File(buildDir, 'jtreg-4.2.0-tip.tar.gz')
// src 'https://builds.shipilev.net/jtreg/jtreg4.2-b16.zip'
src 'https://builds.shipilev.net/jtreg/jtreg-6.2%2B1.zip'
dest new File(buildDir, 'jtreg.zip')
overwrite true
retries 3
doLast {
copy {
// Use 'tarTree' when downloading a .tar.gz file
from zipTree(dest)
into "${jtregHome}/.."
}
exec {
commandLine('chmod', '+x', "${jtregHome}/bin/jtdiff", "${jtregHome}/bin/jtreg")
}
}
}
/**
* Quietly clones the given git repository, {@code url}, to {@code directory} at a depth of 1.
*
* @param url git repository to clone
* @param directory where to clone
* @param ignoreError whether to fail the build if the clone command fails
* @param extraArgs any extra arguments to pass to git
*/
void clone(url, directory, ignoreError, extraArgs = []){
exec {
workingDir "${directory}/../"
executable 'git'
args = [
'clone',
'-q',
'--filter=blob:none',
url,
file(directory).toPath().last()
]
args += extraArgs
ignoreExitValue = ignoreError
timeout = 60000 // 60 seconds
}
}
/**
* Creates a task named {@code taskName} that updates or clones the git repository at
* {@code url} into {@code directory}. If the clone command fails, the task waits
* a minute and then trys again.
*
* @param taskName name of the created task
* @param url location of the git repository
* @param directory where to clone the repository
* @param extraArgs arguments to pass to the git command
*/
def createCloneTask(taskName, url, directory, extraArgs = []) {
tasks.create(name: taskName) {
description "Obtain or update ${url}"
// Always run.
outputs.upToDateWhen { false }
doLast {
if (file(directory).exists()) {
exec {
workingDir directory
executable 'git'
args = ['pull', '-q']
ignoreExitValue = true
timeout = 60000 // 60 seconds
}
} else {
try {
clone(url, directory, true, extraArgs)
} catch (Throwable t) {
println "Exception while cloning ${url}"
t.printStackTrace()
}
if (!file(directory).exists()) {
println "Cloning failed, will try again in 1 minute: clone(${url}, ${directory}, true, ${extraArgs})"
sleep(60000) // wait 1 minute, then try again
clone(url, directory, false, extraArgs)
}
}
}
}
}
createCloneTask('getGitScripts', 'https://github.com/eisop-plume-lib/git-scripts.git', gitScriptsHome)
createCloneTask('getPlumeScripts', 'https://github.com/eisop-plume-lib/plume-scripts.git', plumeScriptsHome)
createCloneTask('getHtmlTools', 'https://github.com/plume-lib/html-tools.git', htmlToolsHome)
createCloneTask('getDoLikeJavac', 'https://github.com/opprop/do-like-javac.git', doLikeJavacHome)
// No group so it does not show up in the output of `gradlew tasks`
task pythonIsInstalled(type: Exec) {
description 'Check that the python3 executable is installed.'
executable = 'python3'
args '--version'
}
task tags {
group 'Emacs'
description 'Create Emacs TAGS table'
doLast {
exec {
commandLine 'etags', '-i', 'checker/TAGS', '-i', 'checker-qual/TAGS', '-i', 'checker-util/TAGS', '-i', 'dataflow/TAGS', '-i', 'framework/TAGS', '-i', 'framework-test/TAGS', '-i', 'javacutil/TAGS', '-i', 'docs/manual/TAGS'
}
exec {
commandLine 'make', '-C', 'docs/manual', 'tags'
}
}
}
subprojects {
configurations {
errorprone
annotatedGuava
}
dependencies {
// https://mvnrepository.com/artifact/com.google.errorprone/error_prone_core
// If you update this:
// * Temporarily comment out "-Werror" elsewhere in this file
// * Repeatedly run `./gradlew clean compileJava` and fix all errors
// * Uncomment "-Werror"
if (currentRuntimeJavaVersion >= 17) {
errorprone group: 'com.google.errorprone', name: 'error_prone_core', version: versions.errorprone
} else {
// EP 2.31.0 is the last release that works on Java < 17.
errorprone group: 'com.google.errorprone', name: 'error_prone_core', version: '2.31.0'
}
// TODO: it's a bug that annotatedlib:guava requires the error_prone_annotations dependency.
annotatedGuava "com.google.errorprone:error_prone_annotations:${versions.errorprone}"
annotatedGuava ('org.checkerframework.annotatedlib:guava:33.1.0.2-jre') {
// So long as Guava only uses annotations from checker-qual, excluding it should not cause problems.
exclude group: 'org.checkerframework'
}
}
shadowJar {
// If you add an external dependency, then do the following:
// * On the master branch and on the modified branch, run:
// ./gradlew assembleForJavac && jar tf checker/dist/checker.jar | grep -v '^annotated-jdk/' | sort > checker-jar-contents.txt
// * Compare the files, and add relocate lines below.
// * Repeat until no new classes appear (all are under org/checkerframework/).
// Note that string literals are also relocated. Therefore, when the original
// names should be used, e.g. to load the original classes, one needs to work
// around the relocation. When adding a new external dependency, make
// sure no existing string literals are accidentally relocated.
// For an example work-around see NullnessAnnotatedTypeFactory#NONNULL_ALIASES.
// Relocate packages that might conflict with user's classpath.
relocate 'org.apache', 'org.checkerframework.org.apache'
relocate 'org.relaxng', 'org.checkerframework.org.relaxng'
relocate 'org.plumelib', 'org.checkerframework.org.plumelib'
relocate 'org.codehaus', 'org.checkerframework.org.codehaus'
relocate 'org.objectweb.asm', 'org.checkerframework.org.objectweb.asm'
// Add the classgraph relocations if it is included in releases.
// relocate 'io.github.classgraph', 'org.checkerframework.io.github.classgraph'
// relocate 'nonapi.io.github.classgraph', 'org.checkerframework.nonapi.io.github.classgraph'
// relocate 'sun', 'org.checkerframework.sun'
relocate 'com.google', 'org.checkerframework.com.google'
exclude '**/module-info.class'
doFirst {
if (release) {
// Only relocate JavaParser during a release:
relocate 'com.github.javaparser', 'org.checkerframework.com.github.javaparser'
}
}
minimize()
}
if (!project.name.startsWith('checker-qual-android')) {
task tags(type: Exec) {
description 'Create Emacs TAGS table'
commandLine 'bash', '-c', "find . \\( -name build -o -name jtreg -o -name tests \\) -prune -o -name '*.java' -print | sort-directory-order | xargs ctags -e -f TAGS"
}
}
java {
withJavadocJar()
withSourcesJar()
}
// Things in this block reference definitions in the subproject that do not exist,
// until the project is evaluated.
afterEvaluate {
// Adds manifest to all Jar files
tasks.withType(Jar) {
includeEmptyDirs = false
if (archiveFileName.get().startsWith('checker-qual') || archiveFileName.get().startsWith('checker-util')) {
metaInf {
from './LICENSE.txt'
}
} else {
metaInf {
from "${rootDir}/LICENSE.txt"
}
}
manifest {
attributes('Implementation-Version': "${project.version}")
attributes('Implementation-URL': 'https://eisop.github.io/')
if (! archiveFileName.get().endsWith('source.jar')) {
attributes('Automatic-Module-Name': 'org.checkerframework.' + project.name.replaceAll('-', '.'))
}
if (archiveFileName.get().startsWith('checker-qual') || archiveFileName.get().startsWith('checker-util')) {
attributes('Bundle-License': 'MIT')
} else {
attributes('Bundle-License': '(GPL-2.0-only WITH Classpath-exception-2.0)')
}
}
}
// Tasks such as `checkResourceLeak` to run various checkers on all the main source sets.
// These pass and are run by the `typecheck` task.
// When you add one here, also update a dependsOn item for the 'typecheck' task.
createCheckTypeTask(project.name, 'Formatter',
'org.checkerframework.checker.formatter.FormatterChecker')
createCheckTypeTask(project.name, 'Interning',
'org.checkerframework.checker.interning.InterningChecker',
[
'-Astubs=javax-lang-model-element-name.astub'
])
createCheckTypeTask(project.name, 'Optional',
'org.checkerframework.checker.optional.OptionalChecker',
[
// to avoid having to annotate JavaParser
'-AassumePureGetters',
'-AassumeAssertionsAreEnabled',
])
createCheckTypeTask(project.name, 'Purity',
'org.checkerframework.framework.util.PurityChecker')
createCheckTypeTask(project.name, 'ResourceLeak',
'org.checkerframework.checker.resourceleak.ResourceLeakChecker')
createCheckTypeTask(project.name, 'Signature',
'org.checkerframework.checker.signature.SignatureChecker')
// The checkNullness task runs on all code, but it only *checks* the following code:
// * All files outside the 'framework' and 'checker' subprojects.
// * In the 'framework' and 'checker' subprojects, files with `@AnnotatedFor("nullness")`.