English 中文(简体)
Getting code statistics from big projects
原标题:

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 ?

最佳回答

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!

问题回答

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.

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"

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.

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.

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

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





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签