forked from typetools/checker-framework
/
build.gradle
1044 lines (917 loc) · 44.5 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
plugins {
id 'java-library'
// https://github.com/n0mer/gradle-git-properties ; target is: generateGitProperties
id 'com.gorylenko.gradle-git-properties' version '2.4.1'
}
sourceSets {
main {
resources {
// Stub files, message.properties, etc.
srcDirs += ['src/main/java']
}
}
testannotations
}
sourcesJar {
// The resources duplicate content from the src directory.
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
configurations {
implementation.extendsFrom(annotatedGuava)
fatJar {
canBeConsumed = true
canBeResolved = false
}
}
dependencies {
// Use "api" instead of "implementation" to re-export sub-projects, making
// sure "minimize()" does not remove those classes.
api project(':framework')
/* NO-AFU
// AFU is an "includedBuild" imported in checker-framework/settings.gradle, so the version number doesn't matter.
// https://docs.gradle.org/current/userguide/composite_builds.html#settings_defined_composite
implementation('org.checkerframework:annotation-file-utilities:*') {
exclude group: 'com.google.errorprone', module: 'javac'
}
*/
api project(':checker-qual')
api project(':checker-util')
// External dependencies:
// If you add an external dependency, you must shadow its packages.
// See the comment in ../build.gradle in the shadowJar block.
// As of 2019-12-16, the version of reflection-util in the Annotation
// File Utilities takes priority over this version, in the fat jar
// file. :-( So update it and re-build it locally when updating this.
implementation "org.plumelib:reflection-util:${reflectionUtilVersion}"
implementation "org.plumelib:plume-util:${plumeUtilVersion}"
// Dependencies added to "shadow" appear as dependencies in Maven Central.
shadow project(':checker-qual')
shadow project(':checker-util')
// Called Methods Checker AutoValue + Lombok support
testImplementation "com.google.auto.value:auto-value-annotations:1.7.4"
testImplementation "com.google.auto.value:auto-value:1.7.4"
testImplementation "com.ryanharter.auto.value:auto-value-parcel:0.2.9"
testImplementation "org.projectlombok:lombok:1.18.24"
// Called Methods Checker support for detecting misuses of AWS APIs
testImplementation "com.amazonaws:aws-java-sdk-ec2"
testImplementation "com.amazonaws:aws-java-sdk-kms"
// The AWS SDK is used for testing the Called Methods Checker.
testImplementation platform("com.amazonaws:aws-java-sdk-bom:1.12.293")
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation project(':framework-test')
testImplementation sourceSets.testannotations.output
testannotationsImplementation project(':checker-qual')
}
// It's not clear why this dependencies exists, but Gradle issues the following warning:
// - Gradle detected a problem with the following location:
// '/Users/smillst/jsr308/checker-framework/.git'.
// Reason: Task ':checker:generateGitProperties' uses this output of task ':installGitHooks'
// without declaring an explicit or implicit dependency. This can lead to incorrect results being
// produced, depending on what order the tasks are executed. Please refer to
// https://docs.gradle.org/7.1/userguide/validation_problems.html#implicit_dependency for more
// details about this problem.
generateGitProperties.dependsOn(':installGitHooks')
jar {
manifest {
attributes("Main-Class": "org.checkerframework.framework.util.CheckerMain")
}
}
// checker.jar is copied to checker/dist/ when it is built by the shadowJar task.
task copyJarsToDist(dependsOn: shadowJar, group: 'Build') {
description 'Builds or downloads jars required by CheckerMain and puts them in checker/dist/.'
dependsOn project(':checker-qual').tasks.jar
doLast {
def checkerQualJarFile = file(project(':checker-qual').tasks.getByName("jar").archivePath)
if (!checkerQualJarFile.exists()) {
throw new GradleException("File not found: " + checkerQualJarFile)
}
copy {
from checkerQualJarFile
into "${projectDir}/dist"
rename { String fileName ->
// remove version number on checker-qual.jar
fileName.replace(fileName, "checker-qual.jar")
}
}
def checkerUtilJarFile = file(project(':checker-util').tasks.getByName("jar").archivePath)
if (!checkerUtilJarFile.exists()) {
throw new GradleException("File not found: " + checkerUtilJarFile)
}
copy {
from checkerUtilJarFile
into "${projectDir}/dist"
rename { String fileName ->
// remove version number on checker-util.jar
fileName.replace(fileName, "checker-util.jar")
}
}
copy {
from configurations.javacJar
into "${projectDir}/dist"
rename { String fileName ->
fileName.replace(fileName, "javac.jar")
}
}
}
}
assemble.dependsOn copyJarsToDist
task allSourcesJar(type: Jar, group: 'Build') {
description 'Creates a sources jar that includes sources for all Checker Framework classes in checker.jar'
destinationDirectory = file("${projectDir}/dist")
archiveFileName = "checker-source.jar"
archiveClassifier = "sources"
from (sourceSets.main.java, project(':framework').sourceSets.main.allJava,
project(':dataflow').sourceSets.main.allJava, project(':javacutil').sourceSets.main.allJava,
project(':checker-qual').sourceSets.main.allJava, project(':checker-util').sourceSets.main.allJava)
}
task allJavadocJar(type: Jar, group: 'Build') {
description 'Creates javadoc jar including Javadoc for all of the Checker Framework'
dependsOn rootProject.tasks.allJavadoc
destinationDirectory = file("${projectDir}/dist")
archiveFileName = "checker-javadoc.jar"
archiveClassifier = "javadoc"
from rootProject.tasks.allJavadoc.destinationDir
}
// Shadowing Test Sources and Dependencies
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
task checkerJar(type: ShadowJar, dependsOn: compileJava, group: 'Build') {
description "Builds checker-${project.version}.jar with all dependencies except checker-qual and checker-util."
includeEmptyDirs = false
archivesBaseName = 'checker'
archiveClassifier = ''
from shadowJar.source
configurations = shadowJar.configurations
// To see what files are incorporated into the shadow jar file:
// doLast { println sourceSets.main.runtimeClasspath.asPath }
manifest {
attributes("Main-Class": "org.checkerframework.framework.util.CheckerMain")
}
exclude 'org/checkerframework/**/qual/*'
exclude 'org/checkerframework/checker/*/util/*'
relocators = shadowJar.getRelocators()
}
jar {
dependsOn(checkerJar)
// Never build the skinny jar.
onlyIf {false}
archiveClassifier = 'skinny'
}
shadowJar {
description 'Creates checker-VERSION-all.jar and copies it to dist/checker.jar.'
// To see what files are incorporated into the shadow jar file:
// doFirst { println sourceSets.main.runtimeClasspath.asPath }
doLast{
copy {
from archiveFile.get()
into file("${projectDir}/dist")
rename 'checker.*', 'checker.jar'
}
}
minimize()
}
artifacts {
// Don't add this here or else the Javadoc and the sources jar is built during the assemble task.
// archives allJavadocJar
// archives allSourcesJar
archives shadowJar
archives checkerJar
fatJar(shadowJar)
}
clean {
delete "${projectDir}/dist"
delete "tests/calledmethods-delomboked"
delete("tests/ainfer-testchecker/annotated")
delete("tests/ainfer-testchecker/inference-output")
delete("tests/ainfer-nullness/annotated")
delete("tests/ainfer-nullness/inference-output")
delete("tests/ainfer-index/annotated")
delete("tests/ainfer-index/inference-output")
}
// Add non-junit tests
createCheckTypeTask(project.name, "CompilerMessages",
'org.checkerframework.checker.compilermsgs.CompilerMessagesChecker')
checkCompilerMessages {
doFirst {
options.compilerArgs += [
'-Apropfiles=' + sourceSets.main.resources.filter { file -> file.name.equals('messages.properties') }.asPath + File.pathSeparator
+ project(':framework').sourceSets.main.resources.filter { file -> file.name.equals('messages.properties') }.asPath
]
}
}
task nullnessExtraTests(type: Exec, dependsOn: copyJarsToDist, group: 'Verification') {
description 'Run extra tests for the Nullness Checker.'
executable 'make'
environment JAVAC: "${projectDir}/bin/javac -AnoJreVersionCheck", JAVAP: 'javap'
args = ['-C', 'tests/nullness-extra/']
}
task commandLineTests(type: Exec, dependsOn: copyJarsToDist, group: 'Verification') {
description 'Run tests that need a special command line.'
executable 'make'
environment JAVAC: "${projectDir}/bin/javac -AnoJreVersionCheck"
args = ['-C', 'tests/command-line/']
}
task tutorialTests(dependsOn: copyJarsToDist, group: 'Verification') {
description 'Test that the tutorial is working as expected.'
doLast {
ant.ant(dir: "${rootDir}/docs/tutorial/tests", useNativeBasedir: 'true', inheritAll: 'false') {
target(name: 'check-tutorial')
}
}
}
task exampleTests(type: Exec, dependsOn: copyJarsToDist, group: 'Verification') {
description 'Run tests for the example programs.'
executable 'make'
environment JAVAC: "${projectDir}/bin/javac -AnoJreVersionCheck"
args = ['-C', '../docs/examples']
}
task demosTests(dependsOn: copyJarsToDist, group: 'Verification') {
description 'Test that the demos are working as expected.'
doLast {
if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
File demosDir = new File(projectDir, '../../checker-framework.demos');
if (!demosDir.exists()) {
exec {
workingDir file(demosDir.toString() + '/../')
executable 'git'
args = ['clone', '--depth', '1', 'https://github.com/typetools/checker-framework.demos.git']
}
} else {
exec {
workingDir demosDir
executable 'git'
args = ['pull', 'https://github.com/typetools/checker-framework.demos.git']
ignoreExitValue = true
}
}
ant.properties.put('checker.lib', file("${projectDir}/dist/checker.jar").absolutePath)
ant.ant(dir: demosDir.toString())
} else {
println("Skipping demosTests because they only work with Java 8.")
}
}
}
task allNullnessTests(type: Test, group: 'Verification') {
description 'Run all Junit tests for the Nullness Checker.'
include '**/Nullness*.class'
}
task allCalledMethodsTests(type: Test, group: 'Verification') {
description 'Run all Junit tests for the Called Methods Checker.'
include '**/CalledMethods*.class'
dependsOn 'delombok'
}
// These are tests that should only be run with JDK 11+.
task jtregJdk11Tests(dependsOn: ':downloadJtreg', group: 'Verification') {
description 'Run the jtreg tests made for JDK 11+.'
dependsOn('compileJava')
dependsOn('compileTestJava')
dependsOn('shadowJar')
String jtregOutput = "${buildDir}/jtregJdk11"
String name = 'all'
doLast {
if (isJava8) {
println "This test is only run with JDK 11+."
return;
}
exec {
executable "${jtregHome}/bin/jtreg"
args = [
"-dir:${projectDir}/jtregJdk11",
"-workDir:${jtregOutput}/${name}/work",
"-reportDir:${jtregOutput}/${name}/report",
"-verbose:summary",
"-javacoptions:-g",
"-keywords:!ignore",
"-samevm",
"-javacoptions:-classpath ${tasks.shadowJar.archiveFile.get()}:${sourceSets.test.output.asPath}",
"-vmoptions:-classpath ${tasks.shadowJar.archiveFile.get()}:${sourceSets.test.output.asPath}",
"-vmoptions:--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"-vmoptions:--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"-vmoptions:--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"-vmoptions:--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"-vmoptions:--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"-vmoptions:--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"-vmoptions:--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
"-vmoptions:--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"-vmoptions:--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"-javacoptions:-classpath ${sourceSets.testannotations.output.asPath}",
// Location of jtreg tests
'.'
]
}
}
}
// JSpecify tests are excluded by default. To run them:
// ./gradlew NullnessJSpecifySamplesTest
test {
exclude '**/org/checkerframework/checker/test/junit/NullnessJSpecifySamplesTest.class'
}
task delombok {
description 'Delomboks the source code tree in tests/calledmethods-lombok'
def srcDelomboked = 'tests/calledmethods-delomboked'
def srcJava = 'tests/calledmethods-lombok'
inputs.files file(srcJava)
outputs.dir file(srcDelomboked)
// Because there are Checker Framework annotations in the test source.
dependsOn project(':checker-qual').tasks.jar
doLast {
def collection = files(configurations.testCompileClasspath)
ant.taskdef(name: 'delombok', classname: 'lombok.delombok.ant.Tasks$Delombok',
classpath: collection.asPath)
if (isJava17) {
// TODO: Delombok crashes with Java 17 on uses of Singular, see
// https://github.com/projectlombok/lombok/issues/2940
ant.delombok(to: srcDelomboked, classpath: collection.asPath) {
ant.fileset(dir: srcJava) {
include(name: '**/*.java')
exclude(name: '**/LombokSingularExample.java')
}
}
} else {
ant.delombok(from: srcJava, to: srcDelomboked, classpath: collection.asPath)
}
}
}
tasks.test.dependsOn("delombok")
///
/// Whole-program inference tests
///
test {
useJUnit {
// These are run in task ainferTest.
excludeCategories 'org.checkerframework.checker.test.junit.ainferrunners.AinferTestCheckerJaifsTest'
excludeCategories 'org.checkerframework.checker.test.junit.ainferrunners.AinferTestCheckerStubsTest'
excludeCategories 'org.checkerframework.checker.test.junit.ainferrunners.AinferTestCheckerAjavaTest'
excludeCategories 'org.checkerframework.checker.test.junit.ainferrunners.AinferNullnessJaifsTest'
excludeCategories 'org.checkerframework.checker.test.junit.ainferrunners.AinferIndexAjavaTest'
}
}
task ainferTestCheckerGenerateStubs(type: Test) {
description 'Internal task. Users should run ainferTestCheckerStubTest instead. This type-checks the ainfer-testchecker files with -Ainfer=stubs to generate stub files.'
dependsOn(compileTestJava)
doFirst {
delete("tests/ainfer-testchecker/annotated")
delete("${buildDir}/ainfer-testchecker/")
}
outputs.upToDateWhen { false }
include '**/AinferTestCheckerStubsTest.class'
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and the expected diagnostics not found.
exceptionFormat "full"
events "passed", "skipped", "failed"
}
doLast {
copyNonannotatedToAnnotatedDirectory("ainfer-testchecker")
// The stub file format doesn't support annotations on anonymous inner classes, so
// this test also expects errors on these tests that expect annotations to be inferred
// inside anonymous classes.
delete('tests/ainfer-testchecker/annotated/UsesAnonymous.java')
delete('tests/ainfer-testchecker/annotated/AnonymousClassWithField.java')
// This test causes an error when its corresponding stub file is read, because the test
// contains an annotation definition. The stub file parser does not support reading
// files that define annotations; this test can be reinstated if the stub parser
// is extended to support annotation definitions.
delete("tests/ainfer-testchecker/annotated/all-systems/Issue4083.java")
copy {
from file('tests/ainfer-testchecker/non-annotated/UsesAnonymous.java')
into file('tests/ainfer-testchecker/annotated')
}
}
}
task ainferTestCheckerValidateStubs(type: Test) {
description 'Internal task. Users should run ainferTestCheckerStubTest instead. This type-checks the ainfer-testchecker tests using the stub files generated by ainferTestCheckerGenerateStubs.'
dependsOn(ainferTestCheckerGenerateStubs)
outputs.upToDateWhen { false }
include '**/AinferTestCheckerStubsValidationTest.class'
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and the expected diagnostics not found.
exceptionFormat "full"
events "passed", "skipped", "failed"
}
}
task ainferTestCheckerGenerateAjava(type: Test) {
description 'Internal task. Users should run ainferTestCheckerAjavaTest instead. This type-checks the ainfer-testchecker files with -Ainfer=ajava to generate ajava files.'
dependsOn(compileTestJava)
doFirst {
delete("tests/ainfer-testchecker/annotated")
delete("${buildDir}/ainfer-testchecker/")
}
outputs.upToDateWhen { false }
include '**/AinferTestCheckerAjavaTest.class'
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and the expected diagnostics not found.
exceptionFormat "full"
events "passed", "skipped", "failed"
}
doLast {
copyNonannotatedToAnnotatedDirectory("ainfer-testchecker")
// A crash occurs because of a bug in Java Parser when trying to read the .ajava
// file produced for these tests. Reinstate them when https://github.com/javaparser/javaparser/pull/3527
// has been merged and released, and we've updated to a JavaParser version with that fix.
delete("tests/ainfer-testchecker/annotated/all-systems/java8/memberref/Issue946.java")
delete("tests/ainfer-testchecker/annotated/all-systems/java8/memberref/Receivers.java")
// This test must be deleted, because otherwise an error about a missing type in an
// ajava file is issued. The test itself shouldn't be run as an all-systems test while testing
// WPI; see the copy in the non-annotated WPI tests for an explanation.
delete("tests/ainfer-testchecker/annotated/all-systems/java8/memberref/Purity.java")
// These tests cause an error like the following when their corresponding ajava files are read:
// :0: warning: Annotations-org.checkerframework.common.value.ValueChecker.ajava:(line 3,col 1): Skipping annotation type: Anno
delete("tests/ainfer-testchecker/annotated/all-systems/Annotations.java")
delete("tests/ainfer-testchecker/annotated/all-systems/Issue4083.java")
// These tests cause unsuppressable errors from the Annotation File Parser, so they are also
// skipped. The errors are of the form:
// :0: warning: ConditionalExpressions-org.checkerframework.common.value.ValueChecker.ajava:(line 53,col 10): Annotations on intersection types are not yet supported
// These tests can all be reinstated when the Annotation File Parser is enhanced to support
// intersection types.
delete("tests/ainfer-testchecker/annotated/all-systems/ConditionalExpressions.java")
delete("tests/ainfer-testchecker/annotated/all-systems/GenericCrazyBounds.java")
delete("tests/ainfer-testchecker/annotated/all-systems/InferAndIntersection.java")
delete("tests/ainfer-testchecker/annotated/all-systems/IntersectionTypes.java")
delete("tests/ainfer-testchecker/annotated/all-systems/Issue1102.java")
delete("tests/ainfer-testchecker/annotated/all-systems/Issue1690.java")
delete("tests/ainfer-testchecker/annotated/all-systems/Issue2195.java")
delete("tests/ainfer-testchecker/annotated/all-systems/Issue2198.java")
delete("tests/ainfer-testchecker/annotated/all-systems/Issue2739.java")
delete("tests/ainfer-testchecker/annotated/all-systems/Issue3120.java")
delete("tests/ainfer-testchecker/annotated/all-systems/Issue3302.java")
delete("tests/ainfer-testchecker/annotated/all-systems/Issue577.java")
delete("tests/ainfer-testchecker/annotated/all-systems/Issue717.java")
delete("tests/ainfer-testchecker/annotated/all-systems/MultipleUnions.java")
// TODO: why does this specific ajava file need to be deleted, even though its corresponding source
// file has already been removed? This problem does not occur for any of the others.
delete("tests/ainfer-testchecker/inference-output/MultipleUnions-org.checkerframework.common.value.ValueChecker.ajava")
delete("tests/ainfer-testchecker/annotated/all-systems/TypeVarPrimitives.java")
delete("tests/ainfer-testchecker/annotated/all-systems/Unions.java")
delete("tests/ainfer-testchecker/annotated/all-systems/WildcardBounds.java")
// There is some kind of bad interaction between the purity checker's inference mode
// and method references to constructors: every one of them in this test causes a
// purity.methodref warning during validation. This problem only occurs for ajava-based
// inference because the relevant purity annotations that seem to trigger it are on
// inner classes, which stubs cannot annotate.
// TODO: investigate the cause of this error in the Purity checker, fix it, and then reinstate this test.
delete("tests/ainfer-testchecker/annotated/all-systems/java8/memberref/MemberReferences.java")
}
}
task ainferTestCheckerValidateAjava(type: Test) {
description 'Internal task. Users should run ainferTestCheckerAjavaTest instead. This re-type-checks the ainfer-testchecker files using the ajava files generated by ainferTestCheckerGenerateAjava'
dependsOn(ainferTestCheckerGenerateAjava)
outputs.upToDateWhen { false }
include '**/AinferTestCheckerAjavaValidationTest.class'
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and the expected diagnostics not found.
exceptionFormat "full"
events "passed", "skipped", "failed"
}
}
// Copies directories as needed by WPI tests.
// Formal parameter testdir is, for example, "ainfer-testchecker".
// Does work in directory "tests/${testdir}/".
// 1. Copies whole-program inference test source code from the non-annotated/ to the annotated/ directory.
// 2. Copies WPI output, such as .jaif or .stub files, to the inferference-output/ directory.
void copyNonannotatedToAnnotatedDirectory(String testdir) {
// Copying all test files to another directory, removing all expected errors that should not
// occur after inserting inferred annotations from .jaif files.
copy {
from files("tests/${testdir}/non-annotated")
into file("tests/${testdir}/annotated")
filter { String line ->
line.contains('// :: error:')
// Don't remove unchecked cast warnings, because they're genuinely expected in some all-systems
// tests, such as GenericsCasts.java.
|| (line.contains('// :: warning:') && !line.contains("// :: warning: [unchecked]"))
? null : line
}
}
// The only file for which expected errors are maintained is ExpectedErrors.java, so we copy it over.
delete("tests/${testdir}/annotated/ExpectedErrors.java")
copy {
from file("tests/${testdir}/non-annotated/ExpectedErrors.java")
into file("tests/${testdir}/annotated")
}
delete("tests/${testdir}/inference-output")
file("build/whole-program-inference").renameTo(file("tests/${testdir}/inference-output"))
}
// This task is similar to the ainferTestCheckerJaifTest task below, but it doesn't
// run the insert-annotations-to-source tool. Instead, it tests the -Ainfer=stubs feature
// and the -AmergeStubsWithSource feature to do WPI using stub files.
task ainferTestCheckerStubTest(dependsOn: 'shadowJar', group: 'Verification') {
description 'Run tests for whole-program inference using stub files'
dependsOn(ainferTestCheckerValidateStubs)
outputs.upToDateWhen { false }
}
// Like ainferTestCheckerStubTest, but with ajava files instead
task ainferTestCheckerAjavaTest(dependsOn: 'shadowJar', group: 'Verification') {
description 'Run tests for whole-program inference using ajava files'
dependsOn(ainferTestCheckerValidateAjava)
outputs.upToDateWhen { false }
}
task ainferTestCheckerGenerateJaifs(type: Test) {
description 'Internal task. Users should run ainferTestCheckerJaifTest instead. This type-checks the ainfer-testchecker files with -Ainfer=jaifs to generate .jaif files'
dependsOn(compileTestJava)
dependsOn(':checker-qual:jar') // For the Value Checker annotations.
doFirst {
delete("tests/ainfer-testchecker/annotated")
}
outputs.upToDateWhen { false }
include '**/AinferTestCheckerJaifsTest.class'
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and expected diagnostics not found.
exceptionFormat "full"
events "passed", "skipped", "failed"
}
doLast {
copyNonannotatedToAnnotatedDirectory("ainfer-testchecker")
// JAIF-based WPI fails these tests, which were added for stub-based WPI.
// See issue here: https://github.com/typetools/checker-framework/issues/3009
delete('tests/ainfer-testchecker/annotated/ConflictingAnnotationsTest.java')
delete('tests/ainfer-testchecker/annotated/MultiDimensionalArrays.java')
// JAIF-based WPI also fails this test. It used to pass, but the test was changed
// in a way that exposed a bug in the Annotation File Utilities: the AFU
// places annotations incorrectly on qualified types. In this test, a failure occurs because
// the AFU prints "@Annotation Outer.Inner this", rather than "Outer.@Annotation Inner this"
// (see an explanation of the syntax here:
// https://checkerframework.org/manual/#common-problems-non-typechecking).
// TODO: fix this bug in the AFU, then reinstate this test.
delete('tests/ainfer-testchecker/annotated/OverriddenMethodsTest.java')
// Inserting annotations from .jaif files in-place.
String jaifsDir = "tests/ainfer-testchecker/inference-output";
List<File> jaifs = fileTree(jaifsDir).matching {
include '*.jaif'
}.asList()
if (jaifs.isEmpty()) {
throw new GradleException("no .jaif files found in ${jaifsDir}")
}
String javasDir = "tests/ainfer-testchecker/annotated/";
List<File> javas = fileTree(javasDir).matching {
include '*.java'
}.asList()
if (javas.isEmpty()) {
throw new GradleException("no .java files found in ${javasDir}")
}
exec {
executable "${afu}/scripts/insert-annotations-to-source"
// Script argument -cp must precede Java program argument -i.
// checker-qual is needed for Constant Value Checker annotations.
// Note that "/" works on Windows as well as on Linux.
args = ['-cp', "${sourceSets.test.output.asPath}:${project(':checker-qual').tasks.jar.archivePath}:" + file("tests/build/testclasses")]
args += ['-i']
for (File jaif : jaifs) {
args += [jaif.toString()]
}
for (File javaFile : javas) {
args += [javaFile.toString()]
}
}
}
}
task ainferTestCheckerValidateJaifs(type: Test) {
description 'Internal task. Users should run ainferTestCheckerJaifTest instead. This type-checks the ainfer-testchecker files using the .jaif files generated by ainferTestCheckerGenerateJaifs'
dependsOn(ainferTestCheckerGenerateJaifs)
outputs.upToDateWhen { false }
include '**/AinferTestCheckerJaifsValidationTest.class'
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and expected diagnostics not found.
exceptionFormat "full"
events "passed", "skipped", "failed"
}
}
task ainferTestCheckerJaifTest(dependsOn: 'shadowJar', group: 'Verification') {
description 'Run tests for whole-program inference using .jaif files'
dependsOn(ainferTestCheckerValidateJaifs)
outputs.upToDateWhen { false }
}
task ainferIndexGenerateAjava(type: Test) {
description 'Internal task. Users should run ainferIndexAjavaTest instead. This type-checks the ainfer-index files with -Ainfer=ajava to generate ajava files.'
dependsOn(compileTestJava)
doFirst {
delete("tests/ainfer-index/annotated")
delete("${buildDir}/ainfer-index/")
}
outputs.upToDateWhen { false }
include '**/AinferIndexAjavaTest.class'
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and the expected diagnostics not found.
exceptionFormat "full"
events "passed", "skipped", "failed"
}
doLast {
copyNonannotatedToAnnotatedDirectory("ainfer-index")
}
}
task ainferIndexValidateAjava(type: Test) {
description 'Internal task. Users should run ainferIndexAjavaTest instead. This re-type-checks the ainfer-index files using the ajava files generated by ainferIndexGenerateAjava'
dependsOn(ainferIndexGenerateAjava)
outputs.upToDateWhen { false }
include '**/AinferIndexAjavaValidationTest.class'
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and the expected diagnostics not found.
exceptionFormat "full"
events "passed", "skipped", "failed"
}
}
task ainferIndexAjavaTest(dependsOn: 'shadowJar', group: 'Verification') {
description 'Run tests for whole-program inference using ajava files and the Index Checker'
dependsOn(ainferIndexValidateAjava)
outputs.upToDateWhen { false }
}
task ainferNullnessGenerateAjava(type: Test) {
description 'Internal task. Users should run ainferNullnessAjavaTest instead. This type-checks the ainfer-nullness files with -Ainfer=ajava to generate ajava files.'
dependsOn(compileTestJava)
doFirst {
delete("tests/ainfer-nullness/annotated")
delete("${buildDir}/ainfer-nullness/")
}
outputs.upToDateWhen { false }
include '**/AinferNullnessAjavaTest.class'
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and the expected diagnostics not found.
exceptionFormat "full"
events "passed", "skipped", "failed"
}
doLast {
copyNonannotatedToAnnotatedDirectory("ainfer-nullness")
}
}
task ainferNullnessValidateAjava(type: Test) {
description 'Internal task. Users should run ainferNullnessAjavaTest instead. This re-type-checks the ainfer-nullness files using the ajava files generated by ainferNullnessGenerateAjava'
dependsOn(ainferNullnessGenerateAjava)
outputs.upToDateWhen { false }
include '**/AinferNullnessAjavaValidationTest.class'
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and the expected diagnostics not found.
exceptionFormat "full"
events "passed", "skipped", "failed"
}
}
task ainferNullnessAjavaTest(dependsOn: 'shadowJar', group: 'Verification') {
description 'Run tests for whole-program inference using ajava files and the Nullness Checker'
dependsOn(ainferNullnessValidateAjava)
outputs.upToDateWhen { false }
}
task ainferNullnessGenerateJaifs(type: Test) {
description 'Internal task. Users should run ainferNullnessJaifTest instead. This type-checks the ainfer-nullness files with -Ainfer=jaifs to generate .jaif files'
dependsOn(compileTestJava)
doFirst {
delete("tests/ainfer-nullness/annotated")
}
outputs.upToDateWhen { false }
include '**/AinferNullnessJaifsTest.class'
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and expected diagnostics not found.
exceptionFormat "full"
events "passed", "skipped", "failed"
}
doLast {
copyNonannotatedToAnnotatedDirectory("ainfer-nullness")
// JAIF-based WPI fails these tests, which was added for stub-based WPI.
// See issue here: https://github.com/typetools/checker-framework/issues/3009
delete('tests/ainfer-nullness/annotated/ConflictingAnnotationsTest.java')
delete('tests/ainfer-nullness/annotated/MultiDimensionalArrays.java')
// Inserting annotations from .jaif files in-place.
String jaifsDir = "tests/ainfer-nullness/inference-output";
List<File> jaifs = fileTree(jaifsDir).matching {
include '*.jaif'
}.asList()
if (jaifs.isEmpty()) {
throw new GradleException("no .jaif files found in ${jaifsDir}")
}
String javasDir = "tests/ainfer-nullness/annotated/";
List<File> javas = fileTree(javasDir).matching {
include '*.java'
}.asList()
if (javas.isEmpty()) {
throw new GradleException("no .java files found in ${javasDir}")
}
exec {
executable "${afu}/scripts/insert-annotations-to-source"
// Script argument -cp must precede Java program argument -i.
// Note that "/" works on Windows as well as on Linux.
args = ['-cp', "${sourceSets.test.output.asPath}:${project(':checker-qual').tasks.jar.archivePath}:" + file("tests/build/testclasses")]
args += ['-i']
for (File jaif : jaifs) {
args += [jaif.toString()]
}
for (File javaFile : javas) {
args += [javaFile.toString()]
}
}
}
}
task ainferNullnessValidateJaifs(type: Test) {
description 'Internal task. Users should run ainferNullnessJaifTest instead. This re-type-checks the ainfer-nullness files using the .jaif files generated by ainferNullnessGenerateJaifs'
dependsOn(ainferNullnessGenerateJaifs)
outputs.upToDateWhen { false }
include '**/AinferNullnessJaifsValidationTest.class'
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and expected diagnostics not found.
exceptionFormat "full"
events "passed", "skipped", "failed"
}
}
task ainferNullnessJaifTest(dependsOn: 'shadowJar', group: 'Verification') {
description 'Run tests for whole-program inference using .jaif files'
dependsOn(ainferNullnessValidateJaifs)
outputs.upToDateWhen { false }
}
// Empty task that just runs both the jaif and stub WPI tests.
// It is run as part of the inferenceTests task.
task ainferTest(group: 'Verification') {
description "Run tests for all whole program inference modes."
dependsOn('ainferTestCheckerJaifTest')
dependsOn('ainferTestCheckerStubTest')
dependsOn('ainferTestCheckerAjavaTest')
dependsOn('ainferNullnessJaifTest')
dependsOn('ainferIndexAjavaTest')
}
// This is run as part of the inferenceTests task.
task wpiManyTest(group: "Verification") {
description 'Tests the wpi-many.sh script (and indirectly the wpi.sh script). Requires an Internet connection.'
dependsOn(copyJarsToDist)
// This test must always be re-run when requested.
outputs.upToDateWhen { false }
doFirst {
delete("${project.projectDir}/build/wpi-many-tests-results/")
// wpi-many.sh is run in skip mode so that logs are preserved, but
// we don't actually want to skip previously-failing tests when we
// re-run the tests locally.
delete fileTree("${project.projectDir}/build/wpi-many-tests") {
include '**/.cannot-run-wpi'
}
}
doLast {
// Run wpi-many.sh
def typecheckFilesDir = "${project.projectDir}/build/wpi-many-tests-results/"
try {
exec {
environment CHECKERFRAMEWORK: "${projectDir}/.."
commandLine 'bin/wpi-many.sh',
'-i', "${project.projectDir}/tests/wpi-many/testin.txt",
'-o', "${project.projectDir}/build/wpi-many-tests",
'-s',
'--', '--checker', 'nullness,interning,lock,regex,signature,calledmethods,resourceleak'
}
} catch (Exception e) {
println("Failure: Running wpi-many.sh failed with a non-zero exit code.")
File wpiOut = new File("${typecheckFilesDir}/wpi-out")
if (wpiOut.exists()) {
println("========= Output from last run of wpi.sh (${typecheckFilesDir}/wpi-out): ========")
exec {
commandLine 'cat', "${typecheckFilesDir}/wpi-out"
}
println("========= End of output from last run of wpi.sh (${typecheckFilesDir}/wpi-out): ========")
throw e
}
}
// collect the logs from running WPI
def typecheckFiles = fileTree(typecheckFilesDir).matching {
include "**/*-typecheck.out"
}
def testinLines = file("${project.projectDir}/tests/wpi-many/testin.txt").text.readLines()
testinLines.removeIf { it.startsWith("#") }
def expectedTypecheckFileCount = testinLines.size()
def actualTypecheckFileCount = typecheckFiles.size()
if (actualTypecheckFileCount != expectedTypecheckFileCount) {
println("Failure: Too few *-typecheck.out files in ${typecheckFilesDir}: " +
"found ${actualTypecheckFileCount} but expected ${expectedTypecheckFileCount}.")
println("========= Found in ${typecheckFilesDir} ========")
exec {
commandLine 'ls', '-al', "${typecheckFilesDir}"
}
println("========= Expected in ${typecheckFilesDir} ========")
exec {
commandLine 'cat', "${project.projectDir}/tests/wpi-many/testin.txt"
}
println("========= Output from last run of wpi.sh (${typecheckFilesDir}/wpi-out): ========")
exec {
commandLine 'cat', "${typecheckFilesDir}/wpi-out"
}
println("========= End of output from last run of wpi.sh (${typecheckFilesDir}/wpi-out): ========")
def logFiles = fileTree(typecheckFilesDir).matching {
include "**/*.log"
}
logFiles.visit { FileVisitDetails details ->
def filename = "${typecheckFilesDir}" + details.getName()
println("======== printing contents of ${filename} ========")
details.getFile().eachLine { line -> println(line) }
println("======== end of contents of ${filename} ========")
}
// If any of these files are present, their contents should be an error
// message that might indicate what went wrong. Even their presenence,
// however, is intereseting (even if they are empty).
def cannotRunWpiFiles = fileTree(typecheckFilesDir).matching {
include "**/.cannot-run-wpi"
}
cannotRunWpiFiles.visit { FileVisitDetails details ->
def filename = "${typecheckFilesDir}" + details.getName()
println("======== printing contents of ${filename} ========")
details.getFile().eachLine { line -> println(line) }
println("======== end of contents of ${filename} ========")
}
throw new GradleException("Failure: Too few *-typecheck.out files in ${typecheckFilesDir}: " +
"found ${actualTypecheckFileCount} but expected ${expectedTypecheckFileCount}.")
}
// check that WPI causes the expected builds to succeed
typecheckFiles.visit { FileVisitDetails details ->
def filename = "${project.projectDir}/build/wpi-many-tests-results/" + details.getName()
def file = details.getFile()
if (file.length() == 0) {
throw new GradleException("Failure: WPI produced empty typecheck file " + filename)
}
file.eachLine { line ->
if (
// Ignore the line that WPI echoes with the javac command being run.
line.startsWith("Running ")
// Warnings about bad path elements aren't related to WPI and are ignored.
|| line.startsWith("warning: [path]")
// Ignore bootstrap classpath warning:
|| line.startsWith("warning: [options] bootstrap")
// Ignore the warnings about --add-opens arguments to the JVM
|| line.contains("warning: [options] --add-opens has no effect at compile time")
// Ignore the summary line that reports the total number of warnings (which can be single or plural).
|| line.endsWith("warning")
|| line.endsWith("warnings")) {
return;
}
if (!line.trim().equals("")) {
println("======== printing contents of ${filename} ========")
details.getFile().eachLine { l -> println(l) }
println("======== end of contents of ${filename} ========")
throw new GradleException("Failure: WPI scripts produced an unexpected output in " + filename + ". " +
"Failing line is the following: " + line)
}
}
}
}
}
// This is run as part of the inferenceTests task.
task wpiPlumeLibTest(group: "Verification") {
description 'Tests whole-program inference on the plume-lib projects. Requires an Internet connection.'
dependsOn(copyJarsToDist)
// This test must always be re-run when requested.
outputs.upToDateWhen { false }
doLast {
exec {
commandLine 'bin-devel/wpi-plumelib/test-wpi-plumelib.sh'