Skip to content

Instantly share code, notes, and snippets.

@nikku nikku/bash-code-metrics.sh Secret
Created Dec 8, 2013

Embed
What would you like to do?
A small utility script that computes Java code metrics over a series of versions (in terms of git tags or commits).
#/bin/bash
src_dir=$1
test_dir=$2
commits=`cat $3`
commits_count=`echo $commits | wc -w`
dest_file=$4
printf "Writing metrics for %s commits into %s\n src_dir: %s\n test_dir: %s\n" $tag_count $dest_file $src_dir $test_dir
count=0
for commit in $commits
do
printf "."
# checkout
git checkout -q $commit
src_files=$(find $src_dir -type f -name '*.java' | wc -l)
src_loc=$(find $src_dir -type f -name '*.java' -exec cat {} \; | sed '/^\s*$/d' | wc -l)
test_files=$(find $test_dir -type f -name '*.java' | wc -l)
test_loc=$(find $test_dir -type f -name '*.java' -exec cat {} \; | sed '/^\s*$/d' | wc -l)
tests=$(find $test_dir -type f -name '*.java' -exec cat {} \; | grep @Test | wc -l)
echo "$commit;$src_files;$test_files;$src_loc;$test_loc;$tests" >> $dest_file
done
printf "\nDone.\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.