Rational Developer for System z

サンプル・スクリプトの実行

サンプル・スクリプトは、Linux または Windows のコマンド行からコード・レビュー・アプリケーションを呼び出す方法の実施例を示しています。

サンプル・スクリプトについて

サンプル・スクリプトは、コマンド行からコード・レビュー・パラメーターを収集し、それらの値を指定してコード・レビュー・アプリケーションを呼び出し、アプリケーションからの出力を出力ファイルに書き込みます。 スクリプトには一定レベルのエラー処理機能があり、必須パラメーターを検査して欠落しているものがあればエラー・メッセージを表示します。

ご使用のオペレーティング・システム向けのバージョンのサンプル・スクリプトは、製品インストール・ディレクトリーの bin サブディレクトリーにある以下のファイルです。
  • Linux の場合: install/bin/codereviewbatch.sh
  • Windows の場合: install¥bin¥codereviewbatch.bat
ここで、install は製品インストール・ディレクトリーです。

Linux 用サンプル・スクリプトと Windows 用サンプル・スクリプトの内容については、後のサブトピックで示します。

サンプル・スクリプトの実行

サンプル・スクリプトを実行するには、以下のようにします。
  1. 分析構成エディターから規則情報をエクスポートして規則ファイルを作成します。
  2. パラメーター値として使用するディレクトリー、データ・ファイル、ソース・コード・ファイルをセットアップします。
  3. コマンド・コンソールを開きます。
  4. コマンドを 1 行に入力してスクリプトを実行します。例を以下に示します。
    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

スクリプト構文

サンプル・スクリプトの構文は、以下のとおりです。 ブラケットはオプション・パラメーターを示します。

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


それぞれの意味は次のとおりです。
   -workspace ws_location は、使用する Eclipse ワークスペースのファイル・パスです。

   -rulefile rule_file は、分析構成エディターからエクスポートした規則セットが入っている .dat ファイルです。

   -exportdir exp_location は、出力データ・ファイルが書き込まれるディレクトリーです。

   -directory dirs は、ソース・ファイルが入っているディレクトリーのコンマ区切りリストです。

   -projects projs は、ソース・ファイルがあるワークスペース内プロジェクトのコンマ区切りリストです。

   -includefile in_file は、コード・レビューに含めるソース・ファイルのリストが入っているテキスト・ファイルです。

   -excludefile ex_file は、コード・レビューから除外するソース・ファイルのリストが入っているテキスト・ファイルです。

   -outputfile out_file は、出力情報を入れるターゲット・ファイルです。

   -debug は、出力情報をコンソールに表示します。

Linux 用スクリプト

次のコード・ブロックに Linux 用スクリプトを示します。

図 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 用スクリプト

次のコード・ブロックに Windows 用スクリプトを示します。

図 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

ご利用条件 | フィードバック

このインフォメーション・センターでは Eclipse テクノロジーが採用されています。 (http://www.eclipse.org)