Skip to content

Commit

Permalink
[BUILD] Check java formatting in Travis CI
Browse files Browse the repository at this point in the history
* Introduced Formatting stage in travis
* Created script for downloading and executing
  the google java formatter
  • Loading branch information
m273d15 committed Nov 26, 2018
1 parent e92567d commit 57f7bfb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ jobs:
allow_failures:
- env: J_TYPE=STF_TEST
include:
- if: type in (push, pull_request)
- stage: formatting
if: type in (push, pull_request)
script:
- $PWD/travis/script/format/check_java.sh $PWD

- stage: build
if: type in (push, pull_request)
before_script: docker pull saros/ci_build:0.2
script:
- docker run -td --name build -v $PWD:/home/ci/saros_src saros/ci_build:0.2 bash
Expand Down
34 changes: 34 additions & 0 deletions travis/script/format/check_java.sh
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 "$jar_name" "$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 $?

0 comments on commit 57f7bfb

Please sign in to comment.