views:

407

answers:

6

I'm interested in code statistics tools. Specifically I need to get statistics on Java EE code, but any code analyzer would do. Should I start creating one of my own or is there some project that you have used?

ex. LOC, number of classes , libs ...

What is your experience ?

+2  A: 

I've already used Metrics Eclipse Plugin. It's outdated nowadays, but has a number of interesting metrics.

There's StateOfFlow too. It supports less metrics, but it seems it's not so outdated.

Jaú
+3  A: 

You can use JavaNCSS - A Source Measurement Suite for Java which supports some basic metrics (NCSS, # classes/packages/functions, CCN).

Then there is Sonar which supports some 20+ code metrics and Clover (where you even can define your own metrics with in a special language)

If that isn't enough for you can google for "java" and "metrics"

jitter
+1 for Sonar. Note that JavaNCSS has some troubles with Java 1.5+ projects, and that's why the Sonar team developed their own tool in replacement for JavaNCSS (this tool is called SonarSquid and is embended in Sonar since the version 1.9 if I am correct).
romaintaz
+1  A: 

One tool, which gathers quite niche statistics is Testability Explorer. It operates on Java byte code, providing stats for cyclomatic complexity, mutable global state and some other things. It's free and open-source under the Apache 2.0 license.

As I said it is very niche, and probably won't give metrics which are as easy to relate to as LOC. However, what's interesting is that you would be able to compare the projects you run it on against several well known open-source projects. This would perhaps make the results more useful.


Another tool which I recently used is SLOCCount. It's a command line tool designed to give statistics for many different languages, including Java. After failing to run JavaNCSS on a large codebase (it complained of too many files) I got this tool running no problem, for a very large codebase (IntelliJ IDEA). A nice feature is that it takes very little configurability, I didn't even have to tell it to look for *.java files, it recognised different languages automatically and reported on them.

The downside to SLOCCount is if you're running Windows - you'll have to use Cygwin to run it.

Grundlefleck
A: 

For eclipse you could try Emma (code coverage) and JDepend (design quality metrics)

rsp
+7  A: 

As explained by jitter, Sonar is definitively the tool that you are looking for. Note that this tool used JavaNCSS, but since the version 1.9, they have their own internal tool (called SonarSquid) that is really totally compatible with Java 1.5 or 1.6 projects.

alt text

In addition, you can monitor a complete set of projects.

You can access the Nemo demo instance to have a complete overview of the tool!

romaintaz
+1  A: 

The SD Java Metrics Tool provides SLOC, comment count, Halstead and Cyclomatic complexity numbers, down to the method level and for all rollups larger than that (method, class, file, directory, ...)

The SD Java Clone Doctor analyzes software systems for code duplication, and provides a complete list of detected clones, typically 10-20% in large software systems. You can see a clone detection report at the link.

The SD Source Code Search Engine indexes your source code base to provide lightning-fast searches across millions of lines of code. As a byproduct of indexing the source base, it produces file-level statistics for SLOC, comment count, Halstead and Cyclomatic numbers. It operates on Java, C#, and many other languages.

Ira Baxter