Running a code review from the command line

You can run code reviews on Java™ source code from the command line using analysis rules in a rules file that you created.

To run a code review from the command line, you must create a rules file.
Code reviews run from the command line operate an Eclipse environment in headless mode. You must specify the parameters required by the command-line analysis application, called com.ibm.xtools.analysis.commandline.AnalyzeApplication, when you run the code review. .

The headless mode reference topic Command line code review reference shows the options and corresponding parameters for the command line application. The parameters specify the scope of the analysis, the location of the source code, the rules to apply, and the location of the analysis results. The application can also write analysis results to stdout.

To run a code review from the command line:
  1. Open a command line interface (Microsoft® Windows® command prompt, or UNIX® or Linux® shell), and complete one of the following steps:
    • To run a code review on Java source code in an existing Eclipse workspace, type the following instruction at the prompt:
      <path to Eclipse executable file> -data <path to existing workspace> -application com.ibm.xtools.analysis.commandline.AnalyzeApplication
      -rulefile <path to rules file> -projects <name of Java project> -exportdirectory <path to results directory>
      -verbose
    • To run a code review on Java source code in a directory location that is not an Eclipse workspace, type the following instruction at the prompt:
      <path to Eclipse executable file>-data <path to temp workspace> -application com.ibm.xtools.analysis.commandline.AnalyzeApplication
      -rulefile <path to rules file> -directory <path to Java source code src directory> -exportdirectory <path to results directory>
      -verbose
  2. Press Enter to start the code review.
    Note: You can run the analysis using the Java launcher instead of the Eclipse executable file. To do so, replace the path to the Eclipse executable file with the path to the Java launhcer and a classpath option (-cp), whose argument points to the startup.jar file, and the org.eclipse.core.launcher.Main class. For example:
    <path to Java executable> -cp <path to Eclipse startup.jar> org.eclipse.core.launcher.Main 
    -data <path to temp workspace> -application com.ibm.xtools.analysis.commandline.AnalyzeApplication
    -rulefile <path to rules file> -directory <path to Java source code src directory> -exportdirectory <path to results directory>
    -verbose
Related concepts
Code reviews
Command line code review
Rules and rule categories
Related reference
Code review reference
Command line code review reference