是否有任何工具可以检测不再使用的代码/功能?
我们有许多应用程序正在运行(考虑所有应用程序都在 Java 平台上运行),我们需要检查过去(例如 3 个月)使用了哪些应用程序,以及在这些活动应用程序中,哪些部分/功能(以及使用频率)仍在使用中。这可能吗?
这里的目标是检测不再与业务相关的应用程序或功能并将其删除,以便我们最终需要维护和监控的代码更少。
有没有什么工具可以帮助我们实现这一目标?
我们确实使用敏捷方法,因此当新应用程序投入生产时,它只具有对业务重要的功能,但有时该应用程序的某些功能会过期(由于不同的原因),因此我们希望有一种方法来识别那。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
即使在生产环境中,至少有两个工具可以在您的应用程序中部署并收集一些统计信息:
AspectJ - 编织所有类并以某种方式记录每个方法的执行。
JaCoCo - 本质上做同样的事情,但自动Java 代理的帮助。执行的方法/分支(实际上,这是一个代码覆盖工具)保存在文件中以供将来处理。应该很容易解决你的问题。
这两种方法都应该适用于任何 JVM 语言(我看到 jruby 在你的问题中)因为它们在字节码级别上工作。我曾经在 Selenium 测试运行期间使用 JaCoCo 来测量代码覆盖率(想想:执行了哪些方法/分支)。
There are at least two tools you can deploy along your application and collect some statistics, even in production:
AspectJ - weave all classes and somehow log every method execution.
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.
例如,Intellij IDEA 具有静态分析功能,它将未调用的类型/方法的名称灰显。如果您需要自动工具,请尝试 声纳。我想,如果您以某种形式使用反射,这两种方法都会给出一些错误的结果。
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.
还有 PMD
顺便说一句,它可以作为不同 IDE 的插件安装
There is also PMD
btw it could be installed as a plugin for different IDEs
我还使用以下静态分析工具:
UCDetector(开源 Eclipse 插件) - 非常有帮助.
Structure101(商业软件)- 也可以用于此目的(例如查找未使用的类)。
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.
您可以使用 JArchitect 工具来分析您的代码并检测未使用的代码和功能,其中有一些功能:
You can use JArchitect tool to analyse your code and detect the unused code and functionnalities, there are some of it's functionnalities :