-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUILD] Check java formatting in Travis CI
* Introduced Formatting stage in travis * Created script for downloading and executing the google java formatter
- Loading branch information
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
shopt -s globstar | ||
|
||
project_root_dir=$1 | ||
formatter_jar_name=formatter.jar | ||
|
||
function download_formatter() { | ||
local jar_name=$1 | ||
local url="https://repo.maven.apache.org/maven2/com/google/googlejavaformat/google-java-format/1.6/google-java-format-1.6-all-deps.jar" | ||
echo "Downloading formatter from $url" | ||
curl -Lo formatter.jar "$url" | ||
} | ||
|
||
function check_formatting() { | ||
local jar_name=$1 | ||
|
||
echo 'Checking format' | ||
java -jar "$jar_name" --dry-run --set-exit-if-changed **/*.java | ||
|
||
local rc=$? | ||
[ "$rc" == "0" ] && | ||
echo 'All files are well formatted' || | ||
printf "\nERROR: Some files are not well formatted. The file list above shows all files containing a wrong formatting.\n" | ||
|
||
return "$rc" | ||
} | ||
|
||
cd $project_root_dir | ||
|
||
download_formatter $formatter_jar_name | ||
check_formatting $formatter_jar_name | ||
|
||
exit $? |