This example plugin analyzes 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 is installed.
- Open the plugin development workspace and make sure the example project com.example.javancss is imported into the workspace following this guide.
- Download this test project 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.