9

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 ?

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
Mite Mitreski
  • 3,596
  • 3
  • 29
  • 39

7 Answers7

12

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 http://sonar.codehaus.org/wp-content/uploads/2009/05/sonar-squid.jpg

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!

Romain Linsolas
  • 79,475
  • 49
  • 202
  • 273
  • 1
    This tool is overkill to solve the problem of OP. If you want to install a 3-tier web application on your dev machine which relies on a second tool to do the actual analyzing, and fiddle with at least two config files - then go ahead. If you simply want a tool to give you the three criterias OP listed (and more!) in 60 seconds, look to the answer of Marcelo. – Nilzor May 03 '13 at 09:05
  • @Nilzor I disagree. Sonar is really simple to use. Just download the zip, start it, and run an analysis. Of course, it provides a lot of information, many more than the ones that OP asked. Regarding the tools suggested by Marcelo, I fear that they are too old and may not be able to analyze correctly Java 1.5+ code (that happens with the JavaNCSS tool, which was not compatible with Java 1.5 for a long time) – Romain Linsolas May 03 '13 at 09:11
5

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.

mcrisc
  • 809
  • 1
  • 9
  • 19
  • StateOfFlow crashes when I export my project to a metrics report. "No typeinfo available package=(my package)". Issues that had been reported are ignored. The project is dead. – Name is carl Aug 28 '13 at 15:16
4

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
  • 53,475
  • 11
  • 111
  • 124
  • +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). – Romain Linsolas Nov 21 '09 at 11:16
3

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
  • 124,925
  • 25
  • 94
  • 111
3

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
  • 93,541
  • 22
  • 172
  • 341
2

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

rsp
  • 23,135
  • 6
  • 55
  • 69
2

You can try also JavaDepend,it provides more than 82 metrics, and CQL ( SQL like) to query code base make it flexible.

And the metric view give you visually a good idea of SLOC,Complexity and other ineresting metrics.

Metric View