Outputting xml would be a great feature, because it would then be a lot easier to actually reuse data outputted by coder.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zroger’s picture

Version: 6.x-2.0-beta1 » 6.x-2.x-dev
Status: Active » Needs review
FileSize
4.5 KB

Here is a patch that adds an additional drush command to output coder results in the checkstyle xml format. Checkstyle is a java utility for evaluating different coding standards, particularly targeted at java files. This utility is widely integrated into IDE's and CI environments, so using this output format makes a lot of sense.

Using the Hudson violations plugin with the output from this drush command, I am able to get really useful charts of coding standard violations, and even see the offending code in the browser. http://skitch.com/zroger/d3gea/hudson

About the new drush command... I wrote this as a separate command because the current command is tightly integrated with the main module code. I based the new command off of the coder test cases, since that method provides access to the results arrays rather than the formatted output.

$ drush help coder-checkstyle
Run a code review and output in checkstyle xml format.

Arguments:
 project               The drupal project to be checked. 

Options:
 --reviews             Comma separated list of coder reviews to run.       
                      Defaults to "recommended", which is an alias for    
                      style,comment,sql,security,i18n                     
 --severity            One of "minor", "normal" or "critical". Defaults to minor.           
moshe weitzman’s picture

Wow, this is awesome. Watching a demo now. Thanks Tree House.

rapsli’s picture

Status: Needs review » Reviewed & tested by the community

really cool. Patch works just fine.
Just haven't figured out yet, how to make the reports :( I'm not too familiar with maven and co

jsobiecki’s picture

FileSize
4.7 KB

Hi, This patch is very cool and works for me.

I think that one small addition to this patch would be helpful: possibility of specifying comma separated list of projects. I attached slighty modified version of this patch with this feature added.

dixon_’s picture

subscribing.

zroger’s picture

FileSize
4.68 KB

Here's a matching d7 patch for good measure ;)

Steven Merrill’s picture

... and the D7 patch needs a little more love, which is forthcoming shortly.

rapsli’s picture

is this getting into the module?

rapsli’s picture

@zroger I'm not quite sure how to use the options. Would you mind posting an example call using the options?

JvE’s picture

FileSize
10.82 KB

In the [#4] patch ".module" files are ignored.
The latest checkstyle_plugin for Jenkins (3.14) ignores "minor", "normal" and "critical" severity.
it expects "info", "warning" and "error".
I also had to add a callback to the $info before it worked at all in drush 4.

My 1st attempt at a patch tries to solve these.

JvE’s picture

Status: Reviewed & tested by the community » Needs work
FileSize
4.73 KB

Oh shoot. that file is no good.
attempt nr2..

JvE’s picture

Status: Needs work » Needs review
royjs’s picture

Seems to be an error in the patch
I think that line

results = _coder_drush_run_review($path, $review);

Should be

results = _coder_drush_run_review($path, $review, $severity);

Else the --severity argument is ignored

royjs’s picture

I'm using the output of the coder-checkstyle command in Jenkins and except a small problem that I noted in #13 it works for me so far.

Cyberwolf’s picture

Subscribing

stella’s picture

I'd like to see this added to coder, but not as a "coder-checkstyle" command. The option for xml output should be added to the existing "coder-review" command which supports additional options and can review patch files too.

stella’s picture

Status: Needs review » Patch (to be ported)

I added a modified version of this to the Drupal 7 version which adds support for xml output to the existing drush coder-review command.

I just need to backport it to Drupal 6.

royjs’s picture

I think it's a good idea to add it as an option for the coder-review command

pwolanin’s picture

If only java tools took JSON more readily...

stella’s picture

Status: Patch (to be ported) » Fixed

Committed to 6.x-2.x

kasperg’s picture

Is it the intent that this feature should output a general XML file or a Checkstyle XML report?

If the latter is the case I've found several differences when trying to integrate Coder Review into our Jenkins CI process with Checkstyle plugins:

  • Jenkins expects a <checkstyle> root element. The Coder Review XML output contains a <coderreview> root element. This difference causes the parsing of the report in Jenkins to fail.
  • As mentioned by #10 Jenkins expects the severity attribute for elements to be either "info", "warning" or "error". The Coder Review XML output uses severities "minor", "normal" and "critical". This difference causes Jenkins to rate all errors as medium priority.
  • Jenkins uses the source attribute to categorize error using categories and type based on a Namespace.Classname string such as Generic.PHP.LowerCaseConstant produced by PHP_Codesniffer. The Coder Review XML output uses the line containing the error as the source.

Whether or not these differences are actual errors depends on how you see it. I have not found any official Checkstyle report schema to validate the Coder Review XML output against. On the other hand other tools such as Jenkins and PHP_Codesniffer are clearly working with a different format than Coder Review.

JvE’s picture

Yeah, I noticed this too.
It's nice that there is xml output now, but it's useless for integration with jenkins & checkstyle

I'm using the attached patch in combination with the 7.x-1.0-beta6 release. My jenkins "coder" build step:

# Coder
# coder is already in svn, just needs patching to support xml
patch -f -p0 < ../coder_review_checkstyle.patch

# enable and run
$DRUSH pm-enable coder coder_review
for MODULE in time_entry time_widget superselect
do
  $DRUSH coder-review xml minor comment security sql style $MODULE > checkstyle-$MODULE-result.xml
done
kasperg’s picture

I use the 7.x-1.x release with patches here and here.

The build is orchestrated using Phing, the Drush task and filterchains to modify the Coder Review XML output as mentioned in #21.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

stella’s picture

Added in checkstyle option too in latest dev, both 6.x and 7.x versions.

royjs’s picture

The new checkstyle option works as expected and the files are valid in jenkins.
My problem is that I have some errors missing the message when using both the xml and the checkstyle options.

The error xml tag has a message property but its value is simply ""

Does anyone else have that problem ?

royjs’s picture

The parameter "warning" received in function "theme_drush_coder_warning" of file coder.drush.inc doesn't seem to always be the same. Sometimes $warning is a string and contains the message and sometimes it is an array and the message is in $warning['#warning']

patcon’s picture

Just wanted to say thanks to everyone who got this in. It's a rockin feature :)

patcon’s picture

[doublepost]