XRadar provided you with 4 distinct Ant Task to have it running in your Ant's build:
XRadar does not analyse you code by itself, it relies on other products, (such as PMD, Checkstyle, CKJM,...) to do it. It only agregate the results and make its own results with those.
Your build may already using most of those tools, however, if not the case you can use a default script, placed inside the jar of xradar to have them running.
In this case, you just need to define a special Task, called the XRadarLoader to enable you to retrieve the script (and then run it) automatically. (You can also extract it once in for all from the jar).
<taskdef name="xradar-loader" classname="org.sourceforge.xradar.ant.RadarLoaderTask"> <classpath refid="tools.classpath"/> </taskdef> <!-- retrieving the tools.xml script --> <xradar-loader resource="xradar://scripts/${script}" target="${workdir}/tooling/${script}" /> <property name="javadoc.dir.name" value="javadoc"/> <!-- executing it --> <ant antfile="${workdir}/tooling/${script}"> <!-- please study the testproject to know more about thoses settings.... --> <property name="tools.lib" value="${tools.home}"/> <property name="target.javadoc" value="${docs.home}/${javadoc.dir.name}"/> <property name="java2html.root" value="${docs.home}/htmlcode"/> <property file="etc/${version.prefix}${version}.properties"/> <property file="etc/statics.properties"/> </ant>
Enable your build to run the agregation of your quality tools reports. Task is pretty much self documented, here is a sample:
<taskdef name="xradar-statics" classname="org.sourceforge.xradar.ant.StaticsTask"> <classpath refid="tools.classpath"/> </taskdef> <xradar-statics debug="false" properties="${properties-file}" config="etc/radar-config.xml" offline="true" target="${workdir}/" javadocEnabled="true" javadocRoot="../${javadoc.dir.name}" java2htmlRoot="htmlcode"> <report file="${docs.home}/xml/jdepend_report.xml" type="jdepend"/> <report file="${docs.home}/xml/cpd_report.xml" type="cpd"/> <report file="${docs.home}/xml/pmd_report.xml" type="pmd"/> <report file="${docs.home}/xml/javancss_report.xml" type="javancss"/> <report file="${docs.home}/xml/ckjm_report.xml" type="ckjm"/> <report file="${docs.home}/xml/depfind_report.xml" type="depfind"/> <report file="${docs.home}/xml/test_depfind_report.xml" type="test_depfind"/> <report file="${docs.home}/xml/checkstyle_report.xml" type="checkstyle"/> <report file="${docs.home}/xml/junit.xml" type="junit"/> <report file="${docs.home}/xml/cobertura.xml" type="cobertura"/> <report file="${docs.home}/xml/findbugs_report.xml" type="findbugs"/> <report file="${docs.home}/xml/cloc.xml" type="cloc"/> <report file="${docs.home}/xml/emma.xml" type="emma"/> </xradar-statics>
Once you'll have the statics task running for while,you'll probably wants to see how your code quality has been going (Is it improving or does this young developer who joined the team last week is missing around with it ?)
In order to do so, you can use the dynanic task, to generate the dynamics website, that agregates data from XRadar run on distinct versions of your project!
<taskdef name="xradar-dynamics" classname="org.sourceforge.xradar.ant.DynamicsTask"> <classpath refid="tools.classpath"/> </taskdef> <xradar-dynamics debug="false" config="etc/radar-config.xml" target="${docs.home}" staticsConfigured="true"> <input reportToMerge="release1/docs/xml/radar_report_normalized.xml" qualityReportPath="release1/docs/xml/reports/" versionId="1" daysSinceLast="1" staticsRoot="release1/docs" masterFinal="${docs.home}/xml/dynamics-master-final.xml"/> <input previousReport="${docs.home}/xml/dynamics-master-final.xml" reportToMerge="release2/docs/xml/radar_report_normalized.xml" qualityReportPath="release2/docs/xml/reports/" versionId="2" daysSinceLast="1" staticsRoot="release2/docs" masterFinal="${docs.home}/xml/dynamics-master-final.xml"/> <input previousReport="${docs.home}/xml/dynamics-master-final.xml" reportToMerge="release3/docs/xml/radar_report_normalized.xml" qualityReportPath="release3/docs/xml/reports/" versionId="3" daysSinceLast="1" staticsRoot="release3/docs" masterFinal="${docs.home}/xml/dynamics-master-final.xml"/> <input previousReport="${docs.home}/xml/dynamics-master-final.xml" reportToMerge="release4/docs/xml/radar_report_normalized.xml" qualityReportPath="release4/docs/xml/reports/" versionId="4" daysSinceLast="1" staticsRoot="release4/docs" masterFinal="${docs.home}/xml/dynamics-master-final.xml"/> </xradar-dynamics>
Obviously, setting up the dynamic part can be a little tricky... Please refer to the testproject to see exactly how to do it.
Once you'll have XRadar running smoothly, you'll probably want to have the build breaks if someones do something as nasty are creating an illegal dependency.
A new features of XRadar 1.1 only you to do so using a simple XPath query that will check if one of XRadar agregated results files contains something it shouldn't...
<xradar-analyser> <rule name="illegal-dependancy" type="xpath" query="//IntegratedAnalysis/Packages/Package/DependsUpon/Package[@legal='false']" file="${workdir}/xml/masterreport_final.xml"/> </xradar-analyser>
Note that the API is rather new. For now, you must code any query you wants, which require from you to take a look at the rather heavy and complex file XRadar is producing. Soon, you'll have already predefined rules, that will only require as little configuration as possible (probably just a name).
By the way, feel free to send us your own "analyser" :) !
Probably the easiest way to approach XRadar's Ant usage is to "play" with the testproject provided with XRadar.
In your console, go to the XRADAR_HOME directory and type:
XRADAR_HOME$ cd testproject XRADAR_HOME/testproject$ ant
On a modern computer, the task will take a few minutes ( 1 to 5), and should run successfully. If not, there is something wrong in the configuration (you should go back and see if there is something that you have forgotten).The script will build 4 test projects and analyse them all.
The XRadar Statics analysis of these projects can be found in XRADAR_HOME/release[1..4]/docs/index.html on your system. The XRadar Dynamics analysis for them all can be found in XRADAR_HOME/dynamics/docs/index.html. Enjoy!
After these initial steps, you may continue with the XRadar setup for your project through XRadar Statics Installation and XRadar Dynamics Installation.
We do recommend that you do try to install the Unit test and coverage features so that you can see the XRadar's full potentional, however, Cobertura is known to be quite buggy. Thankfully, now XRadar can also uses Emma reports.
If you want to integrate JUnit or JCoverage into the XRadar, that is possible as well. JUnit is the first thing recommend to integrate. The solution is fairly simple. From $XRADAR_HOME/testproject/lib, copy junit.jar over to the $ANT_HOME/lib directory.
Then, in a terminal, go to the $XRADAR_HOME/testproject directory and type:
# On windows export ANT_OPTS="-Dinclude.junit=true" $XRADAR_HOME\testproject$ ant # On *nix $XRADAR_HOME/testproject$ ant -Dinclude.junit=true
The system will now build the unit tests and run them against the testproject. A report will finally be formatted and integrated into the XRadar. The prosess will take some time, but afterwards, you will see unit test metrics in both XRadar reports.
After that, a more usefull move, would be either install Cobertura or Emma, in order to get some data how well your tests are covering your source codes.
Assuming you have done the necessary installion of junit as described in the previous section you are now ready to go. Go to the $XRADAR_HOME/testproject directory and type:
# On windows export ANT_OPTS="-Dinclude.junit=true -Dinclude.cobertura=true" $XRADAR_HOME\testproject$ ant # On *nix $XRADAR_HOME$/testproject ant -Dinclude.junit=true -Dinclude.cobertura=true
The system will now instument the classes of the testproject for coverage. The system will build the unit tests and run them agains the testproject. A junit-report and cobertura-report will finally be formatted and integrated into the XRadar.