mirror of
https://github.com/google/nomulus.git
synced 2025-04-29 19:47:51 +02:00
Pass --java-binary to _all_ formatter invocations (#1024)
* Pass --java-binary to _all_ formatter invocations When implementing a flag to pass in the java binary to google-java-format-diff.py, I missed the location in showNoncompliantFiles which gets run before a check. This change also refactors the core logic of the script so that google-java-format-diff.py is only called from one place and (in all but one case) only one time. Tested: Ran check format and show, with and without diffs present in the tree.
This commit is contained in:
parent
67d767bd68
commit
08c704ee52
1 changed files with 26 additions and 21 deletions
|
@ -64,15 +64,29 @@ if ! "$JAVA_BIN" -version 2>&1 | grep 'version "11\.' >/dev/null; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
function runGoogleJavaFormatAgainstDiffs() {
|
||||
local forkPoint="$1"
|
||||
shift
|
||||
|
||||
git diff -U0 "$forkPoint" | \
|
||||
${SCRIPT_DIR}/google-java-format-diff.py \
|
||||
--java-binary "$JAVA_BIN" \
|
||||
--google-java-format-jar "${SCRIPT_DIR}/${JAR_NAME}" \
|
||||
-p1 "$@" | tee gjf.out
|
||||
}
|
||||
|
||||
# Show the file names in a diff preceeded by a message.
|
||||
function showFileNames() {
|
||||
local message="$1"
|
||||
|
||||
awk -v "message=$message" '/\+\+\+ ([^ ]*)/ { print message $2 }' 1>&2
|
||||
}
|
||||
|
||||
function showNoncompliantFiles() {
|
||||
local forkPoint="$1"
|
||||
local message="$2"
|
||||
|
||||
git diff -U0 ${forkPoint} | \
|
||||
${SCRIPT_DIR}/google-java-format-diff.py \
|
||||
--google-java-format-jar "${SCRIPT_DIR}/${JAR_NAME}" \
|
||||
-p1 | awk -v "message=$message" \
|
||||
'/\+\+\+ ([^ ]*)/ { print message $2 }' 1>&2
|
||||
runGoogleJavaFormatAgainstDiffs "$forkPoint" | showFileNames "$2"
|
||||
}
|
||||
|
||||
function callGoogleJavaFormatDiff() {
|
||||
|
@ -82,27 +96,18 @@ function callGoogleJavaFormatDiff() {
|
|||
local callResult
|
||||
case "$1" in
|
||||
"check")
|
||||
showNoncompliantFiles "$forkPoint" "\033[1mNeeds formatting: "
|
||||
callResult=$(git diff -U0 ${forkPoint} | \
|
||||
${SCRIPT_DIR}/google-java-format-diff.py \
|
||||
--java-binary "$JAVA_BIN" \
|
||||
--google-java-format-jar "${SCRIPT_DIR}/${JAR_NAME}" \
|
||||
-p1 | wc -l)
|
||||
local output=$(runGoogleJavaFormatAgainstDiffs "$forkPoint")
|
||||
echo "$output" | showFileNames "\033[1mNeeds formatting: "
|
||||
callResult=$(echo -n "$output" | wc -l)
|
||||
;;
|
||||
"format")
|
||||
# Unfortunately we have to do this twice if we want to see the names of
|
||||
# the files that got reformatted
|
||||
showNoncompliantFiles "$forkPoint" "\033[1mReformatting: "
|
||||
callResult=$(git diff -U0 ${forkPoint} | \
|
||||
${SCRIPT_DIR}/google-java-format-diff.py \
|
||||
--java-binary "$JAVA_BIN" \
|
||||
--google-java-format-jar "${SCRIPT_DIR}/${JAR_NAME}" \
|
||||
-p1 -i)
|
||||
callResult=$(runGoogleJavaFormatAgainstDiffs "$forkPoint" -i)
|
||||
;;
|
||||
"show")
|
||||
callResult=$(git diff -U0 ${forkPoint} | \
|
||||
${SCRIPT_DIR}/google-java-format-diff.py \
|
||||
--java-binary "$JAVA_BIN" \
|
||||
--google-java-format-jar "${SCRIPT_DIR}/${JAR_NAME}" \
|
||||
-p1)
|
||||
callResult=$(runGoogleJavaFormatAgainstDiffs "$forkPoint")
|
||||
;;
|
||||
esac
|
||||
echo -e "\033[0m" 1>&2
|
||||
|
|
Loading…
Add table
Reference in a new issue