View Source

This example plugin analyzes [JavaNCSS|http://www.kclee.de/clemens/java/javancss/] report to count source and comment lines of your project and if comment to source ratio is under a specified threshold, it reports a build error. It also adds a pie chart to build overview page displaying source and comment lines, and adds a stack bar chart to statistics page to display trends of comment to source ratio over time.

Before diving into the source code, please follow below steps to see how this plugin works:
# Make sure [Apache Ant|http://ant.apache.org] is installed.
# Open the [plugin development workspace|set up plugin development workspace] and make sure the example project _com.example.javancss_ is imported into the workspace following [this guide|Plugin Examples].
# Download [this test project|^componentA.zip] and extract it to a directory, say _/path/to/componentA_.
# Start QuickBuild by running Eclipse configuration _Bootstrap_.
# Open the browser and point to _http://localhost:8810_ (or any other port you configured in _<QuickBuild install dir>/conf/node.properties_), select the _root_ configuration and switch to steps tab.
# Define the master step as a sequential composition step, and add below child steps into it:
#* A step of type _Build/Ant_. Give this step a name, and specify the property _Ant build file_ as _/path/to/componentA/build/build.xml_.
#* A step of type _Publish/JavaNCSS Report_. Give this step a name, and specify the property _JavaNCSS report path_ as _/path/to/componentA/build/metrics.xml_.
# Switch to page _Administration->Plugin Management_, and configure the Ant plugin to specify path to Ant executable if it is not in the system path.
# Run root configuration to build the test project. After the build finishes:
#* A pie chart will appear in the build overview screen displaying source and comment lines of the test project.
#* A build tab named "javancss" will appear. This tab is created only for demonstration purpose, and does not include any content.
#* Switch to dashboard, and hover mouse over _more..._ link of the newly generated build to bring up the build summary. The build summary will include source and comment line information. Clicking on this information will lead to javancss build tab.
# Switch to menu _Administration->Plugin Management_ and configure property _comment threshold_ of the JavaNCSS plugin as _20_. This tells QuickBuild to fail the build if comment to source ratio is less than 20%.
# Edit file _/path/to/componentA/src/com/example/componentA/ComponentA.java_ to remove all comments.
# Switch back to QuickBuild and run the root configuration again. The build will fail with a message _Source comments are less than 20%_.
# Edit file _/path/to/componentA/src/com/example/componentA/ComponentA.java_ to add comments, and run the root configuration again to generate a new build.
# Switch to menu _Statistics->JavaNCSS_, and you will see a stack bar chart displaying trends of source and comment lines for all builds.