Rational Developer for System z

Running the sample script

The sample script provides a working example of how to invoke the code review application from the Linux or Windows command line.

About the sample script

The sample script gathers code review parameters from the command line, invokes the code review application with those values, and writes the output from the application to an output file. The script provides a level of error handling by checking for required parameters and displaying an error message when one is missing.

The version of the sample script appropriate for your operating system resides in the bin subdirectory of the product install directory:
  • For Linux: install/bin/codereviewbatch.sh
  • For Windows: install\bin\codereviewbatch.bat
where install is the product install directory.

The contents of the Linux and Windows sample scripts are shown in later subtopics.

Running the sample script

To run the sample script:
  1. Export rule information from the analysis configuration editor to create a rule file.
  2. Set up directories, data files, and source code files to use as parameter values.
  3. Open a command console.
  4. Run the script by entering a command on a single line. An example:
    codereviewbatch 
         -workspace c:\ws\workspace_0001  
         -rulefile c:\rf\rule_file.dat 
         -exportdir c:\cobol_export_file
         -directory c:\source_code  
         -includefile c:\rf\include_file
         -outputfile c:\tm\output_information
         -debug

Script syntax

The syntax of the sample script is as follows. Brackets indicate optional parameters:

codereviewbatch
     -workspace ws_location  -rulefile rule_file
     -exportdir exp_location  [-directory dirs]  [-projects projs]
     [-includefile in_file]  [-excludefile ex_file]
     [-outputfile out_file]  [-debug]


where:
   -workspace ws_location is the file path of the Eclipse workspace that you want to use.

   -rulefile rule_file is a .dat file containing a set of rules that you have exported from the analysis configuration editor.

   -exportdir exp_location is the directory where output data files are written.

   -directory dirs is a comma-separated list of directories containing source files.

   -projects projs is a comma-separated list of projects in the workspace that contain source files.

   -includefile in_file is a text file containing a list of source files to include in the code review.

   -excludefile ex_file is a text file containing a list of source files to exclude from  the code review.

   -outputfile out_file is the target file for output information.

   -debug prints output information to the console.

Linux script

The following block of code shows the Linux script:

Figure 1. codereviewbatch.sh
#!/bin/sh
#############################################################################
#                                                                           #
# IBM Rational Developer for System z 5724-T07                              #
#                                                                           #
# Copyright IBM Corp. 2012 All rights reserved.                             #
# All rights reserved.  US Government Users Restricted Rights -             #
# Use, duplication or disclosure restricted by GSA ADP Schedule Contract    #
# with IBM Corp.                                                            #
#                                                                           #
#############################################################################

usage()
{
  echo
  echo "codereviewbatch -workspace ws_location -rulefile rule_file" 
  echo "    -exportdir exp_location [-directory dirs] [-projects projs]"
  echo "    [-includefile in_file] [-excludefile ex_file] [-outputfile out_file]"
  echo
  echo "  ws_location   The workspace location"
  echo "  rule_file     The file containing exported rules to be executed"
  echo "  exp_location  The directory where data files are written"
  echo "  dirs          Comma-separated directories containing source"
  echo "  projs         Comma-separated workspace projects containing source"
  echo "  in_file       File containing list of files to include in analysis"
  echo "  ex_file       File containing list of files to exclude from analysis"
  echo "  out_file      Target file for command output"
  echo
  echo Use -debug to print command output to the console.
  echo   
  echo "The correct usage of this tool is described in the on-line documentation"
  echo "for Rational Developer for System z."
  return
}

rdz_install_dir=@RDZINSTALLDIR@

# supply defaults if desired
workspace=
rulefile=
exportdir=
directory=
projects=
includefile=
excludefile=
outputfile=
debug=

# process parameters
while [ $# -gt 0 ]
do
  case "$1" in
    -workspace ) workspace=$2; shift 2;;
    -rulefile ) rulefile=$2; shift 2;;
    -exportdir ) exportdir=$2; shift 2;;
    -directory ) directory=$2; shift 2;;
    -projects ) projects=$2; shift 2;;
    -includefile ) includefile=$2; shift 2;;
    -excludefile ) excludefile=$2; shift 2;;
    -outputfile ) outputfile=$2; shift 2;;
    -debug ) debug="true"; shift 1;;
    # unknown parameter
    * ) echo "Ignoring parameter: $1"; shift 1;;
  esac
done
  
# workspace, rulefile, exportdir are mandatory
if [ "$workspace" == "" ]
then 
  echo "-workspace parameter is mandatory"; usage
elif [ "$rulefile" == "" ] 
then
  echo "-rulefile parameter is mandatory"; usage
elif [ "$exportdir" == "" ] 
then
  echo "-exportdir parameter is mandatory"; usage
