Static program analysis is the analysis of computer software that is performed without actually executing programs (analysis performed on executing programs is known as dynamic analysis). In most cases the analysis is performed on some version of the source code, and in the other cases, some form of the object code.
Static analysis provides a low cost way of automating code review of certain types of source code errors and standards. Static code analysis, automated tests and code coverage are staples of the Continuous Integration process replacing manual effort with automation.
Full featured IDEs implement their own integrated static analysis and test measurement tools. IntelliJ comes with a comprehensive set of integrated static analysis tools and rules. It can run the rules in an incremental fashion updating results as code is edited. Rule violations are immediately reflected in the user interface.
CI servers and IDEs each have their own system from running code analysis, tests and test analysis. There are some times differences in the results generated by IDEs and build servers. This makes it hard for developers to reliably implement coding standards, pass static analysis and generate expected test results and coverage. IDE code quality extensions, or plugins, can run the CI tools inside the IDE so that developers can troubleshoot inconsistencies and predict results in the CI builds.
The above diagram shows a possible workflow where developers start with the integrated IDE tools. They then use IDE extensions to run the batch/CI automated tools. Finally the project code is then analyzed again by the CI build tools.
Example Static Analysis Plugins within IntelliJ
The next three videos walk through the installation and usage of several 3rd party IntelliJ plugins that let developers run standard Java static analysis and code coverage tools. We are really interested in
- Checkstyle: A code format and style tool.
- PMD: A static analysis tool
- Findbugs : A static analysis tool out of University of Maryland
- Clover: A test code coverage tool.
- Cobertura: A test code coverage tool.
- Emma: A test code coverage tool.
The following IntelliJ demos highlight Checkstyle, Findbugs and PMD.
This single unified plugin supports the running Checkstyle, Findbugs and PMD with custom configuration files. This means can use the same custom rulesets in IntelliJ that they use in a Hudson, Bamboo, TFS or other CI build.
QAPlug is run via the Analyze context menu available on a right mouse click. It is configured in the IntelliJ preferences screen and can be connected to one or more IntelliJ profiles
The video on the right walks through installation and usage of the Checkstyle and PMD module for this.
This single purpose plugin supports running Findbugs with custom rule files. It can share the same rule files used in a CI build. Findbugs-IDEA can be invoked via the "Findbugs" right mouse context menu.
The video at the right walks through installation and usage of the Findbugs plugin
This single purpose plugin supports running Checkstyle from the right mouse Analyze context menu. It can share Checkstyles with those used on the CI server.
The video at the right walks through installation and usage of the Checkstyle-IDEA IntelliJ extension.