I neeed a free tool to count SLOC on a Java project. I only really need the following metrics:
- SLOC
- number of comment lines
- optionally javadoc metrics
- optionally sort statistics by file type (.java, .js, .css, .html, .xml, etc)
Bonus:
- 100% Java, I don't like mix something like sloccount with cygwin
- netbeans plugin
- or preferably, maven plugin
Did you consider using Sonar (which uses its own internal tool since version 1.9, sonar-squid, instead of JavaNCSS which has some flaws and doesn't work well with Java 1.5 or 1.6 projects)? This is the kind of report you'll get:
alt text http://sonar.codehaus.org/wp-content/uploads/2009/05/sonar-squid.jpg
Sonar does a lot more than just collecting SLOC though, maybe not what you want.
My advice is don't.
You get what you measure for.
If you reward big LOC, you'll get a lot of LOC.
If you reward small LOC, you'll get perl.
There is a maven plugin for JavaNCSS. There is also the JDepend plugin that generates some complexity metrics if you're interested in those.
Interestingly, the reason you're having trouble finding a decent plugin is because most people don't care enough to write one or don't find those metrics useful enough. Take that as you wish.
This is free (as in beer, not source sadly): http://www.campwoodsw.com/sourcemonitor.html
It's a bit rough around the edges, but does the job.
I used combination of RefactorIt browser and FreeMind (with some Groovy scripting) for semi-automatic generating of SLOC and Comments LOC metrics reports. RefactorIt can export metric in csv format, it is open source and pure Java. Unfortunately, it seems to be no longer developed. FreeMind is mind mapping software and I used it to generate mind map from that csv metrics report. I've done that mostly for fun, to be honest. You could build your solution upon these tools, though I doubt that it is the best way.
For an open source project, you can get SLOC measures as a side benefit of registering your project at http://ohloh.org
CodeFacts will give you line counts for the source and comments along with some stats on lines and class/method counts differences between two revisions. It's really a metrics tool though so it may be overkill for what you want.
If using NetBeans 8, download the TikiOne JaCoCoverage plugin and then run the code coverage test against your project. It will give you lines per package and total lines. It doesn't, however, differentiate between things like lines of code and lines of comments.
来源:https://stackoverflow.com/questions/2184999/sloc-for-java-projects