else
  # construct parameters and command
  ap_parm="-application com.ibm.rsaz.analysis.commandline.AnalyzeApplication"
  ws_parm="-data $workspace"
  rf_parm="-rulefile $rulefile"
  exp_parm="-exportdirectory $exportdir"
  dir_parm=
  if [ "$directory" != "" ]
  then
    dir_parm="-directory $directory"
  fi
  proj_parm=
  if [ "$projects" != "" ]
  then
    proj_parm="-projects $projects"
  fi
  in_parm=
  if [ "$includefile" != "" ]
  then
    in_parm="-includefile $includefile"
  fi
  ex_parm=
  if [ "$excludefile" != "" ]
  then
    ex_parm="-excludefile $excludefile"
  fi
  command="""$rdz_install_dir/eclipse"" $ap_parm $ws_parm $rf_parm $dir_parm $proj_parm $in_parm $ex_parm $exp_parm -verbose -nosplash"

  # run command
  echo "Running software analysis..."
  echo $command
  if [ "$outputfile" != "" ]
  then
    $command > $outputfile
    if [ "$debug" == "true" ]
    then
      cat $outputfile
    fi
  else
    $command
  fi
fi

Windows script

The following block of code shows the Windows script:

Figure 2. codereviewbatch.bat
@setlocal
@echo off

:: ============================================================================
::  IBM Rational Developer for System z 5724-T07
:: 
::  Copyright IBM Corp. 2012 All rights reserved.
::  All rights reserved. US Government Users Restricted Rights - 
::  Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
::  IBM Corp.
:: ============================================================================

set rdz_install_dir=@RDZINSTALLDIR@

:: supply defaults if desired; use quotes around paths containing spaces
set workspace=
set rulefile=
set exportdir=
set directory=
set projects=
set includefile=
set excludefile=
set outputfile=
set debug=

:: handle parameters
:setOptions
if [%1[==[-workspace[ (set workspace=%2& shift /1 & shift /1 & goto setOptions)
if [%1[==[-rulefile[ (set rulefile=%2& shift /1 & shift /1 & goto setOptions)
if [%1[==[-exportdir[ (set exportdir=%2& shift /1 & shift /1 & goto setOptions)
if [%1[==[-directory[ (set directory=%2& shift /1 & shift /1 & goto setOptions)
if [%1[==[-projects[ (set projects=%2& shift /1 & shift /1 & goto setOptions)
if [%1[==[-includefile[ (set includefile=%2& shift /1 & shift /1 & goto setOptions)
if [%1[==[-excludefile[ (set excludefile=%2& shift /1 & shift /1 & goto setOptions)
if [%1[==[-outputfile[ (set outputfile=%2& shift /1 & shift /1 & goto setOptions)
if [%1]==[-debug] (set debug=true& shift /1 & goto setOptions)
if not [%1[==[[ goto promptuser


:: workspace, rulefile, exportdir are mandatory
:validate
if [%workspace%[==[[ (
	echo -workspace parameter is mandatory 
	goto promptuser
)
if [%rulefile%[==[[ (
	echo -rulefile parameter is mandatory 
	goto promptuser
)
if [%exportdir%[==[[ (
	echo -exportdir parameter is mandatory 
	goto promptuser
)


:: construct parameters and command
set ap_parm=-application com.ibm.rsaz.analysis.commandline.AnalyzeApplication
set ws_parm=-data %workspace%
set rf_parm=-rulefile %rulefile%
set exp_parm=-exportdirectory %exportdir%
set dir_parm=
if not [%directory%[==[[ set dir_parm=-directory %directory%
set proj_parm=
if not [%projects%[==[[ set proj_parm=-projects %projects%
set in_parm=
if not [%includefile%[==[[ set in_parm=-includefile %includefile%
set ex_parm=
if not [%excludefile%[==[[ set ex_parm=-excludefile %excludefile%
set command="%rdz_install_dir%\eclipse.exe" %ap_parm% %ws_parm% %rf_parm% %dir_parm% %proj_parm% %in_parm% %ex_parm% %exp_parm% -verbose -nosplash

:: run command
echo Running software analysis...
echo %command%
if not [%outputfile%[==[[ goto commandwithoutput
if [%outputfile%[==[[ goto commandnooutput

:commandwithoutput
%command% > %outputfile%
if [%debug%[==[true[ type %outputfile%
goto done

:commandnooutput
if [%debug%[==[true[ goto commandnooutputdebug
%command%
goto done

:commandnooutputdebug
set outfile=codereviewbatch.log
if not [%tmp%[==[[ set outfile=%tmp%\codereviewbatch.log
%command% > %outfile%
type %outfile%
goto done

:promptuser
echo.   
echo codereviewbatch -workspace ws_location -rulefile rule_file 
echo     -exportdir exp_location [-directory dirs] [-projects projs]
echo     [-includefile in_file] [-excludefile ex_file] [-outputfile out_file]
echo     [-debug]
echo.
echo   ws_location   The workspace location
echo   rule_file     The file containing exported rules to be executed
echo   exp_location  The directory where data files are written
echo   dirs          Comma-separated directories containing source
echo   projs         Comma-separated workspace projects containing source
echo   in_file       File containing list of files to include in analysis      
echo   ex_file       File containing list of files to exclude from analysis
echo   out_file      Target file for command output
echo.   
echo Use -debug to print command output to the console.
echo.   
echo The correct usage of this tool is described in the on-line documentation
echo for Rational Developer for System z. 
goto done

:done
endlocal

Feedback