Skip to content

Commit

Permalink
Update to Error Prone 2.36.0 and test on JDK 21 (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
wmdietl authored Jan 2, 2025
1 parent ed18e69 commit ad8dec7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build:
strategy:
matrix:
jdk: [ 11, 17 ]
jdk: [ 11, 17, 21 ]
runs-on: ubuntu-latest
steps:
- name: Pull Request Checkout
Expand Down
21 changes: 16 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,42 +29,44 @@ 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(),
FilenameUtils.getName(getLatestGitHubReleaseAsset().getPath()));
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,15 +14,15 @@ 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))
.toFile();
}

@Override
public File download() throws IOException {
public File download() throws IOException, URISyntaxException {
File unzipped = getUnzipped();
if (!unzipped.exists()) {
File dest = doDownload();
Expand Down

0 comments on commit ad8dec7

Please sign in to comment.