Skip to content

Instantly share code, notes, and snippets.

@nikku
Created December 8, 2013 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikku/4a4c0b7848bd78afc457 to your computer and use it in GitHub Desktop.
Save nikku/4a4c0b7848bd78afc457 to your computer and use it in GitHub Desktop.
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