forked from aws/aws-lambda-java-libs
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·41 lines (36 loc) · 952 Bytes
/
pre-commit
File metadata and controls
executable file
·41 lines (36 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash -e
#
# based on : https://hdpe.me/post/maven-checkstyle-pre-commit-hook/
#
# DESCRIPTION
# Considering only the staged .java files, it walks the filesystem tree
# to look for any modules (it considers a module if it has a pom.xml file).
# For each module found it runs Checkstyle on it.
function get_module() {
local path=$1;
while true; do
path=$(dirname $path);
if [ -f "$path/pom.xml" ]; then
echo "$path";
return;
elif [[ "./" =~ "$path" ]]; then
return;
fi
done
}
modules=();
for file in $(git diff --name-only --cached \*.java); do
module=$(get_module "$file");
if [ "" != "$module" ] \
&& [[ ! " ${modules[@]} " =~ " $module " ]]; then
modules+=("$module");
fi
done;
if [ ${#modules[@]} -eq 0 ]; then
exit;
fi
for dir in ${modules[@]}; do
cd ${dir};
mvn checkstyle:check -Dcheckstyle.config.location=google_checks.xml -Dcheckstyle.consoleOutput=true;
cd ..;
done;