|Java tools and libraries|
Hammurapi 5 Quick Start Guide
This document describes how to set up Hammurapi 5 and automatically review Java source code. Hammurapi 5 is a componentry for automated code reviews. As such this document is not a dogma but a guide to action which helps you make first steps toward implementing your code governance processes.
How it works
The bundle reviews Java source files in the directory specified in review.src property, which defaults to test. You set the property in the command line. See Hammurapi 5 Ant task documentation for more details.
If, for whatever reason, the bundle doesn't fit your needs, you can assemble your own solution from pieces as described in this section.
Hammurapi uses a relational database to store review results. The database initialization script is packaged in the Hammurapi jar file. In this example we will use the same HSQLDB database for storing parsed source files (Mesopotamia repository), and review results. There is a utility class to execute the script and create tables in HSQLDB server running on localhost on default port. If you are planning to use another database then you should extract the script (Hammurapi.sql) from the jar file and execute it in the target database console tool. Please note that SQL syntax might have to be adjusted for the target database.
Here is how to execute the InitDatabase utility class:
You should see output like this:
Reviews are executed by biz.hammurapi.review.Reviewer class. This class has main() method which allows to execute reviews. hammurapi.bat in Hammurapi distribution invokes this method. If you run this batch file without parameters it will print usage information and exit. In order to review code you have to provide the following parameters:
To review scan 0 with Java inspectors use the following command line:
Hammurapi 5 uses a web application to render review results. Web files are located in the web directory. Build a WAR file using buildwar.bat. Out of the box the web application uses direct JNDI reference to the datasource java:/HammurapiDS. Hammurapi distribution contains hammurapi-ds.xml datasource definition for JBoss. web.xml file contains commented out resource reference section. If you use JBoss all you need to do it to build a war file and then copy hammurapiweb.war and hammurapi-ds.xml to the deploy directory of JBoss. Then open http://localhost:8080/hammurapiweb/ URL in your browser. Make sure that hsqldb.jar in JBoss is of the same version as in Mesopotamia (1.8).
If you use some other application server or servlet container, you should create a datasource pointing to the Mesopotamia/Hammurapi database. You might have to modify the web.xml to adjust JNDI name of the datasource. You can also uncomment resource reference section in the web.xml file. Some application servers complain when a web application uses direct JNDI references.
Once you achieved basic review functionality you can rearrange Hammurapi code review components to meet your exact needs. For example:
If online reports are going to be accessed by many people, it is recommended to deploy a caching proxy server in front of the Hammurapi Web application.