Created
May 30, 2012 16:31
-
-
Save ralfstx/2837460 to your computer and use it in GitHub Desktop.
Checks the year in copyright headers in RAP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to check copyright headers in RAP | |
# Usage: check-copyright.sh <file or folder> | |
# | |
# Checks for latest change of the file. For every file that has been | |
# changed in the current year, but does not have a copyright header | |
# with this year in it, a message is prepended to the file. | |
if [ $# -lt 1 ]; then | |
echo missing argument | |
exit 1 | |
fi | |
filename=$1 | |
if [ -d "$filename" ]; then | |
exec find "$filename" -name "*.java" -o -name "*.js" -exec "$0" "{}" \; | |
elif [ ! -f "$filename" ]; then | |
echo "no such file or directory" | |
exit 1 | |
fi | |
tmpfile=_copyright.tmp | |
# Ignore common third-party copyright headers | |
grep -qi "Copyright.*IBM" "$filename" && exit 0 | |
grep -qi "Copyright.*Yahoo" "$filename" && exit 0 | |
grep -qi "Copyright.*World Wide Web Consortium" "$filename" && exit 0 | |
grep -qi "Copyright.*The Apache Software Foundation" "$filename" && exit 0 | |
currentYear=`date +%Y` | |
year=`git log -n 1 --pretty=format:%ai -- "$filename" | cut -d - -f 1` | |
# only fix copyright for this year, | |
# otherwise the last commit will differ from the copyright again | |
if [ "$year" == "$currentYear" ]; then | |
grep -q "Copyright.*$year" "$filename" | |
if [ $? != 0 ]; then | |
echo "Last changed: $year $filename" | |
mv "$filename" "$tmpfile" | |
echo "Last changed: $year" > "$filename" | |
cat "$tmpfile" >> "$filename" | |
rm "$tmpfile" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment