Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 26 Next »

Name

Web Plugin

Authors

Matthijs Galesloot

Jira

http://jira.codehaus.org/browse/SONARPLUGINS/component/14423

Requires Sonar version

2.2 or higher (check version compatibility )

Latest version

0.1 (august 2010)

License

Apache 2.0

Sources

http://svn.codehaus.org/sonar-plugins/trunk/web/

Download

http://repository.codehaus.org/org/codehaus/sonar-plugins/sonar-web-plugin/0.1/sonar-web-plugin-0.1.jar

Features

The plugin provides static code analysis of web files within Sonar. Currently JSP and JSF are supported. Some initial support is provided for Ruby templating (erb files). 

The following metrics are supported:

  • sizing (files, lines of code)
  • rules compliancy
  • complexity
  • duplication
  • comments

The plugin scans the following files by default: .xhtml, .jspf, .jsp. The file extensions are configurable. 

The plugin imports the source code in Sonar, calculates measurements and scans the code for violations, duplications and complexity. The checks are configurable in the Sonar rules repository. 

Usage & Installation

Installation

  1. Copy the jar into /extensions/plugins/ directory
  2. Restart Sonar Web server

Analysis
Create a maven pom for your project. Set the following properties:

  • sonar.language: web
  • sonar.web.sourceDirectory: [folder of the web files]
  • sonar.dynamicAnalysis: false

Sample pom file:

Quick analysis
For an existing maven project, you might start an analysis by the following command:

Please note you can run sonar analysis for an artefact in only one language. So you cannot run a web analysis and a java analysis on the same maven project. The fix is to make a separate maven pom for the web project with a different name. 

Analysis

Rules

There are about 20 checks in the library. Please read the documentation of the checks on the page Web Rules Library.

The ruleset is inspired on the following standards and guidelines:

A complete explanation of the available checks is given here .

Complexity
Complexity of the web page is measured by counting the decision tags (such as if and forEach) and boolean operators in expressions ("&&" and "||"), plus one for the body of the document. It is a measure of the minimum number possible paths to render the page.

The decision tags and the operators are configurable. For details see rules library

Duplication
Duplication is counted by comparing nodes. Duplication is reported if more than a minimum amount of nodes are replicated (in the same file or another file). The default minimum tokens is set to 5.

Comments
Comments are counted by adding the lines for server side and client side comments.

Configuration

The following properties of the plugin are configurable:

property

default value

sonar.web.sourceDirectory

 

sonar.web.fileExtensions

xhtml,jspf,jsp

Plugin Architecture

The plugin uses a simple tokenizer to parse the web pages. The tokenizer is based on the sonar-channel library. The output of the tokenizer is analyzed by a set of analyzers and checks. Expressions written in the Unified Expression Language (EL) are validated with JBoss EL.

No further external tools or maven plugins are being used for analyzing the code.

Alpha Status and Testing

The plugin has alpha status: testing should focus on functionality and usability. Does the plugin deliver the required metrics? What is the quality of the rules library? What do you think of the complexity metric? 

An option could be to check out source code from an open source project and run the analysis on this project. Find below a few samples. You would need to create a simple pom file as described above and specify the property sonar.web.sourceDirectory as indicated. 

Seam in Action prototype

svn checkout http://seaminaction.googlecode.com/svn/trunk/prototype/projects/open18 seaminaction-open18

sonar.web.sourceDirectory = view

FacesGoodies

svn checkout http://facesgoodies.googlecode.com/svn/trunk facesgoodies

sonar.web.sourceDirectory = src/main/webapp

Alfresco

svn checkout http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/web-client alfresco-web-client

sonar.web.sourceDirectory = source/web

Changelog

Loading

Release 0.1 (5 issues)

Roadmap ideas

  • Run analysis directly from maven (without sonar)
  • More support for WCAG, webrichtlijnen
  • Enhanced validation of unified expressions (using JSFUnit?)
  • Dependency analysis
  • No labels