Running code reviews from a command line

You can run code reviews in a "headless" workbench (with no user interface for the development environment) from a command line interface. The code review rules that run on the source code are the ones that were last used in the user interface. If a code review has never been run, the default settings in the Java preferences – Code Review page (the Quick code review) run on the code. By default, after the code review runs, two reports are generated: an HTML report and a JSML (JScrib Markup Language) report. They are located in the metadata folder of the workspace in the com.ibm.r2a.command.line.mode folder. You can specify which type of report is generated and the location in which the reports appear after the code review runs.

Note: You can run code reviews in headless mode only on the workspace. If you want to analyze a subset of the workspace, such as one or more specific projects, create a workspace with these projects and run the code review on this workspace.
Before running code reviews in headless mode: The development environment does not need to be running.

You cannot run several executions of code review in headless mode on the same workspace at the same time, nor can you use headless mode while an Eclipse graphical user interface has locked the workspace.

Note: Because of Windows operating system limitations, the length of the string that is used to run the command line mode (C:\path\java.exe …) must be as short as possible, or the parameters at the end of the string could be cut and lost by the system. Windows users should use the following best practices for optimal results:
  • The PATH variable should include as many paths as possible, for example, the Java path and the path to the JAR files.
  • The path to the workspace should be as short as possible, for example, C:\workspace.
  • The path to the location where reports are generated should also be as short as possible, for example, C:\report.
To run code reviews in a headless workbench, you launch the command line mode application using the command <eclipse_dir>/jre/bin/java <virtual machine options> -cp <eclipse_dir>/startup.jar org.eclipse.core.launcher.Main <command line mode options> <eclipse options>, along with your product configuration. You can find your product configuration at Help > About > Configuration Details > System properties. <virtual machine options> are located under the eclipse.vmargs property. The main Eclipse options are located under the eclipse.commands property, to which you add the workspace path using the Eclipse token -data. <command line mode options> refers to command-line mode options.
Note: You might need to append additional parameters to the commands in the following steps, depending on your operating system configuration. The parameters are located in the system configuration details under "System properties".
To run a code review in a headless workbench:
  1. Open a command line window or shell.
    • For Windows, enter the following command: <eclipse_dir>/jre/bin/java -Xj9 -Dorg.eclipse.swt.browser.internal.flash -Dorg.eclipse.emf.ecore.EPackage.Registry.INSTANCE=org.eclipse.emf.ecore.impl.EPackageRegistryImpl -cp <eclipse_dir>/startup.jar org.eclipse.core.launcher.Main -application com.ibm.r2a.command.line.mode.CommandLineModeApplication -plugincustomization <pluginCustomizationPath> -data <workspace_dir> -reportDirectory <your_report_directory> -onlyClient CodeReview
    • For Linux, enter the following command: <eclipse_dir>/jre/bin/java -Xj9 -Dorg.eclipse.swt.browser.internal.flash -Dorg.eclipse.emf.ecore.EPackage.Registry.INSTANCE=org.eclipse.emf.ecore.impl.EPackageRegistryImpl -cp <eclipse_dir>/startup.jar org.eclipse.core.launcher.Main -application com.ibm.r2a.command.line.mode.CommandLineModeApplication -os linux -ws gtk -plugincustomization <pluginCustomizationPath> -data <workspace_dir> -reportDirectory <your_report_directory> -onlyClient CodeReview
    Replace <eclipse_dir> with the path to the Eclipse directory. This Eclipse directory must be the Eclipse directory located in the project root directory. Replace <workspace_dir> with the path to the workspace directory. Replace <pluginCustomizationPath> with the path of your pluginCustomization.ini file. Add any additional options to the end of the command line. For information about optional parameters, see the related reference topic for code review headless mode. In these commands:
    • -Xj9 –Dorg.eclipse.swt.browser.internal.flash - Dorg.eclipse.emf.ecore.EPackage.Registry.INSTANCE=org.eclipse.emf.ecore.impl.EPackageRegistryImpl corresponds to the virtual machine arguments that are required by RASD products.
    • -data <workspace_dir> -plugincustomization <pluginCustomizationPath> corresponds to the required Eclipse arguments.
    • The other arguments are related to the application for command-line mode.
    Use double quotes when the path contains spaces. If you are using Windows, use double backslashes (\\) instead of the backslash character. Here is an example: "C:\\Program Files\\IBM\\Rational\\".
  2. Press Enter.
The results of the code review are generated in a report directory located in the workspace.
Related concepts
Code reviews run in headless mode
Related reference
Code review headless mode reference
Quick code review
Feedback
(C) Copyright IBM Corporation 2004, 2005. All Rights Reserved.