There's also a very good static analysis tool called FindBugs that we're using to great effect in NetBeans. See http://findbugs.sourceforge.net/
On Nov 2, 2007 7:46 AM, John Embretsen <[EMAIL PROTECTED]> wrote: > Did you know there is a new tool in town that can detect CRAPpy Java code? > Are you interested in knowing more about Derby's code quality? Test coverage? > Code complexity? > > Well, I don't know if crap4j will help you much, but I just couldn't resist > trying it against the Derby code base... > > C.R.A.P. = "Change Risk Analyzer and Predictor", and is a "tool to help you > defend yourself against overly complex and untested code". > > The current formula for calculating CRAP is described at > http://www.artima.com/weblogs/viewpost.jsp?thread=215899 . In short, CRAP > measures the code complexity in your methods and runs your JUnit tests to > measure the test coverage of those methods. Test coverage can weigh up for > code > complexity, which means that complex methods with no test coverage get a high > CRAP number. > > crap4j is an open source Java implementation of such a tool, and there's a > prototype available at http://www.crap4j.org. It is available as an Ant task > or > an Eclipse plugin. I did a quick run of the Ant task using the attached > modifications to build.xml (your mileage may vary). > > The result was: > ---------------- > > Percentage of CRAPpy Methods 5.80 % > CRAP Load 23101 > Total Method Count 29300 > CRAPpy Method Count (CRAP > 30 ) 1698 > > > This crap4j run measured 5.80 % CRAPpy methods in Derby (trunk @ revision > 589902), which is just above the CRAP threshold of 5 %. Not bad ;) The HTML > reports include listings of methods sorted by CRAP, CRAP load, complexity and > coverage, but the files are quite big so I did not attach detailed results > here. > > Please note that this was just an experimental run of crap4j, which (for > example) assumed that all classes ending with "Test" in the classes/ directory > were Junit tests (which is not entirely true). > > I'm just posting this in case others find this interesting and want to try it > out. And because it's a Friday, a suitable day for viewing things from a > slightly different perspective than usual. > > > -- > John > > > > > Index: build.xml > =================================================================== > --- build.xml (revision 590043) > +++ build.xml (working copy) > @@ -34,6 +34,18 @@ > <property file="${properties.dir}/compilepath.properties"/> > <!-- Release and version info --> > <property file="${properties.dir}/release.properties"/> > + <!-- crap4j library location --> > + <property name="CRAP4J_HOME" value="${user.home}/lib/crap4j"/> > + > + <!-- Task definitions --> > + <!-- crap4j --> > + <taskdef name="crap4j" classname="org.crap4j.anttask.Crap4jAntTask" > > + <classpath> > + <fileset dir="${CRAP4J_HOME}/lib"> > + <include name="**/*.jar" /> > + </fileset> > + </classpath> > + </taskdef> > > <!-- Targets --> > > @@ -1889,6 +1901,35 @@ > > value="${derby.jar.base}/derbyTesting.jar:${derby.jar.base}/derbynet.jar:${derby.jar.base}/derbytools.jar:${derby.jar.base}/derbyclient.jar"/> > </target> > > - > + <!-- ================================================================ --> > + <!-- crap4j target (code analysis tool) --> > + <!-- ================================================================ --> > + <target name="run-crap4j"> > + <crap4j projectdir="${basedir}" > + outputDir="crap4j/reports" > + dontTest="false" debug="false"> > + <classDirs> > + <pathElement location="classes" /> > + </classDirs> > + <srcDirs> > + <pathElement location="java/client" /> > + <pathElement location="java/demo" /> > + <pathElement location="java/drda" /> > + <pathElement location="java/engine" /> > + <pathElement location="java/shared" /> > + <pathElement location="java/storeless" /> > + <pathElement location="java/tools" /> > + </srcDirs> > + <testClassDirs> > + <pathElement location="classes" /> > + </testClassDirs> > + <libClasspath> > + <fileset dir="tools/java"> > + <include name="junit.jar" /> > + </fileset> > + </libClasspath> > + </crap4j> > + </target> > > + > </project> > > > >
