Verifying Header Comments

From Pterodactylus
Revision as of 14:07, 17 January 2013 by Bombe (talk | contribs) (Added categories.)
Jump to: navigation, search

A normal Java source file (in my projects) consists of a header like the following one:

/*
 * FreenetSone - EditImagePage.java - Copyright © 2010–2012 David Roden
 *
…

It should contain the name of the project and the name of the file. Sometimes, due to refactoring or copy/paste, the filename in the header does not match the name of the file in question. The following bash script will locate those files:

# grep -r "Copyright" src/ | grep "java:" | while read line; do f="$(echo "$line" | cut -d: -f1)"; c="$(echo "$line" | cut -d- -f2 | cut -d' ' -f2)"; f2="$(basename "$f")"; [ "$c" != "$f2" ] && echo "$f: $c"; done

And sometimes you even changed the name of the project at some point in the past. Use the following oneliner to find those files that have a different project name than the one you substitute at the end of the command:

# grep -r "Copyright" src/ | grep "java:" | while read line; do f="$(echo "$line" | cut -d: -f1)"; project="$(echo "$line" | cut -d' ' -f3)"; [ $project != "Sone" ] && echo "$f: $project"; done