views:

281

answers:

4

Given a set of properties files and list of files which may reference keys in those properties files, what's the easiest way to determine which keys are unused?

Example:

Given a project with files

muppets.properties

kermit=Kermit the Frog
oscar=Oscar the Grouch

smurfs.properties

papa=Papa Smurf

and /WEB-INF/pages/template.jsp

Some jsp template displaying the key <bean:write bundle='muppets' key='kermit'/>.

then running program with inputs "*.properties" and "/WEB-INF/**/*.jsp" should report

Unused properties:

muppets.properties
oscar

smurfs.properties
papa

What's the simplest way to do this? Are there any open-source Java libraries that make this easy? The idea is to embed the solution inside an in-house Maven reporting plugin that would run when building a web app.

I'm aware that there will be false positives (key strings appearing in the files in a non-key context), but that's ok. Being able to find any unused keys would be helpful.

Edit: I'm seeking a standalone code-base solution.

+1  A: 
OscarRyz
Another great reason why IntelliJ is the best IDE there is, hands down. (No, I don't work for them, and I don't get paid to say nice things.)
duffymo
Unfortunately, I'm in an Eclipse/RAD environment so this isn't a viable alternative for me. Thanks though!
Brian Laframboise
@duffymo. He he I would like to get paid for saying nice things about Idea. A license could do the work too ;)
OscarRyz
How does that feature work? In many cases, which properties you use are decided at runtime.
Chase Seibert
The way that work is to look at your code ( all of the available code in the project ) and see if you're using the "key" of the property. If you don't the analyzer marks it as "unused". Pretty much the same way it does with any other variable.
OscarRyz
A: 

See also this question: The Halting Problem in the field

David Schmitt
A: 

I'm also interested in such a feature. My solution for now is to just use the search function of eclipse to check my project if there is a key anywhere. It would be great if this could be done automaticly.

kukudas
A: 

I think that JInto can help you.

http://www.guh-software.de/jinto%5Fen.html

msugar