mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 03:57: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
|
exit 1
|
||||||
fi
|
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() {
|
function showNoncompliantFiles() {
|
||||||
local forkPoint="$1"
|
local forkPoint="$1"
|
||||||
local message="$2"
|
local message="$2"
|
||||||
|
|
||||||
git diff -U0 ${forkPoint} | \
|
runGoogleJavaFormatAgainstDiffs "$forkPoint" | showFileNames "$2"
|
||||||
${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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function callGoogleJavaFormatDiff() {
|
function callGoogleJavaFormatDiff() {
|
||||||
|
@ -82,27 +96,18 @@ function callGoogleJavaFormatDiff() {
|
||||||
local callResult
|
local callResult
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"check")
|
"check")
|
||||||
showNoncompliantFiles "$forkPoint" "\033[1mNeeds formatting: "
|
local output=$(runGoogleJavaFormatAgainstDiffs "$forkPoint")
|
||||||
callResult=$(git diff -U0 ${forkPoint} | \
|
echo "$output" | showFileNames "\033[1mNeeds formatting: "
|
||||||
${SCRIPT_DIR}/google-java-format-diff.py \
|
callResult=$(echo -n "$output" | wc -l)
|
||||||
--java-binary "$JAVA_BIN" \
|
|
||||||
--google-java-format-jar "${SCRIPT_DIR}/${JAR_NAME}" \
|
|
||||||
-p1 | wc -l)
|
|
||||||
;;
|
;;
|
||||||
"format")
|
"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: "
|
showNoncompliantFiles "$forkPoint" "\033[1mReformatting: "
|
||||||
callResult=$(git diff -U0 ${forkPoint} | \
|
callResult=$(runGoogleJavaFormatAgainstDiffs "$forkPoint" -i)
|
||||||
${SCRIPT_DIR}/google-java-format-diff.py \
|
|
||||||
--java-binary "$JAVA_BIN" \
|
|
||||||
--google-java-format-jar "${SCRIPT_DIR}/${JAR_NAME}" \
|
|
||||||
-p1 -i)
|
|
||||||
;;
|
;;
|
||||||
"show")
|
"show")
|
||||||
callResult=$(git diff -U0 ${forkPoint} | \
|
callResult=$(runGoogleJavaFormatAgainstDiffs "$forkPoint")
|
||||||
${SCRIPT_DIR}/google-java-format-diff.py \
|
|
||||||
--java-binary "$JAVA_BIN" \
|
|
||||||
--google-java-format-jar "${SCRIPT_DIR}/${JAR_NAME}" \
|
|
||||||
-p1)
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
echo -e "\033[0m" 1>&2
|
echo -e "\033[0m" 1>&2
|
||||||
|
|
Loading…
Add table
Reference in a new issue