This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with properties file

 
Neha Kathuriaa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I want to know .How do we find out the unused entries in a properties file and later remove them. Any idea
Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Define "unused". Not used by your application? And what if another application uses those properties?
 
Neha Kathuriaa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those which are unused by any application.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's going to be hard, and I doubt it can be done automatically.

You first would have to find all Properties objects that load from that properties file (already quite hard - sometimes the properties file can be relative, otherwise absolute). Then you have to find all calls to getProperty on those objects and retrieve the property name from those calls. And that for all applications that can potentially use the file.


Now, if it's just one application, and one point of reading the file, you can choose to rebuild the Properties objects at that point. Strip away all properties you don't plan on using:

Afterwards the Properties object only contains the properties you are using (provided isUsedKeyForMyApplication is implemented properly), and when you store it again the file will only contain the properties you want.


Of course it is a LOT more difficult to do if there really are multiple applications reading the file, or multiple points at which the file is read (although the latter can be handled by a single method call).
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no way of really ever knowing this. All you can do is scan your source code to see what properties they reference. Mind you there are binaries/programs that could be referencing properties and you wouldn't necessarily know it. But I assume you are talking about properties for your application only here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic