How to use Checkstyle and Emma

Checkstyle

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. Maven-checkstyle plugin has been added into jcr/core/pom.xml. It checks our source code style according to java code (and some other) conventions. All the settings are default for now (there are just max line length changed, current:120, must be:80). All the checks are easy to configuring.

Usage

Go to jcr/trunk/component/core, run

mvn checkstyle:checkstyle
command. Go to target/site and open checkstyle.html. I recommend to open this big file (approximately 8M) with FireFox browser, other browsers are some slower. Enjoy.

Configuration

Checkstyle configuration file is placed in jcr/trunk/component/core/src/test/resources/exo-checkstyle-checker.xml See pom.xml,

...
  <report>
...
section for details. There are many checks within tag in exo-checkstyle-checker.xml. For example, module
<module name="LineLength">
         <property name="max" value="120"/>
         <property name="severity" value="warning"/>
</module>
checks for line length. If the length of some string of file is more than 120 symols, the corresponding warning will be in the checkstyle report file. By default if checkstyle plugin will find some mismatches, there will be corresponding error in the checkstyle report file. You may exclude some checks (naming ) also, e.g if in the configuration file has not tag, then verification of the length of a line will be ignored. You may exclude some classes from the file list for checking with suppresion-filter. Maven checkstyle plugin details. There is link with description of a check within the configuration file also. Other features If there will not any checks configured, default checks will be run (within plugin jar file). If report will no contain any error the source code will be ideal :)

Emma

Emma is a free open source tool for code coverage statistics. I think Emma is the best open source tool for these purposes. We are using Emma to know how fully tests are covering our code.

Usage

  1. Update maven-surefire-plugin version, replace
<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.0</version>
with
<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.3</version>
2.Uncomment system properties
...
<!-- systemProperties>
    	<property>
    	  <name>test.repository</name>
          <value>db1</value>
       	</property>
...
3. To run eXo tests uncomment the following tags within maven-antrun-plugin
...
<!-- execution>
  <id>0</id>
...
and
...
<!-- execution>
  <id>2</id>
...
4. To run TCK tests uncomment the following tag within maven-antrun-plugin too:
<!-- execution>
  <id>1</id>
...
4.1 Make sure you have excluded initialization section from maven-surefire-plugin
...
<includes>
  <include>**/init/TestAll.java</include>
...
5.Go to jcr/trunk/component/core and run
mvn -Dexo.test.skip=false clean test
command.

Emma is turned off by default. Phases of tests executing:

  • Tests compilation.
  • Instrumentation of generated classes by Emma . There are some classes excluded from instrumentation path because they are not contain debug info.
  • Tests running by surefire plugin. If you are running TCK tests make sure you have test data, tag
<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
    <executions>
...
      <execution>
        <id>1</id>
...
should be commented.

  • Emma report generation.
Process of tests running with Emma takes 10-40 seconds longer than without it. If you are do not like to use Emma , comment
<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
    <executions>
...
      <execution>
        <id>0</id>
...
      <execution>
        <id>2</id>
...
tags.

Emma are currently running with maven-surefire-plugin 2.3, but this plugin has a bug (nested classes prb)

Run

mvn -Dexo.test.skip=false clean test checkstyle:checkstyle
command to use both Emma and Checkstyle.

Tags:
Created by Vitaliy Obmanyuk on 07/23/2007
Last modified by Vitaliy Obmanyuk on 08/08/2007

Products

generated on Thu Sep 02 15:26:38 UTC 2010

eXo Optional Modules

eXo Core Foundations


Copyright (c) 2000-2010. All Rights Reserved - eXo platform SAS
2.4.30451