Login required
Download

CodeNarc Plugin

(3)
Author(s): Chris Mair
Current Release: 0.5
Grails Version: ?
Tags code metrics quality
grails install-plugin codenarc

CodeNarc Plugin

The CodeNarc Plugin provides static code analysis for Groovy code. It uses the CodeNarc library.

Installation

To integrate the plugin into your application just run the 'install-plugin' Grails script, e.g.

grails install-plugin codenarc

Usage

The plugin provides a script 'codenarc' that will analyze your code and write its results to an HTML file. Run

grails codenarc
to perform the analysis.

Customization

The plugin requires no customization to run. By default it will analyze all Groovy files in

  • src/groovy
  • grails-app/controllers
  • grails-app/domain
  • grails-app/services
  • grails-app/taglib
  • grails-app/utils
  • test/unit
  • test/integration
and use a default title and report name. You can restrict which folders are included or add extra ones. The (optional) "codenarc.properties" file can be located in the project base directory. Custom ruleset files can be located in the project base directory, or can be referenced by a path relative to that. The following table lists settings that will be read from grails-app/Config.groovy and used if available:

PropertyDefault ValueMeaning
codenarc.reportName'CodeNarcReport.html'the name of the analysis report file
codenarc.reportType'html'the report type; valid values are 'html', 'xml' and 'text', or the fully-qualified class name of a ReportWriter class
codenarc.reportTitlenonethe report title
codenarc.maxPriority1Violationsunlimitedthe maximum number of Priority 1 violations allowed; more than this value fails the build
codenarc.maxPriority2Violationsunlimitedthe maximum number of Priority 2 violations allowed; more than this value fails the build
codenarc.maxPriority3Violationsunlimitedthe maximum number of Priority 3 violations allowed; more than this value fails the build
codenarc.ruleSetFiles'rulesets/basic.xml,rulesets/exceptions.xml, rulesets/imports.xml,rulesets/grails.xml, rulesets/unused.xml'a comma-delimited list of rule file names
codenarc.processSrcGroovytruewhether to analyze source in src/groovy
codenarc.processControllerstruewhether to analyze source in grails-app/controllers
codenarc.processDomaintruewhether to analyze source in grails-app/domain
codenarc.processServicestruewhether to analyze source in grails-app/services
codenarc.processTaglibtruewhether to analyze source in grails-app/taglib
codenarc.processTestUnittruewhether to analyze source in test/unit
codenarc.processTestIntegrationtruewhether to analyze source in test/integration
codenarc.extraIncludeDirsnoneextra source directories to include; for example to include Quartz job files, specify
codenarc.extraIncludeDirs=['grails-app/jobs']
to add the pattern 'grails-app/jobs//*.groovy' to the analysis fileset

See http://codenarc.sourceforge.net/index.html for more information on CodeNarc configuration options.

Author

Chris Mair chrismair@users.sourceforge.net

(Original: Burt Beckwith burt@burtbeckwith.com)

Please report any issues to the Grails User mailing list and/or write up an issue in JIRA at http://jira.codehaus.org/browse/GRAILSPLUGINS under the Grails-CodeNarc component.

License

Licensed under the Apache License, Version 2.0. See http://www.apache.org/licenses/LICENSE-2.0.

History

  • February 3, 2010
    • Release version 0.5
      • Upgrade to CodeNarc 0.8.1 (bug fixes).
  • January 19, 2010
    • Release version 0.4
      • Upgrade to CodeNarc 0.8. This includes XML and Text report formats (beta), a new NestedBlockDepthRule, enhancement of the applyToFileNames rule property to handle optional path (e.g. “abc/def/MyClass.groovy”).
  • August 26, 2009
    • Released version 0.3
      • Upgrade to CodeNarc 0.7. This includes support for optionally prefixing ruleset file paths with "file:" to indicate a relative or absolute path in the filesystem rather than (the default of) being relative to the classpath.
  • July 18, 2009
    • Released version 0.2
      • Add “Unused” ruleset to default rulesets.
      • Upgrade to CodeNarc 0.6.
      • Include “test” folders in analysis; add codenarc.processTestUnit and codenarc.processTestIntegration properties in Config.groovy.
      • Rename default report file to “CodeNarcReport.html”.
      • Update author and authorEmail fields in CodenarcGrailsPlugin. (Original=Burt Beckwith).
      • Create automated test for CodeNarc plugin.
  • May 25, 2009
    • released initial version 0.1