开发者

How to obtain dependency metrics from Java source code?

For an assignment we have to extract some software metrics from the Hibernate project. We have to extract the afferent coupling and efferent coupling metrics (dependency fan-in, fan-out) from each revision of each package in Hibernate. Some tools were provided which are able to extract these metrics, such as ckjm and JDepend. Other tools I have checked were Sonar, javancss and AOP. There is开发者_StackOverflow社区 also the Metrics Eclipse plugin which I didn't get to work either.

What these tools have in common, as far as I can see, is that they all operate on bytecode (*.class files). This is a problem, because I have to build every revision from source in order to run, say, JDepend on it. Older revisions won't build because my development stack is too recent. What I would like to do is to do this kind of analysis on source files so that I don't have to build each revision. Is this possible? Or is there a good reason why all these tools only operate on bytecode?


Try this: http://sourceforge.net/projects/hibernate/files/hibernate3/

You can download the Jar files for numerous old revisions here.

The reason these tools work on bytecodes is generally because it's simpler to write a bytecode parser than a full source code parser, plus it also allows you to cover 3rd party libraries where you don't have the source.


We found that cccc is capable of gathering metrics on source code (LOC, McCabe's complexity, CK and HK). Perhaps it works on simple project, but running this over all Hibernate code resulted in a large amount of parse errors. Moreover, it stops with a segmentation fault in the end, leaving us with an incomplete report.

In the end, we resorted to write our own script which processes the files to gather the necessary information. It's not water-proof, since it does not actually parse Java but just looks for certain patterns, but it's good enough for now.


Many tools operate on class file bytecodes, because (as other answers have pointed out), it is much easier to write a class-file parser than to actually parse full Java.

Our DMS Software Reengineering Toolkit and its Java Front End can parse and name-resolve Java through 1.6. (It parses 1.7 but doesn't name resolve some very dark corners, to be implemented Very Soon). This provides a full AST and symbol tables. The DMS machinery will let you visit/inspect the ASTs and symbol tables.

DMS will process many source files at once, so you can compute your metrics across multiple files with this data.


You can try the trial version of JavaDepend, it will be sufficient for your needs, it calculate efferent coupling, afferent coupling and many other useful metrics.


Check out Sonar. It's an open-source, stand-alone, web service that you "submit" your code to and it produces beautiful HTML reports on all kinds of code metrics. It also keeps a history of builds. And best of all, you don't have to modify your builds or poms!

There is a maven goal for it too: sonar:sonar. Jenkins (previously Hudson) has a plugin for it, so it's totally painless if you use that for your CI.

Check it out - you won't be sorry!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