From ad8dec7c9cafd242abb3db18d011ef43953dab83 Mon Sep 17 00:00:00 2001 From: Werner Dietl Date: Thu, 2 Jan 2025 17:24:55 -0500 Subject: [PATCH] Update to Error Prone 2.36.0 and test on JDK 21 (#232) --- .github/workflows/main.yml | 2 +- build.gradle | 21 +++++++++++++----- .../languageserver/BaseDownloader.java | 22 +++++++++++-------- .../CheckerFrameworkDownloader.java | 5 +++-- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f668f11..7db97f6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: build: strategy: matrix: - jdk: [ 11, 17 ] + jdk: [ 11, 17, 21 ] runs-on: ubuntu-latest steps: - name: Pull Request Checkout diff --git a/build.gradle b/build.gradle index e6dc481..fd736d3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,8 @@ plugins { id 'java' id 'application' - id 'com.github.johnrengelman.shadow' version '8.1.1' + // https://plugins.gradle.org/plugin/com.gradleup.shadow + id 'com.gradleup.shadow' version '8.3.5' id 'com.diffplug.spotless' version '6.25.0' id 'net.ltgt.errorprone' version '4.1.0' } @@ -21,8 +22,10 @@ dependencies { 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' + if (JavaVersion.current() >= JavaVersion.VERSION_17) { + errorprone('com.google.errorprone:error_prone_core:2.36.0') + errorproneJavac('com.google.errorprone:javac:9+181-r4173-1') + } } application { @@ -34,8 +37,9 @@ shadowJar { minimize() } -tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:deprecation" +tasks.withType(JavaCompile) { compilationTask -> + options.compilerArgs += ['-Xlint', '-Werror'] + options.errorprone.enabled = JavaVersion.current() >= JavaVersion.VERSION_17 } spotless { @@ -44,4 +48,11 @@ spotless { importOrder('com', 'jdk', 'lib', 'lombok', 'org', 'java', 'javax') formatAnnotations() } + groovyGradle { + target '*.gradle' + importOrder() + greclipse() // which formatter Spotless should use to format .gradle files. + indentWithSpaces(4) + trimTrailingWhitespace() + } } diff --git a/src/main/java/org/checkerframework/languageserver/BaseDownloader.java b/src/main/java/org/checkerframework/languageserver/BaseDownloader.java index 16aa655..ead8f65 100644 --- a/src/main/java/org/checkerframework/languageserver/BaseDownloader.java +++ b/src/main/java/org/checkerframework/languageserver/BaseDownloader.java @@ -11,6 +11,8 @@ import java.io.File; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Path; @@ -27,34 +29,36 @@ protected BaseDownloader(String org, String repo, File folder) { this.folder = folder; } - public File download() throws IOException { + public File download() throws IOException, URISyntaxException { if (!exists()) { return doDownload(); } return getDestination(); } - public boolean exists() throws IOException { + public boolean exists() throws IOException, URISyntaxException { return getDestination().exists(); } - public URL getLatestGitHubReleaseURL() throws MalformedURLException { - return new URL("https://api.github.com/repos/" + org + "/" + repo + "/releases/latest"); + public URL getLatestGitHubReleaseURL() throws MalformedURLException, URISyntaxException { + return new URI("https://api.github.com/repos/" + org + "/" + repo + "/releases/latest") + .toURL(); } - public JsonElement getLatestGitHubRelease() throws IOException { + public JsonElement getLatestGitHubRelease() throws IOException, URISyntaxException { String json = IOUtils.toString(getLatestGitHubReleaseURL(), StandardCharsets.UTF_8.name()); return JsonParser.parseString(json); } - public URL getLatestGitHubReleaseAsset() throws IOException { + public URL getLatestGitHubReleaseAsset() throws IOException, URISyntaxException { JsonElement root = getLatestGitHubRelease(); JsonArray assets = root.getAsJsonObject().getAsJsonArray("assets"); - return new URL(assets.get(0).getAsJsonObject().get("browser_download_url").getAsString()); + return new URI(assets.get(0).getAsJsonObject().get("browser_download_url").getAsString()) + .toURL(); } // returns the File object corresponding to a file if it's successful downloaded - public File getDestination() throws IOException { + public File getDestination() throws IOException, URISyntaxException { Path dest = Paths.get( folder.getAbsolutePath(), @@ -62,7 +66,7 @@ public File getDestination() throws IOException { return dest.toFile(); } - protected File doDownload() throws IOException { + protected File doDownload() throws IOException, URISyntaxException { URL assetURL = getLatestGitHubReleaseAsset(); File dest = getDestination(); System.out.printf("Downloading from %s to %s\n", assetURL.toString(), dest.toString()); diff --git a/src/main/java/org/checkerframework/languageserver/CheckerFrameworkDownloader.java b/src/main/java/org/checkerframework/languageserver/CheckerFrameworkDownloader.java index 17edf37..85f46e6 100644 --- a/src/main/java/org/checkerframework/languageserver/CheckerFrameworkDownloader.java +++ b/src/main/java/org/checkerframework/languageserver/CheckerFrameworkDownloader.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import java.nio.file.Paths; import net.lingala.zip4j.ZipFile; @@ -13,7 +14,7 @@ public CheckerFrameworkDownloader(String org, String repo, File folder) { super(org, repo, folder); } - private File getUnzipped() throws IOException { + private File getUnzipped() throws IOException, URISyntaxException { File dest = getDestination(); String cfzip = dest.getAbsolutePath(); return Paths.get(FilenameUtils.getFullPath(cfzip), FilenameUtils.getBaseName(cfzip)) @@ -21,7 +22,7 @@ private File getUnzipped() throws IOException { } @Override - public File download() throws IOException { + public File download() throws IOException, URISyntaxException { File unzipped = getUnzipped(); if (!unzipped.exists()) { File dest = doDownload();