Skip to content

Commit

Permalink
add choose language option
Browse files Browse the repository at this point in the history
  • Loading branch information
yangziwen committed Jan 12, 2022
1 parent bc41a87 commit 5e32436
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 11 additions & 1 deletion hooks/pre-commit-checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ if [[ "true" != "$checkstyle_enabled" ]]; then
exit 0
fi

checkstyle_language="`git config --get diff-check.checkstyle.language`"
if [ ! -n "$checkstyle_language" ]; then
checkstyle_language="`git config --get diff-check.language`"
fi
if [ -n "$checkstyle_language" ]; then
checkstyle_language=" -Duser.language=$checkstyle_language "
else
checkstyle_langauge=""
fi

GIT_ROOT_DIR=`git rev-parse --show-toplevel`
GIT_HOOK_DIR=`git config --get core.hooksPath`
if [ ! -d "${GIT_HOOK_DIR}" ]; then
Expand Down Expand Up @@ -33,7 +43,7 @@ if [ -z "$checkstyle_config_file" -o ! -f "$checkstyle_config_file" ]; then
fi

echo "Check Style"
java -jar ${GIT_HOOK_DIR}/diff-checkstyle.jar -c $checkstyle_config_file --git-dir ${GIT_ROOT_DIR} --include-staged-codes $exclude_regexp_opt
java $checkstyle_language -jar ${GIT_HOOK_DIR}/diff-checkstyle.jar -c $checkstyle_config_file --git-dir ${GIT_ROOT_DIR} --include-staged-codes $exclude_regexp_opt
result=$?
if [ $result -ne 0 ]; then
echo "Please fix the checkstyle problems before submit the commit!"
Expand Down
13 changes: 12 additions & 1 deletion hooks/pre-commit-pmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ if [[ "true" != "$pmd_enabled" ]]; then
exit 0
fi

pmd_language="`git config --get diff-check.pmd.language`"
if [ ! -n "$pmd_language" ]; then
pmd_language="`git config --get diff-check.language`"
fi
if [ -n "$pmd_language" ]; then
pmd_language=" -Dpmd.language=$pmd_language "
else
pmd_language=""
fi


GIT_ROOT_DIR=`git rev-parse --show-toplevel`
GIT_HOOK_DIR=`git config --get core.hooksPath`
if [ ! -d "${GIT_HOOK_DIR}" ]; then
Expand Down Expand Up @@ -34,7 +45,7 @@ if [ -z "$pmd_rulesets" ]; then
pmd_rulesets="rulesets/java/ali-all.xml"
fi
echo "PMD Check"
java -jar ${GIT_HOOK_DIR}/diff-pmd.jar -R $pmd_rulesets -f diff-text -git-dir ${GIT_ROOT_DIR} -include-staged-codes $exclude_regexp_opt
java $pmd_language -jar ${GIT_HOOK_DIR}/diff-pmd.jar -R $pmd_rulesets -f diff-text -git-dir ${GIT_ROOT_DIR} -include-staged-codes $exclude_regexp_opt
result=$?
if [ $result -ne 0 ]; then
echo "Please fix the pmd problems before submit the commit!"
Expand Down

0 comments on commit 5e32436

Please sign in to comment.