From cb7c169c4064b83762941e1c2222c8606817f7bb Mon Sep 17 00:00:00 2001 From: Johannes Bauer <82513679+bauerjs1@users.noreply.github.com> Date: Mon, 8 Nov 2021 14:20:10 +0100 Subject: [PATCH] Support JDK 17 Analogous to #22 : * Update to latest `google-java-format-1.12.0-all-deps.jar` to support JDK 17 language features. * Update `java` command to comply with [JEP 261: Module System](https://openjdk.java.net/jeps/261) updates to run with strict encapsulation by default. --- format-code.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/format-code.sh b/format-code.sh index da44ba3..27c232c 100755 --- a/format-code.sh +++ b/format-code.sh @@ -1,13 +1,23 @@ #!/usr/bin/env sh + +VERSION=1.12.0 +JARFILE=google-java-format-$VERSION-all-deps.jar + mkdir -p .cache cd .cache -if [ ! -f google-java-format-1.7-all-deps.jar ] +if [ ! -f $JARFILE ] then - curl -LJO "https://github.com/google/google-java-format/releases/download/google-java-format-1.7/google-java-format-1.7-all-deps.jar" - chmod 755 google-java-format-1.7-all-deps.jar + curl -LJO "https://github.com/google/google-java-format/releases/download/v$VERSION/$JARFILE" + chmod 755 $JARFILE fi cd .. changed_java_files=$(git diff --cached --name-only --diff-filter=ACMR | grep ".*java$" ) echo $changed_java_files -java -jar .cache/google-java-format-1.7-all-deps.jar --replace $changed_java_files +java \ + --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ + --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ + -jar .cache/$JARFILE --replace $changed_java_files