Is there any tool to detect code/functionality which is no longer used?

流过昼夜 提交于 2020-01-14 02:54:06

问题


We have many applications running (consider all of them run on Java Platform) and we need to check which ones were used in the last, say, 3 months, and, among those active applications, which parts/functionalities (and how often) are still being used. Is that possible?

The goal here is to detect applications or funcionalities which no longer are relevant to the business and remove them, so that we end up having less code to maintain and monitor.

Is there any tool which could help us achieving that?


We DO use agile methods, so when a new application gets into production it has only the funcionalities which are important to the business, but sometimes some features of this application expires (for different reasons), so we would like to have a way of identifying that.


回答1:


There are at least two tools you can deploy along your application and collect some statistics, even in production:

  1. AspectJ - weave all classes and somehow log every method execution.

  2. JaCoCo - essentially does the same thing but automatically with a help of a Java agent. Executed methods/branches (in fact, this is a code coverage tool) are saved in a file for future processing. Should solve your problem pretty easy.

Both approaches should work with any JVM language (I see jruby in your question) as they work on bytecode level. I once used JaCoCo to measure code coverage (think: which methods/branches were execured) during Selenium test run.




回答2:


For example, Intellij IDEA has static analysis which greys out names of Types/Methods which aren't called. If you want automatic tool for that, try Sonar. I guess, both of these methods can give a few false results if you use reflection in some form.




回答3:


There is also PMD

btw it could be installed as a plugin for different IDEs




回答4:


I'm also using the following static analysis tools:

  • UCDetector (open source eclipse plugin) - can be quite helpful.

  • Structure101 (commercial software)- can be used for that purpose (e.g. finding unused classes), too.




回答5:


You can use JArchitect tool to analyse your code and detect the unused code and functionnalities, there are some of it's functionnalities :

  • Code Query language (CQLinq),
  • more than 80 Metrics,
  • and display analysis results in different types of Diagrams


来源:https://stackoverflow.com/questions/8449870/is-there-any-tool-to-detect-code-functionality-which-is-no-longer-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!