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 aa2d20e commit ced4a5c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ 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/build_test:0.1
script:
- docker run -v $PWD:/home/saros/ci/saros_src saros/build_test:0.1 /home/saros/ci/saros_src/travis/script/build/build_all.sh
after_success:
- sonar-scanner
# set env to avoid multiple build executions

- <<: *stf_before_script
script: docker exec -t stf_master scripts/start_stf_tests.sh
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 ced4a5c

Please sign in to comment.