-
Notifications
You must be signed in to change notification settings - Fork 348
/
build.gradle
218 lines (186 loc) · 7.39 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
plugins {
id 'java-library'
}
ext {
annotatedJdkHome = '../../jdk'
}
sourceSets {
main {
resources {
// Stub files, message.properties, etc.
srcDirs += ['src/main/java', "${buildDir}/generated/resources"]
}
}
testannotations
}
sourcesJar {
// The resources duplicate content from the src directory.
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
def versions = [
autoValue : "1.7.4",
lombok : "1.18.22",
]
configurations {
implementation.extendsFrom(annotatedGuava)
}
dependencies {
api project(':javacutil')
api project(':dataflow')
api files("${stubparserJar}")
// 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
api('org.checkerframework:annotation-file-utilities:*') {
exclude group: 'com.google.errorprone', module: 'javac'
}
api project(':checker-qual')
// External dependencies:
// If you add an external dependency, you must shadow its packages.
// See the comment in ../build.gradle in the shadowJar block.
implementation 'org.plumelib:plume-util:1.5.8'
implementation 'org.plumelib:reflection-util:1.0.4'
implementation 'io.github.classgraph:classgraph:4.8.126'
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation project(':framework-test')
testImplementation sourceSets.testannotations.output
// AutoValue support in Returns Receiver Checker
testImplementation "com.google.auto.value:auto-value-annotations:${versions.autoValue}"
testImplementation "com.google.auto.value:auto-value:${versions.autoValue}"
// Lombok support in Returns Receiver Checker
testImplementation "org.projectlombok:lombok:${versions.lombok}"
}
task cloneTypetoolsJdk() {
description 'Obtain or update the annotated JDK.'
doLast {
if (file(annotatedJdkHome).exists()) {
exec {
workingDir annotatedJdkHome
executable 'git'
args = ['pull', '-q']
ignoreExitValue = true
}
} else {
println 'Cloning annotated JDK repository.'
exec {
workingDir "${annotatedJdkHome}/../"
executable 'git'
args = ['clone', '-q', '--depth', '1', 'https://github.com/typetools/jdk.git', 'jdk']
}
}
}
}
task copyAndMinimizeAnnotatedJdkFiles(dependsOn: cloneTypetoolsJdk, group: 'Build') {
dependsOn ':framework:compileJava'
def inputDir = "${annotatedJdkHome}/src"
def outputDir = "${buildDir}/generated/resources/annotated-jdk/"
description "Copy annotated JDK files to ${outputDir}. Removes private and package-private methods, method bodies, comments, etc. from the annotated JDK"
inputs.dir file(inputDir)
outputs.dir file(outputDir)
doLast {
FileTree tree = fileTree(dir: inputDir)
SortedSet<String> annotatedForFiles = new TreeSet<>();
tree.visit { FileVisitDetails fvd ->
if (!fvd.file.isDirectory() && fvd.file.name.matches(".*\\.java")
&& !fvd.file.path.contains("org/checkerframework")) {
fvd.getFile().readLines().any { line ->
if (line.contains("@AnnotatedFor") || line.contains("org.checkerframework")) {
annotatedForFiles.add(fvd.file.absolutePath)
return true;
}
}
}
}
String absolutejdkHome = file(annotatedJdkHome).absolutePath
int jdkDirStringSize = absolutejdkHome.size()
copy {
from(annotatedJdkHome)
into(outputDir)
for (String filename : annotatedForFiles) {
include filename.substring(jdkDirStringSize)
}
}
javaexec {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'org.checkerframework.framework.stub.JavaStubifier'
args outputDir
}
}
}
sourcesJar.dependsOn(copyAndMinimizeAnnotatedJdkFiles)
processResources.dependsOn(copyAndMinimizeAnnotatedJdkFiles)
task checkDependencies(dependsOn: ':maybeCloneAndBuildDependencies') {
doLast {
if (!file(stubparserJar).exists()) {
throw new GradleException("${stubparserJar} does not exist. Try running './gradlew cloneAndBuildDependencies'")
}
}
}
compileJava.dependsOn(checkDependencies)
task allSourcesJar(type: Jar, group: 'Build') {
description 'Creates a sources jar that includes sources for all Checker Framework classes in framework.jar'
destinationDirectory = file("${projectDir}/dist")
archiveFileName = "framework-source.jar"
from (project(':framework').sourceSets.main.java,
project(':dataflow').sourceSets.main.allJava,
project(':javacutil').sourceSets.main.allJava)
}
task allJavadocJar(type: Jar, group: 'Build') {
description 'Creates javadoc jar include Javadoc for all of the framework'
dependsOn rootProject.tasks.allJavadoc
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
destinationDirectory = file("${projectDir}/dist")
archiveFileName = "framework-javadoc.jar"
from (project(':framework').tasks.javadoc.destinationDir,
project(':dataflow').tasks.javadoc.destinationDir,
project(':javacutil').tasks.javadoc.destinationDir)
}
shadowJar {
description 'Creates the "fat" framework.jar in dist'
destinationDirectory = file("${projectDir}/dist")
archiveFileName = "framework.jar"
manifest {
attributes('Automatic-Module-Name': "org.checkerframework.framework")
}
}
createCheckTypeTask(project.name, "CompilerMessages",
'org.checkerframework.checker.compilermsgs.CompilerMessagesChecker')
checkCompilerMessages {
options.compilerArgs += [
'-Apropfiles=' + sourceSets.main.resources.filter { file -> file.name.equals('messages.properties') }.asPath
]
}
task loaderTests(dependsOn: 'shadowJar', group: 'Verification') {
description 'Run tests for the annotation class loader'
dependsOn(compileTestJava)
// TODO: this dependency on checker is a bit ugly.
dependsOn project(':checker-qual').tasks.jar
dependsOn project(':checker').tasks.assemble
doLast {
exec {
executable 'make'
args = ['-C', "tests/annotationclassloader/", "all"]
}
}
}
clean {
delete("tests/returnsreceiverdelomboked")
delete('dist')
}
task delombok {
description 'Delomboks the source code tree in tests/returnsreceiverlombok'
def srcDelomboked = 'tests/returnsreceiverdelomboked'
def srcJava = 'tests/returnsreceiverlombok'
inputs.files file(srcJava)
outputs.dir file(srcDelomboked)
// This dependency is required to ensure the checker-qual jar exists,
// to prevent lombok from emitting "cannot find symbol" errors for @This
// annotations in the test input code.
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)
ant.delombok(from: srcJava, to: srcDelomboked, classpath: collection.asPath)
}
}
tasks.test.dependsOn("delombok")