Make the formatting tasks work with Java 17 (#2301)

TESTED=ran gradle jIFA locally after intentionally mis-formatting a Java
file.
This commit is contained in:
Lai Jiang 2024-01-24 17:15:13 -05:00 committed by GitHub
parent 2166c28d6d
commit a4903c27b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 28 deletions

View file

@ -503,10 +503,8 @@ def createGetBuildSrcDirectDepsTask(outputFileName) {
rootProject.ext { rootProject.ext {
invokeJavaDiffFormatScript = { action -> invokeJavaDiffFormatScript = { action ->
println("JAVA_HOME=${System.env.JAVA_HOME}") def javaHome = project.findProperty('org.gradle.java.home')
println("PATH=${System.env.PATH}") println("Running the formatting tool with JDK at $javaHome")
println(ext.execInBash("type java", "${rootDir}"))
println(ext.execInBash("java -version", "${rootDir}"))
def scriptDir = rootDir.path.endsWith('buildSrc') def scriptDir = rootDir.path.endsWith('buildSrc')
? "${rootDir}/../java-format" ? "${rootDir}/../java-format"
: "${rootDir}/java-format" : "${rootDir}/java-format"
@ -517,7 +515,7 @@ rootProject.ext {
def pythonExe = getPythonExecutable() def pythonExe = getPythonExecutable()
return ext.execInBash( return ext.execInBash(
"PYTHON=${pythonExe} ${formatDiffScript} ${action}", "${workingDir}") "JAVA=${javaHome}/bin/java PYTHON=${pythonExe} ${formatDiffScript} ${action}", "${workingDir}")
} }
} }

Binary file not shown.

View file

@ -40,37 +40,22 @@ where:
show show the effect of the formatting as unified diff" show show the effect of the formatting as unified diff"
SCRIPT_DIR="$(realpath $(dirname $0))" SCRIPT_DIR="$(realpath $(dirname $0))"
JAR_NAME="google-java-format-1.8-all-deps.jar" JAR_NAME="google-java-format-1.19.2-all-deps.jar"
# Make sure we have a valid python interpreter. # Make sure we have a valid python interpreter.
if [ -z "$PYTHON" ]; then if [ -z "$PYTHON" ]; then
echo "You must specify the name of a python3 interpreter in the PYTHON" \ echo "You must specify the name of a Python interpreter in the PYTHON" \
"environment variable." "environment variable."
exit 1 exit 1
elif ! "$PYTHON" -c ''; then elif ! "$PYTHON" -c ''; then
echo "Invalid python interpreter: $PYTHON" echo "Invalid Python interpreter: $PYTHON"
exit 1 exit 1
fi fi
# Locate the java binary. # Make sure we have a valid JRE binary
if [ -n "$JAVA_HOME" ]; then if [ -z "$JAVA" ]; then
JAVA_BIN="$JAVA_HOME/bin/java" echo "You must specify the name of a JRE binary in the JAVA" \
if [ ! -x "$JAVA_BIN" ]; then "environment variable."
echo "No java binary found in JAVA_HOME (JAVA_HOME is $JAVA_HOME)"
exit 1
fi
else
# Use java from the path.
JAVA_BIN="$(which java)" || JAVA_BIN=""
if [ -z "$JAVA_BIN" ]; then
echo "JAVA_HOME is not defined and java was not found on the path"
exit 1
fi
fi
if ! "$JAVA_BIN" -version 2>&1 | grep 'version "11\.' >/dev/null; then
echo "Bad java version. Requires java 11, got:"
"$JAVA_BIN" -version
exit 1 exit 1
fi fi
@ -80,7 +65,7 @@ function runGoogleJavaFormatAgainstDiffs() {
git diff -U0 "$forkPoint" | \ git diff -U0 "$forkPoint" | \
"${PYTHON}" "${SCRIPT_DIR}/google-java-format-diff.py" \ "${PYTHON}" "${SCRIPT_DIR}/google-java-format-diff.py" \
--java-binary "$JAVA_BIN" \ --java-binary "$JAVA" \
--google-java-format-jar "${SCRIPT_DIR}/${JAR_NAME}" \ --google-java-format-jar "${SCRIPT_DIR}/${JAR_NAME}" \
-p1 "$@" | \ -p1 "$@" | \
tee gjf.out tee gjf.out