Skip to content

Commit

Permalink
Common setup for spotless, error prone, and eisop
Browse files Browse the repository at this point in the history
  • Loading branch information
wmdietl committed Jun 25, 2024
1 parent a7c9289 commit 442e513
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 66 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
java: [ '11', '17', '21', '22' ]
java: [ '8', '11', '17', '21' ]

steps:
- uses: actions/checkout@v4
Expand All @@ -30,4 +30,5 @@ jobs:
- name: ./gradlew requireJavadoc
run: ./gradlew requireJavadoc
- name: ./gradlew spotlessCheck
if: ${{ matrix.java != '8' }}
run: ./gradlew spotlessCheck
137 changes: 77 additions & 60 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
buildscript {
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-library'

// To create a fat jar build/libs/...-all.jar, run: ./gradlew shadowJar
id 'com.github.johnrengelman.shadow' version '8.1.1'

// Code formatting; defines targets "spotlessApply" and "spotlessCheck"
// Requires JDK 11 or higher; the plugin crashes under JDK 8.
id 'com.diffplug.spotless' version '6.25.0'

// Error Prone linter
id('net.ltgt.errorprone') version '4.0.1'

Expand All @@ -26,6 +33,10 @@ repositories {

ext.errorproneVersion = '2.28.0'

ext {
isJava11orHigher = JavaVersion.current() >= JavaVersion.VERSION_11
}

dependencies {
api 'org.checkerframework.annotatedlib:bcel:6.5.0'
// For a locally-built commons-bcel, set $BCEL and use this line instead of the above.
Expand All @@ -34,6 +45,7 @@ dependencies {
implementation 'org.plumelib:reflection-util:1.1.3'

compileOnly "com.google.errorprone:error_prone_annotations:${errorproneVersion}"
errorprone("com.google.errorprone:error_prone_core:${errorproneVersion}")

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
Expand All @@ -43,8 +55,8 @@ dependencies {
apply from: "${buildscript.sourceFile.parent}/gradle/mavencentral.gradle"

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

test {
Expand All @@ -54,38 +66,41 @@ test {
}
}

spotless {
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 {
targetExclude('**/WeakIdentityHashMap.java')
googleJavaFormat()
formatAnnotations()
}
groovyGradle {
target '**/*.gradle'
greclipse() // which formatter Spotless should use to format .gradle files.
indentWithSpaces(2)
trimTrailingWhitespace()
// endWithNewline() // Don't want to end empty files with a newline
if (isJava11orHigher) {
apply plugin: 'com.diffplug.spotless'
spotless {
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 {
targetExclude('**/WeakIdentityHashMap.java')
googleJavaFormat()
formatAnnotations()
}
groovyGradle {
target '**/*.gradle'
greclipse() // which formatter Spotless should use to format .gradle files.
indentWithSpaces(2)
trimTrailingWhitespace()
// endWithNewline() // Don't want to end empty files with a newline
}
}
}

/// Error Prone linter

dependencies {
errorprone("com.google.errorprone:error_prone_core:${errorproneVersion}")
}
tasks.withType(JavaCompile).configureEach {
// "-processing" avoids javac warning "No processor claimed any of these annotations".
options.compilerArgs << '-Xlint:all,-processing' << '-Werror'
// "-Xlint:-options" is because of JDK 21 warning "source value 8 is obsolete..."
options.compilerArgs << '-Xlint:all,-processing,-options' << '-Werror'
options.errorprone.enabled = isJava11orHigher
options.errorprone {
disable('ExtendsObject') // Incorrect when using the Checker Framework
disable('ReferenceEquality') // Use Interning Checker instead.
Expand All @@ -99,12 +114,32 @@ tasks.withType(JavaCompile).configureEach {

apply plugin: 'org.checkerframework'

def EISOPVersion = '3.42.0-eisop3'
if (true) {
// Use the released version of the EISOP Checker Framework.
ext.checkerFrameworkVersion = '3.42.0-eisop3'
} else {
// To use a snapshot version of the EISOP Checker Framework.
// TODO: Change the above test to false to use a snapshot.
ext.checkerFrameworkVersion = '3.42.0-eisop4-SNAPSHOT'
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'minutes'
}
}

dependencies {
compileOnly "io.github.eisop:checker-qual:${EISOPVersion}"
testCompileOnly "io.github.eisop:checker-qual:${EISOPVersion}"
checkerFramework "io.github.eisop:checker:${EISOPVersion}"
compileOnly "io.github.eisop:checker-qual:${checkerFrameworkVersion}"
testCompileOnly "io.github.eisop:checker-qual:${checkerFrameworkVersion}"
checkerFramework "io.github.eisop:checker:${checkerFrameworkVersion}"
}

// To use a locally-built Checker Framework, run gradle with "-PcfLocal".
if (project.hasProperty('cfLocal')) {
def cfHome = String.valueOf(System.getenv('CHECKERFRAMEWORK'))
dependencies {
compileOnly files(cfHome + '/checker/dist/checker-qual.jar')
testCompileOnly files(cfHome + '/checker/dist/checker-qual.jar')
checkerFramework files(cfHome + '/checker/dist/checker.jar')
}
}

checkerFramework {
Expand All @@ -123,42 +158,24 @@ checkerFramework {
'org.checkerframework.common.initializedfields.InitializedFieldsChecker',
]
extraJavacArgs = [
'-Werror',
// No "'-Werror'" because of JDK 21 warning "source value 8 is obsolete..."
// '-Werror',
'-AcheckPurityAnnotations',
'-ArequirePrefixInWarningSuppressions',
'-AwarnRedundantAnnotations',
'-AwarnUnneededSuppressions',
'-AnoJreVersionCheck',
'-Aversion',
]
}
// To use a snapshot version of the Checker Framework.
if (false) {
// TODO: Change the above test to false when CF is released.
ext.checkerFrameworkVersion = '3.44.0'
dependencies {
compileOnly "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
testCompileOnly "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
checkerFramework "org.checkerframework:checker:${checkerFrameworkVersion}"
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'minutes'
}
}
// To use a locally-built Checker Framework, run gradle with "-PcfLocal".
if (project.hasProperty('cfLocal')) {
def cfHome = String.valueOf(System.getenv('CHECKERFRAMEWORK'))
dependencies {
compileOnly files(cfHome + '/checker/dist/checker-qual.jar')
testCompileOnly files(cfHome + '/checker/dist/checker-qual.jar')
checkerFramework files(cfHome + '/checker/dist/checker.jar')
}
}

/// Javadoc

// Turn Javadoc warnings into errors.
javadoc {
options.addStringOption('Xwerror', '-Xdoclint:all')
// No "'-Werror'" because of JDK 21 warning "source value 8 is obsolete..."
// options.addStringOption('Xwerror', '-Xdoclint:all')
options.addStringOption('Xdoclint:all', '-quiet')
options.addStringOption('private', '-quiet')
exclude 'org/plumelib/bcelutil/StackVer.java'
options.with {
Expand All @@ -176,7 +193,7 @@ javadoc {
// * use JDK 17 links, and "--link-modularity-mismatch info", under JDK > 17 (i.e., JDK >= 18).
// But it's easier to just not use "linksOffline".
}
options.addStringOption('source', '11')
options.addStringOption('source', '8')
doLast {
ant.replaceregexp(match:"@import url\\('resources/fonts/dejavu.css'\\);\\s*", replace:'',
flags:'g', byline:true) {
Expand All @@ -191,7 +208,7 @@ task javadocWeb(type: Javadoc) {
source = sourceSets.main.allJava
destinationDir = file("/cse/web/research/plumelib/${project.name}/api")
classpath = project.sourceSets.main.compileClasspath
options.addStringOption('source', '11')
options.addStringOption('source', '8')
doLast {
ant.replaceregexp(match:"@import url\\('resources/fonts/dejavu.css'\\);\\s*", replace:'',
flags:'g', byline:true) {
Expand Down
10 changes: 5 additions & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
buildscript {
if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
throw new Error("Use Java 11 or later.")
}
}
// buildscript {
// if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
// throw new Error("Use Java 11 or later.")
// }
// }

// Project name is read-only in build scripts, and defaults to directory name.
rootProject.name = "bcel-util"

0 comments on commit 442e513

Please sign in to comment.