3

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.

Brian Laframboise
  • 5,504
  • 2
  • 31
  • 32
  • See also this question: [The Halting Problem in the field](http://stackoverflow.com/questions/235984/the-halting-problem-in-the-field) – David Schmitt Dec 30 '08 at 07:13

2 Answers2

1

IntelliJ IDEA has this functionality. Unfortunately is it used within the app and not as a Maven plugin.

Some of the modules in IDEA are open source. Many plugins are available to the community. Perhaps you could peek at their website to see if there is anything you can grab.

I hope this helps http://www.jetbrains.net/devnet/index.jspa

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
OscarRyz
  • 196,001
  • 113
  • 385
  • 569
  • 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 Dec 29 '08 at 20:28
  • Unfortunately, I'm in an Eclipse/RAD environment so this isn't a viable alternative for me. Thanks though! – Brian Laframboise Dec 29 '08 at 20:39
  • @duffymo. He he I would like to get paid for saying nice things about Idea. A license could do the work too ;) – OscarRyz Dec 29 '08 at 22:47
  • How does that feature work? In many cases, which properties you use are decided at runtime. – Chase Seibert Dec 30 '08 at 03:17
  • 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 Dec 30 '08 at 21:02
  • and how do you do it using ItelliJ? – jpganz18 Apr 20 '16 at 17:08
  • @jpganz18 it works out of the box for me. I'm not sure. This is the doc I've found https://www.jetbrains.com/help/idea/2016.1/properties-files.html?origin=old_help – OscarRyz Apr 21 '16 at 15:52
0

I think that JInto can help you.

http://www.guh-software.de/jinto_en.html

msugar
  • 1