forked from typetools/checker-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
715 lines (641 loc) · 27.9 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
import de.undercouch.gradle.tasks.download.Download
import org.gradle.internal.jvm.Jvm
plugins {
// https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow (v5 requires Gradle 5)
id 'com.github.johnrengelman.shadow' version '4.0.4'
// https://plugins.gradle.org/plugin/de.undercouch.download
id "de.undercouch.download" version "3.4.3"
id 'java'
// TODO: Migrate to newer version: https://github.com/tbroyer/gradle-errorprone-plugin#migration-from-versions-00x
id "net.ltgt.errorprone-base" version "0.0.13"
// https://plugins.gradle.org/plugin/org.ajoberstar.grgit
id 'org.ajoberstar.grgit' version '3.0.0' apply false
}
apply plugin: "de.undercouch.download"
import org.ajoberstar.grgit.Grgit
repositories {
jcenter()
mavenCentral()
}
ext {
release = false
assert JavaVersion.current() == JavaVersion.VERSION_1_8: "Set JAVA_HOME to JDK 8. Current version is ${JavaVersion.current()}"
parentDir = file("${rootDir}/../").absolutePath
annotationTools = "${parentDir}/annotation-tools"
afu = "${annotationTools}/annotation-file-utilities"
afuJar = "${afu}/annotation-file-utilities-all.jar"
stubparser = "${parentDir}/stubparser"
stubparserJar = "${stubparser}/javaparser-core/target/stubparser.jar"
jtregHome = "${parentDir}/jtreg"
formatScriptsHome = "${project(':checker').projectDir}/bin-devel/.run-google-java-format"
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"
}
task setLocalRepo(type:Exec) {
commandLine 'git', 'worktree', 'list'
standardOutput = new ByteArrayOutputStream()
doLast {
String worktreeList = standardOutput.toString()
localRepo = worktreeList.substring(0, worktreeList.indexOf(" ")) + "/.git"
}
}
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"
}
allprojects {
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: "de.undercouch.download"
apply plugin: 'net.ltgt.errorprone-base'
group 'org.checkerframework'
// Increment the minor version rather than just the patch level if:
// * any new checkers have been added,
// * the patch level is 9 (keep the patch level as a single digit), or
// * backward-incompatible changes have been made to APIs or elsewhere.
version '2.7.0'
repositories {
mavenCentral()
}
configurations {
javacJar
toolsJar
}
dependencies {
javacJar 'org.checkerframework:compiler:2.4.0'
// Change the JDK via -Dorg.gradle.java.home=JDK_PATH
toolsJar files(Jvm.current().toolsJar)
}
// After all the tasks have been created, modify some of them.
afterEvaluate {
// 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) {
dependsOn(':checker:shadowJar')
dependsOn(':framework-test:tagletClasses')
doFirst {
options.encoding = 'UTF-8'
options.memberLevel = javadocMemberLevel
classpath += files(project(':checker').tasks.getByName('shadowJar').archivePath)
options.taglets 'org.checkerframework.taglet.ManualTaglet'
options.tagletPath(project(':framework-test').sourceSets.taglet.output as File[])
options.links = ['https://docs.oracle.com/javase/8/docs/api/', 'https://docs.oracle.com/javase/8/docs/jdk/api/javac/tree/']
// This file is looked for by Javadoc.
file("${destinationDir}/resources/fonts/").mkdirs()
ant.touch(file: "${destinationDir}/resources/fonts/dejavu.css")
}
}
// Add standard javac options
tasks.withType(JavaCompile) {
dependsOn(':installGitHooks')
sourceCompatibility = 1.8
targetCompatibility = 1.8
options.failOnError = true
options.deprecation = true
options.compilerArgs += [
'-g',
// To not get a warning about missing bootstrap classpath for Java 8 (once we use Java 9).
"-Xlint:-options",
"-Xlint",
]
options.encoding = 'UTF-8'
}
}
}
task cloneAndBuildDependencies(type: Exec) {
description 'Clones (or updates) and builds all dependencies'
executable './.travis-build-without-test.sh'
args = ['downloadjdk']
}
task version() {
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${shortName}", for example "checkPurity" or "checkNullness".
* @param projectName name of the project
* @param checker full qualified name of the checker to run
* @param shortName shorter version of the checker to use to name the task.
*/
def createCheckTypeTask(projectName, checker, shortName) {
project("${projectName}").tasks.create(name: "check${shortName}", type: JavaCompile, dependsOn: ':checker:shadowJar') {
description "Run the ${shortName} Checker on the main sources."
group 'Verification'
dependsOn ':checker:updateJdk'
// 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)
destinationDir = file("${buildDir}")
options.annotationProcessorPath = files(project(':checker').tasks.shadowJar.archivePath)
options.compilerArgs += [
'-processor', "${checker}",
'-proc:only',
'-Xlint:-processing',
"-Xbootclasspath/p:${rootDir}/checker/dist/jdk8.jar"
]
}
}
/**
* Returns a list of all the Java files that should be formatted for the given project. These are:
*
* All java files in the main sourceSet.
* All java files in the tests directory that compile.
*
* @param projectName name of the project to format
* @return a list of all Java files that should be formatted for projectName
*/
List<String> getJavaFilesToFormat(projectName) {
List<File> javaFiles = new ArrayList<>();
project(':' + projectName).sourceSets.forEach { set ->
javaFiles.addAll(set.java.files)
}
// Collect all java files in tests directory
fileTree("${project(projectName).projectDir}/tests").visit { details ->
if (!details.path.contains("nullness-javac-errors") && details.name.endsWith('java')) {
javaFiles.add(details.file)
}
}
// Collect all java files in jtreg directory
fileTree("${project(projectName).projectDir}/jtreg").visit { details ->
if (!details.path.contains("nullness-javac-errors") && details.name.endsWith('java')) {
javaFiles.add(details.file)
}
}
List<String> args = new ArrayList<>();
for (File f : javaFiles) {
args += f.absolutePath
}
return args
}
task htmlValidate(type: Exec, group: 'Format') {
description 'Validate that HTML files are well-formed'
executable 'html5validator'
args = [
"--ignore",
"/api/",
"/build/",
"/docs/manual/manual.html",
"/checker/jdk/nullness/src/java/lang/ref/package.html"
]
}
// `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 a global API documentation for all the modules'
dependsOn(':checker:shadowJar')
dependsOn(':framework-test:tagletClasses')
destinationDir = file("${rootDir}/docs/api")
source(project(':checker').sourceSets.main.allJava, project(':framework').sourceSets.main.allJava,
project(':dataflow').sourceSets.main.allJava, project(':javacutil').sourceSets.main.allJava)
classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
doLast {
copy {
from 'docs/logo/Checkmark/CFCheckmark_favicon.png'
rename('CFCheckmark_favicon.png', 'favicon-checkerframework.png')
into "${rootDir}/docs/api"
}
}
}
// See documentation for allJavadoc task.
javadoc.dependsOn(allJavadoc)
configurations {
requireJavadoc
}
dependencies {
// https://mvnrepository.com/artifact/org.plumelib/require-javadoc
compile group: 'org.plumelib', name: 'require-javadoc', version: '0.1.0'
}
task requireJavadoc(type: Javadoc, group: "Documentation") {
description = 'Ensures that Java elements have Javadoc documentation.'
destinationDir = file("${rootDir}/docs/api")
source(project(':checker').sourceSets.main.allJava, project(':framework').sourceSets.main.allJava,
project(':dataflow').sourceSets.main.allJava, project(':javacutil').sourceSets.main.allJava)
classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
destinationDir.deleteDir()
// options.memberLevel = JavadocMemberLevel.PRIVATE
options.docletpath = project.sourceSets.main.compileClasspath as List
options.doclet = "org.plumelib.javadoc.RequireJavadoc"
// options.addStringOption('skip', 'ClassNotToCheck|OtherClass')
}
task requireJavadocPrivate(type: Javadoc, group: "Documentation") {
description = 'Ensures that all (even private) Java elements have Javadoc documentation.'
destinationDir = file("${rootDir}/docs/api")
source(project(':checker').sourceSets.main.allJava, project(':framework').sourceSets.main.allJava,
project(':dataflow').sourceSets.main.allJava, project(':javacutil').sourceSets.main.allJava)
classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
destinationDir.deleteDir()
options.memberLevel = JavadocMemberLevel.PRIVATE
options.docletpath = project.sourceSets.main.compileClasspath as List
options.doclet = "org.plumelib.javadoc.RequireJavadoc"
// options.addStringOption('skip', 'ClassNotToCheck|OtherClass')
}
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'
overwrite true
dest new File(buildDir, 'jtreg-4.2.0-tip.tar.gz')
doLast {
copy {
from tarTree(dest)
into "${jtregHome}/.."
}
exec {
commandLine('chmod', '+x', "${jtregHome}/bin/jtdiff", "${jtregHome}/bin/jtreg")
}
}
}
// See alternate implementation getCodeFormatScriptsInGradle below.
task getCodeFormatScripts() {
description 'Obtain or update the run-google-java-format scripts'
if (file(formatScriptsHome).exists()) {
exec {
workingDir formatScriptsHome
executable 'git'
args = ['pull', '-q']
ignoreExitValue = true
}
} else {
exec {
workingDir "${formatScriptsHome}/../"
executable 'git'
args = ['clone', '-q', 'https://github.com/plume-lib/run-google-java-format.git', '.run-google-java-format']
}
}
}
// This implementation is preferable to the above because it does work in Gradle rather than in bash.
// However, it fails in the presence of worktrees: https://github.com/ajoberstar/grgit/issues/97
task getCodeFormatScriptsInGradle {
description "Obtain the run-google-java-format scripts"
doLast {
if (! new File(formatScriptsHome).exists()) {
def rgjfGit = Grgit.clone(dir: formatScriptsHome, uri: 'https://github.com/plume-lib/run-google-java-format.git')
} else {
def rgjfGit = Grgit.open(dir: formatScriptsHome)
rgjfGit.pull()
}
}
}
task pythonIsInstalled(type: Exec) {
description "Check that the python executable is installed."
executable = "python"
args "--version"
}
task tags {
description 'Create Emacs TAGS table'
doLast {
exec {
commandLine "etags", "-i", "checker/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
}
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 runErrorProne` and fix all errors
// * Uncomment "-Werror"
errorprone group: 'com.google.errorprone', name: 'error_prone_core', version: '2.3.3'
}
task checkFormat(type: Exec, dependsOn: [getCodeFormatScripts, pythonIsInstalled], group: 'Format') {
description 'Check whether the source code is properly formatted'
// jdk8 and checker-qual have no source, so skip
onlyIf { !project.name.is('jdk8') && !project.name.startsWith('checker-qual') }
executable 'python'
doFirst {
args += "${formatScriptsHome}/check-google-java-format.py"
args += "--aosp" // 4 space indentation
args += getJavaFilesToFormat(project.name)
}
ignoreExitValue = true
doLast {
if (execResult.exitValue != 0) {
throw new RuntimeException('Found improper formatting, try running: ./gradlew reformat"')
}
}
}
task reformat(type: Exec, dependsOn: [getCodeFormatScripts, pythonIsInstalled], group: 'Format') {
description 'Format the Java source code'
// jdk8 and checker-qual have no source, so skip
onlyIf { !project.name.is('jdk8') && !project.name.startsWith('checker-qual') }
executable 'python'
doFirst {
args += "${formatScriptsHome}/run-google-java-format.py"
args += "--aosp" // 4 space indentation
args += getJavaFilesToFormat(project.name)
}
}
shadowJar {
// Relocate packages that might conflict with user's classpath.
doFirst {
if (release) {
// Only relocate JavaParser during a release:
relocate 'com.github.javaparser', 'org.checkerframework.com.github.javaparser'
}
}
// Don't relocate javac.jar:
// relocate 'com.sun', 'org.checkeframework.com.sun'
// relocate 'javax','org.checkerframework.javax'
// relocate 'jdk', 'org.checkerframework.jdk'
// These appear in annotation-file-utilities-all.jar:
relocate 'org.apache', 'org.checkerframework.org.apache'
relocate 'org.relaxng', 'org.checkerframework.org.relaxng'
relocate 'org.plumelib', 'org.checkerframework.org.plumelib'
// relocate 'sun', 'org.checkerframework.sun'
relocate 'org.objectweb.asm', 'org.checkerframework.org.objectweb.asm'
relocate 'com.google', 'org.checkerframework.com.google'
relocate 'plume', 'org.checkerframework.plume'
}
if (!project.name.startsWith('checker-qual') && !project.name.is('jdk8')) {
task tags(type: Exec) {
description 'Create Emacs TAGS table'
commandLine "bash", "-c", "find . \\( -name jdk \\) -prune -o -name '*.java' -print | sort-directory-order | xargs ctags -e -f TAGS"
}
}
// Things in this block reference definitions in the subproject that do not exist,
// until the project is evaluated.
afterEvaluate {
// Create a sourcesJar task for each subproject
tasks.create(name: 'sourcesJar', type: Jar) {
description 'Creates sources jar.'
classifier = 'source'
baseName = jar.baseName
from sourceSets.main.java
}
// Create a javadocJar task for each subproject
tasks.create(name: 'javadocJar', type: Jar, dependsOn: 'javadoc') {
description 'Creates javadoc jar.'
classifier = 'javadoc'
baseName = jar.baseName
from tasks.javadoc.destinationDir
}
// Adds manifest to all Jar files
tasks.withType(Jar) {
includeEmptyDirs = false
manifest {
attributes("Implementation-Version": "${version}")
attributes("Implementation-URL": "https://checkerframework.org")
attributes('Automatic-Module-Name': "org.checkerframework." + project.name.replaceAll('-', '.'))
}
}
// Add tasks to run various checkers on all the main source sets.
createCheckTypeTask(project.name, 'org.checkerframework.checker.nullness.NullnessChecker', 'Nullness')
createCheckTypeTask(project.name, 'org.checkerframework.framework.util.PurityChecker', 'Purity')
// Add jtregTests to framework and checker modules
if (project.name.is('framework') || project.name.is('checker')) {
tasks.create(name: 'jtregTests', dependsOn: ':downloadJtreg', group: 'Verification') {
description 'Run the jtreg tests.'
dependsOn('compileJava')
dependsOn('compileTestJava')
dependsOn(':checker:updateJdk')
dependsOn('shadowJar')
String jtregOutput = "${buildDir}/jtreg"
String name = 'all'
String tests = '.'
doLast {
exec {
executable "${jtregHome}/bin/jtreg"
args = [
"-dir:${projectDir}/jtreg",
"-workDir:${jtregOutput}/${name}/work",
"-reportDir:${jtregOutput}/${name}/report",
"-verbose:summary",
"-javacoptions:-g",
"-keywords:!ignore",
'-samevm',
// Required for checker/jtreg/nullness/PersistUtil.java and other tests
// Must use langtools javap.jar rather than tools.jar because the
// tools.jar in the docker vm doesn't have the required classes.
"-vmoptions:-Xbootclasspath/p:${configurations.javacJar.asPath}:" +
"${parentDir}/jsr308-langtools/dist/lib/javap.jar:" +
"${tasks.shadowJar.archivePath}:${sourceSets.test.output.asPath}",
"-javacoptions:-Xbootclasspath/p:${configurations.javacJar.asPath}",
]
if (project.name.is('checker')) {
args += [
"-javacoptions:-Xbootclasspath/p:${projectDir}/dist/jdk8.jar",
]
}
// Location of jtreg tests
args += "${tests}"
}
}
}
}
// Create a task for each JUnit test class whose name is the same as the JUnit class name.
sourceSets.test.allJava.filter { it.path.contains('src/test/java/tests') }.forEach { file ->
String junitClassName = file.name.replaceAll(".java", "")
tasks.create(name: "${junitClassName}", type: Test) {
description "Run ${junitClassName} tests."
include "**/${name}.class"
}
}
// Configure JUnit tests
tasks.withType(Test) {
if (project.name.is('checker')) {
dependsOn('copyJarsToDist')
systemProperties += [JDK_JAR: "${projectDir}/dist/jdk8.jar"]
}
if (project.hasProperty('emit.test.debug')) {
systemProperties += ["emit.test.debug": 'true']
}
testLogging {
showStandardStreams = true
// Always run the tests
outputs.upToDateWhen { false }
// Show the found unexpected diagnostics and expected diagnostics not found.
exceptionFormat "full"
events "failed"
}
// After each test, print a summary.
afterSuite { desc, result ->
if (desc.getClassName() != null) {
long mils = result.getEndTime() - result.getStartTime()
double seconds = mils / 1000.0
println "Testsuite: ${desc.getClassName()}\n" +
"Tests run: ${result.testCount}, " +
"Failures: ${result.failedTestCount}, " +
"Skipped: ${result.skippedTestCount}, " +
"Time elapsed: ${seconds} sec\n"
}
}
}
// Create a runErrorProne task.
tasks.create(name: 'runErrorProne', type: JavaCompile, group: 'Verification') {
description 'Run the error-prone compiler on the main sources'
toolChain net.ltgt.gradle.errorprone.ErrorProneToolChain.create(project)
source = sourceSets.main.java.asFileTree
classpath = sourceSets.main.compileClasspath.asFileTree
destinationDir = new File("${buildDir}", 'errorprone')
options.compilerArgs = [
// 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',
// -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 one warning, rather than outputting them all.
// https://github.com/google/error-prone/issues/436
'-Werror',
]
}
// Create an allTests task
tasks.create(name: 'allTests', type: GradleBuild, group: 'Verification') {
description 'Run all Checker Framework tests'
tasks = ['test', 'checkPurity']
if (project.name.is('framework') || project.name.is('checker')) {
tasks += ['checkCompilerMessages', 'jtregTests']
}
if (projects.name.is('framework')) {
tasks += ['wholeProgramInferenceTests', 'loaderTests']
}
if (project.name.is('checker')) {
tasks += ['nullnessExtraTests', 'commandLineTests', 'tutorialTests']
}
}
task javadocPrivate(dependsOn: javadoc) {
doFirst {
javadocMemberLevel = JavadocMemberLevel.PRIVATE
}
doLast {
javadocMemberLevel = JavadocMemberLevel.PROTECTED
}
}
}
}
assemble.dependsOn(':checker:copyJarsToDist')
task checkBasicStyle(group: 'Format') {
description 'Check basic style guidelines. Not related to Checkstyle tool.'
String[] ignoreDirectories = ['.git',
'.gradle',
'.idea',
'annotated',
'api',
'bib',
'bootstrap',
'build',
'jdk',
'maven-artifacts']
String[] ignoreFilePatterns = [
'*.aux',
'*.bib',
'*.class',
'*.dvi',
'*.expected',
'*.gif',
'*.jar',
'*.jtr',
'*.log',
'*.out',
'*.patch',
'*.pdf',
'*.png',
'*.sty',
'*.xcf',
'*~',
'#*#',
'CFLogo.ai',
'logfile.log.rec.index',
'manual.html',
'manual.html-e',
'junit.*.properties']
doLast {
FileTree tree = fileTree(dir: projectDir)
for (String dir : ignoreDirectories) {
tree.exclude "**/${dir}/**"
}
for (String file : ignoreFilePatterns) {
tree.exclude "**/${file}"
}
boolean failed = false
tree.visit {
if (!it.file.isDirectory()) {
int isBlankLine
it.file.eachLine { line ->
if (line.endsWith(' ')) {
println("Trailing whitespace: ${it.file.absolutePath}")
failed = true
}
if (!line.startsWith('\\') &&
(line.matches('^.* (else|finally|try)\\{}.*$')
|| line.matches('^.*}(catch|else|finally) .*$')
|| line.matches('^.* (catch|for|if|while)\\('))) {
// This runs on non-java files, too.
println("Missing space: ${it.file.absolutePath}")
failed = true
}
if (line.isEmpty()) {
isBlankLine++;
} else {
isBlankLine = 0;
}
}
if (isBlankLine > 1) {
println("Blank line at end of file: ${it.file.absolutePath}")
failed = true
}
RandomAccessFile file
try {
file = new RandomAccessFile(it.file, 'r')
int end = file.length() - 1;
if (end > 0) {
file.seek(end)
byte last = file.readByte()
if (last != '\n') {
println("Missing newline at end of file: ${it.file.absolutePath}")
failed = true
}
}
} finally {
if (file != null) {
file.close()
}
}
}
}
if (failed) {
throw new GradleException("Files do not meet basic style guidelines.")
}
}
}
task releaseBuild(type: GradleBuild) {
description 'Build everything required for a release'
startParameter = new StartParameter()
startParameter.setProjectProperties(release: true)
// This downloads rather than builds the jdk8.jar because that's what is used in all the Travis tests.
tasks = ['clean', 'assemble', 'sourcesJar', 'javadocJar', 'allJavadoc']
}
task releaseAndTest(type: GradleBuild, dependsOn: 'releaseBuild') {
description 'Build everything required for a release and run allTests'
startParameter = new StartParameter()
startParameter.setProjectProperties(release: true)
tasks = ['allTests']
}
// Don't create an empty checker-framework-VERSION.jar
jar.onlyIf {false}