`

11款用于优化、分析源代码的Java工具

    博客分类:
  • Java
阅读更多

Below is a list of some tools that can help you examine your Java source code for potential problems:

1. PMD from http://pmd.sourceforge.net/
License: PMD is licensed under a “BSD-style” license

PMD scans Java source code and looks for potential problems like:

* Possible bugs – empty try/catch/finally/switch statements
* Dead code – unused local variables, parameters and private methods
* Suboptimal code – wasteful String/StringBuffer usage
* Overcomplicated expressions – unnecessary if statements, for loops that could be while loops
* Duplicate code – copied/pasted code means copied/pasted bugs

You can download everything from here, and you can get an overview of all the rules at the rulesets index page.

PMD is integrated with JDeveloper, Eclipse, JEdit, JBuilder, BlueJ, CodeGuide, NetBeans/Sun Java Studio Enterprise/Creator, IntelliJ IDEA, TextPad, Maven, Ant, Gel, JCreator, and Emacs.

PMD能够扫描Java 源代码,查找类似以下的潜在问题:

可能的bug——try/catch/finally/switch语句中返回空值。

死代码——未使用的局部变量、参数、私有方法。

不理想的代码——使用String/StringBuffer。

过于复杂的表达式——没有必要使用if语句、while循环可以代替for循环。

重复代码——复制/粘贴的代码引发的bug。

PMD集成了JDeveloper, Eclipse, JEdit, JBuilder, BlueJ, CodeGuide, NetBeans/Sun Java Studio Enterprise/Creator, IntelliJ IDEA, TextPad, Maven, Ant, Gel, JCreator, 以及 Emacs。

 

2. FindBug from http://findbugs.sourceforge.net
License: L-GPL

FindBugs, a program which uses static analysis to look for bugs in Java code. And since this is a project from my alumni university (IEEE – University of Maryland, College Park – Bill Pugh) , I have to definitely add this contribution to this list.

FindBug是一个使用静态方法来查找Java代码漏洞的程序。

3. Clover from http://www.cenqua.com/clover/
License: Free for Open Source (more like a GPL)

Measures statement, method, and branch coverage and has XML, HTML, and GUI reporting. and comprehensive plug-ins for major IDEs.

* Improve Test Quality
* Increase Testing Productivity
* Keep Team on Track

Fully integrated plugins for NetBeans, Eclipse , IntelliJ IDEA, JBuilder and JDeveloper. These plugins allow you to measure and inspect coverage results without leaving the IDE.
Seamless Integration with projects using Apache Ant and Maven. * Easy integration into legacy build systems with command line interface and API.
Fast, accurate, configurable, detailed coverage reporting of Method, Statement, and Branch coverage.
Rich reporting in HTML, PDF, XML or a Swing GUI
Precise control over the coverage gathering with source-level filtering.
Historical charting of code coverage and other metrics.
Fully compatible with JUnit 3.x & 4.x, TestNG, JTiger and other testing frameworks. Can also be used with manual, functional or integration testing.

这个插件允许你在不离开IDE的环境条件下来衡量和检测覆盖效果。该插件通过使用Apache Ant、Maven来无缝集成其它项目,可以通过命令行界面和API系统轻松集成到传统的构建系统中。

 

该插件的特性:

支持快速、准确、可配置的方法,语句等。

支持丰富的报告格式:HTML、PDF、XML、以及Swing GUI。

精确控制源代码级别的过滤。

支持代码覆盖以及其它指标的图表。

完全兼容JUnit 3.x & 4.x, TestNG, JTiger以及其它的测试框架。

 

4. Macker from http://innig.net/macker/
License: GPL

Macker is a build-time architectural rule checking utility for Java developers. It’s meant to model the architectural ideals programmers always dream up for their projects, and then break — it helps keep code clean and consistent. You can tailor a rules file to suit a specific project’s structure, or write some general “good practice” rules for your code. Macker doesn’t try to shove anybody else’s rules down your throat; it’s flexible, and writing a rules file is part of the development process for each unique project.

Macker是一个适用于Java开发人员用来检查架构规则的工具。你可以定制一个适合特定项目架构的规则文件,也可以为您的代码撰写通用的规则说明。

5 EMMA from http://emma.sourceforge.net/
License: EMMA is distributed under the terms of Common Public License v1.0 and is thus free for both open-source and commercial development.

Reports on class, method, basic block, and line coverage (text, HTML, and XML).

EMMA can instrument classes for coverage either offline (before they are loaded) or on the fly (using an instrumenting application classloader).

Supported coverage types: class, method, line, basic block. EMMA can detect when a single source code line is covered only partially.

Coverage stats are aggregated at method, class, package, and “all classes” levels.

Output report types: plain text, HTML, XML. All report types support drill-down, to a user-controlled detail depth. The HTML report supports source code linking.

Output reports can highlight items with coverage levels below user-provided thresholds.

Coverage data obtained in different instrumentation or test runs can be merged together.

EMMA does not require access to the source code and degrades gracefully with decreasing amount of debug information available in the input classes.

EMMA can instrument individial .class files or entire .jars (in place, if desired). Efficient coverage subset filtering is possible, too.

Makefile and ANT build integration are supported on equal footing.

EMMA is quite fast: the runtime overhead of added instrumentation is small (5-20%) and the bytecode instrumentor itself is very fast (mostly limited by file I/O speed). Memory overhead is a few hundred bytes per Java class.

EMMA is 100% pure Java, has no external library dependencies, and works in any Java 2 JVM (even 1.2.x).

EMMA支持的覆盖类型:方法、类等。

输出报告的格式为:文本、HTML、XML。

输出报告可以高亮显示某些项目。

EMMA不需要访问源代码,可以在输入类中减少调试的信息。

 

6. XRadar from http://xradar.sourceforge.net/
License: BSD (me thinks)

The XRadar is an open extensible code report tool currently supporting all Java based systems. The batch-processing framework produces HTML/SVG reports of the systems current state and the development over time – all presented in sexy tables and graphs.

The XRadar gives measurements on standard software metrics such as package metrics and dependencies, code size and complexity, code duplications, coding violations and code-style violations.

XRadar是一个开放的、为代码生成可扩展报告的工具。目前支持基于Java的所有系统。批量处理的框架可以用来生成HTML/SVG系统的报告。Xradar可以估量代码的大小、复杂性以及代码的重复性、依赖性等。

7. Hammurapi from Hammurapi Group
License: (if anyone knows the license for this email me Venkatt.Guhesan at Y! dot com)

Hammurapi is a tool for execution of automated inspection of Java program code. Following the example of 282 rules of Hammurabi’s code, we are offered over 120 Java classes, the so-called inspectors, which can, at three levels (source code, packages, repository of Java files), state whether the analysed source code contains violations of commonly accepted standards of coding.

Relevant Links:

http://en.sdjournal.org/products/articleInfo/93

http://wiki.hammurapi.biz/index.php?title=Hammurapi_4_Quick_Start

Hammurapi是一款执行Java程序代码的自动检测工具。提供的实例中含有282条Hammurapi代码规则,提供了120多个Java类,这款所谓的检测工具,可以从三个级别来检测代码是否违背了编码标准。

8. Relief from http://www.workingfrog.org/
License: GPL

Relief is a design tool providing a new look on Java projects. Relying on our ability to deal with real objects by examining their shape, size or relative place in space it gives a “physical” view on java packages, types and fields and their relationships, making them easier to handle.

Relif是一款设计工具,为Java项目提供了崭新的面貌。我们可以充分发挥自己的能力来处理真实的实例——通过检测大小、形状、关系等来简化处理过程。

9. Hudson from http://hudson-ci.org/
License: MIT

Hudson is a continuous integration (CI) tool written in Java, which runs in a servlet container, such as Apache Tomcat or the GlassFish application server. It supports SCM tools including CVS, Subversion, Git and Clearcase and can execute Apache Ant and Apache Maven based projects, as well as arbitrary shell scripts and Windows batch commands.

Hudson 是一个持续集成工具,使用Java编写,运行在servlet容器中,比如Apache Tomcat或者或GlassFish应用服务器。它支持SCM工具,包括CVS、Subversion、Git和ClearCase。它可以执行 Apache Ant、基于Apache Maven的项目、以及任意的shell脚本和 Windows批处理命令。

10. Cobertura from http://cobertura.sourceforge.net/
License: GNU GPL

Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage.

Cobertura是一个免费的基于jcoverage的Java工具,用于计算代码被测试访问的百分比,它可以被用来确定Java程序中的缺少部分的测试覆盖率。

11. SonarSource from http://www.sonarsource.org/ (recommended by Vishwanath Krishnamurthi – thanks)
License: LGPL

Sonar is an open platform to manage code quality. As such, it covers the 7 axes of code quality:

Architecture & Design, Duplications, Unit Tests, Complexity, Potential bugs, Coding rules, Comments.

Sonar是一个管理代码质量的开放平台。因此,它涵盖了代码质量的7个方面:架构与设计、重复、单元测试、复杂性、潜在错误、编码规则、评论。

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics