summaryrefslogtreecommitdiff
path: root/scripts/format.sh
blob: e22f06e544cf177338d1a6c53a364b873893a6ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash

# Grab root directory to help with creating an absolute path for changed files.
root_dir="$(git rev-parse --show-toplevel)"
[ -d "${root_dir}" ] || exit 1

# Path to jar
jar_base_dir="git_hooks/"
formatter_jar="${root_dir}/${jar_base_dir}/google-java-format-1.6-SNAPSHOT-all-deps.jar"
formatter_cmd="java -jar ${formatter_jar}"

# Format file in-place and use 4-space style (AOSP).
formatter_args="--replace --aosp"

changed_java_files=($(find src/main/java src/test/java -name '*.java'))

# If we have changed java files, format them!
eval ${formatter_cmd} ${formatter_args} "${changed_java_files[@]}"