-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.gradle
228 lines (200 loc) · 7.81 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
buildscript {
repositories {
mavenCentral()
}
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 {
id 'java'
id 'net.ltgt.errorprone' version '3.1.0'
}
ext {
jsr308 = System.getenv('JSR308') ?: file(new File("..")).absolutePath
cfPath = "${jsr308}/checker-framework"
cfiPath = "${jsr308}/checker-framework-inference"
afu = "${jsr308}/annotation-tools/annotation-file-utilities"
universePath = "${jsr308}/universe"
formatScripts = "${universePath}/scripts/.run-google-java-format"
isJava8 = JavaVersion.current() == JavaVersion.VERSION_1_8
isJava11plus = JavaVersion.current() >= JavaVersion.VERSION_11
// Keep in sync with checker-framework/build.gradle.
// TODO: find a way to directly use that variable.
compilerArgsForRunningCF = [
"--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",
"--add-opens",
"jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
]
}
println '==================================='
println ' Universe Checker '
println '==================================='
println ''
println '-------------------------------'
println 'Important Environment Variables'
println '-------------------------------'
println 'JSR308: ' + jsr308
println 'CF: ' + cfPath
println 'CFI: ' + cfiPath
println 'UNIVERSE: ' + universePath
repositories {
mavenCentral()
}
def framework_test_files = fileTree(dir: "${cfPath}/framework-test/build/libs", include: "framework-test-*.jar")
List<File> list_of_files = new ArrayList<>(framework_test_files.getFiles())
Collections.sort(list_of_files)
// pick the last element in the sorted list corresponding to the most recent framework-test-*.*.*.jar
def framework_test_jar = files(list_of_files[list_of_files.size()-1])
dependencies {
implementation fileTree(dir: "${cfPath}/checker/dist", include: "checker.jar")
implementation fileTree(dir: "${cfiPath}/dist", include: "checker-framework-inference.jar")
implementation fileTree(dir: "${cfiPath}/dist", include: "inference-framework-test-lib.jar")
implementation group: 'log4j', name: 'log4j', version: '1.2.17'
implementation 'commons-logging:commons-logging:1.3.4'
testImplementation framework_test_jar
testImplementation 'junit:junit:4.13.2'
errorprone 'com.google.errorprone:error_prone_core:2.31.0'
errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'
}
sourceSets {
main {
java {
srcDir "src/main/java"
}
resources {
srcDir "src/main/java"
exclude "**/*.java"
}
}
test {
java {
srcDirs = ["src/test/java"]
}
}
}
// TODO: This doesn't work when nothing was built before
task cloneAndBuildDependencies(type: Exec) {
description 'Clones (or updates) and builds all dependencies'
executable './scripts/setup-deps.sh'
}
tasks.withType(JavaCompile) { compilationTask ->
options.compilerArgs = [
'-implicit:class',
'-Werror',
'-Xlint:deprecation',
'-Awarns',
'-Xmaxwarns',
'10000',
]
// Error Prone must be available in the annotation processor path
options.annotationProcessorPath = configurations.errorprone
// Enable Error Prone
options.errorprone.enabled = !isJava8
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.errorproneArgs = [
'-Xep:VoidUsed:OFF',
]
}
afterEvaluate {
// 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("${universePath}/src/test/java") }.forEach { file ->
String junitClassName = file.name.replaceAll(".java", "")
String testName = junitClassName.replaceAll("Test", "")
tasks.create(name: "${junitClassName}", type: Test) {
description "Run ${testName} tests."
include "**/${name}.class"
}
}
// Configure JUnit tests
tasks.withType(Test) {
group 'Verification'
systemProperties = [
'path.afu.scripts' : "${afu}/scripts",
'path.inference.script': "${cfiPath}/scripts/inference"
]
environment "external_checker_classpath", "${universePath}/build/classes/java/main:${universePath}/build/libs/universe.jar"
if (isJava8) {
jvmArgs "-Xbootclasspath/p:${cfiPath}/dist/javac.jar"
} else {
jvmArgs += compilerArgsForRunningCF
}
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// The following prints out each time a test is passed.
events "passed", "skipped", "failed", "standardOut", "standardError"
// Show the found unexpected diagnostics and expected diagnostics not found.
exceptionFormat "full"
showExceptions true
showCauses true
showStackTraces true
showStandardStreams true
}
// 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"
}
}
}
}
tasks.clean {
delete 'bin', 'dist', 'testTmp', 'testdata/tmp',
fileTree('.') { include '**/*.jaif', '**/*.txt' },
fileTree('tests') { include '**/*.class' }
}
if (isJava11plus) {
apply plugin: 'com.diffplug.spotless'
spotless {
// If you add any formatters to this block that require dependencies here, then you must also
// add them to spotlessPredeclare block.
format 'misc', {
// define the files to apply `misc` to
target '*.md', '.gitignore'
// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces(2)
endWithNewline()
}
java {
target '**/*.java'
googleJavaFormat().aosp()
importOrder('com', 'jdk', 'lib', 'lombok', 'org', 'java', 'javax')
formatAnnotations().addTypeAnnotation("Any").addTypeAnnotation("Bottom").addTypeAnnotation("Lost").addTypeAnnotation("Peer").addTypeAnnotation("Rep").addTypeAnnotation("Self")
}
groovyGradle {
target '**/*.gradle'
greclipse() // which formatter Spotless should use to format .gradle files.
indentWithSpaces(4)
trimTrailingWhitespace()
// endWithNewline() // Don't want to end empty files with a newline
}
}
}