File: build.gradle

package info (click to toggle)
checker-framework-java 3.0.1%2Bds2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,736 kB
  • sloc: java: 145,286; xml: 785; sh: 456; makefile: 401; perl: 26
file content (332 lines) | stat: -rw-r--r-- 12,039 bytes parent folder | download
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
repositories {
    jcenter()
    mavenCentral()
}

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

    errorproneJavacVersion = '9+181-r4173-1'

    parentDir = file("${rootDir}/../").absolutePath

    annotationTools = "${parentDir}/annotation-tools"
    afu = "${annotationTools}/annotation-file-utilities"
    afuJar = "${afu}/annotation-file-utilities-all-but-javac.jar"

    stubparser = "${parentDir}/stubparser"
    stubparserJar = "${stubparser}/javaparser-core/target/stubparser.jar"

    jtregHome = "${parentDir}/jtreg"

    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"
    }
}

allprojects {
    apply plugin: 'java'

    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 '3.0.1'

    repositories {
        mavenCentral()
    }

    configurations {
        javacJar

        // There's a bug in IntelliJ that adds the processor path to the classpath when building
        // a Gradle project.  Because ErrorProne uses old versions of some of our jars, IntelliJ uses
        // those jars instead of the source code. The next 3 lines exclude Checker Framework from the
        // from the processor path as a work around for this problem.
        annotationProcessor.exclude group:'org.checkerframework', module:'javacutil'
        annotationProcessor.exclude group:'org.checkerframework', module:'dataflow'
        annotationProcessor.exclude group:'org.checkerframework', module:'checker-qual'
    }

    // After all the tasks have been created, modify some of them.
    afterEvaluate {
        /// TODO: One day we can enable this.  For now, CI jobs require Javadoc on changed lines.
        // // Turn Javadoc warnings into errors.
        // tasks.withType(Javadoc) {
        //     options.addStringOption('Xwerror', '-quiet')
        // }

        // Add standard javac options
        tasks.withType(JavaCompile) {
            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.java.net/jeps/247 for details on compiling for older versions.

            // When sourceCompatibilty is changed to 11, then the following will be required.
            // 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.java.net/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.compilerArgs += [
                    '-g',
                    '-Werror',
                    // To not get a warning about missing bootstrap classpath for Java 8 (once we use Java 9).
                    "-Xlint:-options",
                    "-Xlint",
            ]

            options.encoding = 'UTF-8'
            options.fork = true
            if (isJava8) {
                options.forkOptions.jvmArgs += ["-Xbootclasspath/p:${configurations.javacJar.asPath}"]
            }
        }
    }
}

task cloneAndBuildDependencies(type: Exec) {
    description 'Clones (or updates) and builds all dependencies'
    executable 'checker/bin-devel/build.sh'
    args = ['downloadjdk']
}

task version() {
    description 'Print Checker Framework version'
    doLast {
        println version
    }
}




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"
    ]
}



/**
 * Creates a task named taskName that runs javadoc.
 *
 * @param taskName the name of the task to create
 * @param taskDescription description of the task
 * @param memberLevel the JavadocMemberLevel to use
 * @param requireJavadoc whether or not to run the RequireJavadoc doclet. If false -Xdoclint:all is
 * passed. Defaults to true.
 * @return the new task
 */



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 {


    // 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
            //We're only building checker-qual
                metaInf {
                    from './LICENSE.txt'
                }
            manifest {
                attributes("Implementation-Version": "${version}")
                attributes("Implementation-URL": "https://checkerframework.org")

                //We're only building checker-qual
                    attributes("Bundle-License": "MIT")
            }
        }

    }
}


task checkBasicStyle(group: 'Format') {
    description 'Check basic style guidelines.  Not related to Checkstyle tool.'
    String[] ignoreDirectories = ['.git',
                                  '.gradle',
                                  '.idea',
                                  '.plume-scripts',
                                  '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 the CI tests.
    tasks = ['clean', 'assemble']
}

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}