mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Check Java formatting in format.sh (flutter/engine#16500)
Uses google-java-format, a tool that's already in place in flutter/plugins. This should take care of minor style guide issues and unresolved imports.
This commit is contained in:
parent
c69d282dba
commit
d2e8a2d635
14
DEPS
14
DEPS
@ -436,6 +436,20 @@ deps = {
|
||||
'dep_type': 'cipd',
|
||||
},
|
||||
|
||||
'src/third_party/android_tools/google-java-format': {
|
||||
'packages': [
|
||||
{
|
||||
'package': 'flutter/android/google-java-format',
|
||||
'version': 'version:1.7-1'
|
||||
}
|
||||
],
|
||||
# We want to be able to format these as part of CI, and the CI step that
|
||||
# checks formatting runs without downloading the rest of the Android build
|
||||
# tooling. Therefore unlike all the other Android-related tools, we want to
|
||||
# download this every time.
|
||||
'dep_type': 'cipd',
|
||||
},
|
||||
|
||||
'src/third_party/android_tools/sdk/build-tools': {
|
||||
'packages': [
|
||||
{
|
||||
|
||||
@ -30,7 +30,7 @@ CLANG_FORMAT="../buildtools/$OS/clang/bin/clang-format"
|
||||
$CLANG_FORMAT --version
|
||||
|
||||
# Compute the diffs.
|
||||
FILETYPES="*.c *.cc *.cpp *.h *.m *.mm"
|
||||
CLANG_FILETYPES="*.c *.cc *.cpp *.h *.m *.mm"
|
||||
DIFF_OPTS="-U0 --no-color --name-only"
|
||||
|
||||
if git remote get-url upstream >/dev/null 2>&1; then
|
||||
@ -42,10 +42,9 @@ fi;
|
||||
|
||||
BASE_SHA="$(git fetch $UPSTREAM master > /dev/null 2>&1 && \
|
||||
(git merge-base --fork-point FETCH_HEAD HEAD || git merge-base FETCH_HEAD HEAD))"
|
||||
FILES_TO_CHECK="$(git diff $DIFF_OPTS $BASE_SHA -- $FILETYPES)"
|
||||
|
||||
CLANG_FILES_TO_CHECK="$(git diff $DIFF_OPTS $BASE_SHA -- $CLANG_FILETYPES)"
|
||||
FAILED_CHECKS=0
|
||||
for f in $FILES_TO_CHECK; do
|
||||
for f in $CLANG_FILES_TO_CHECK; do
|
||||
set +e
|
||||
CUR_DIFF="$(diff -u "$f" <("$CLANG_FORMAT" --style=file "$f"))"
|
||||
set -e
|
||||
@ -55,6 +54,24 @@ for f in $FILES_TO_CHECK; do
|
||||
fi
|
||||
done
|
||||
|
||||
GOOGLE_JAVA_FORMAT="../third_party/android_tools/google-java-format/google-java-format-1.7-all-deps.jar"
|
||||
if [[ -f "$GOOGLE_JAVA_FORMAT" && -f "$(which java)" ]]; then
|
||||
java -jar "$GOOGLE_JAVA_FORMAT" --version 2>&1
|
||||
JAVA_FILETYPES="*.java"
|
||||
JAVA_FILES_TO_CHECK="$(git diff $DIFF_OPTS $BASE_SHA -- $JAVA_FILETYPES)"
|
||||
for f in $JAVA_FILES_TO_CHECK; do
|
||||
set +e
|
||||
CUR_DIFF="$(diff -u "$f" <(java -jar "$GOOGLE_JAVA_FORMAT" "$f"))"
|
||||
set -e
|
||||
if [[ ! -z "$CUR_DIFF" ]]; then
|
||||
echo "$CUR_DIFF"
|
||||
FAILED_CHECKS=$(($FAILED_CHECKS+1))
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "WARNING: Cannot find google-java-format, skipping Java file formatting!"
|
||||
fi
|
||||
|
||||
if [[ $FAILED_CHECKS -ne 0 ]]; then
|
||||
echo ""
|
||||
echo "ERROR: Some files are formatted incorrectly. To fix, run \`./ci/format.sh | patch -p0\` from the flutter/engine/src/flutter directory."
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user