ここでは、フック スクリプトに CAL (ClearCase Automation Library) メソッドを組み込んで、Rational® ClearQuest® の UCM との統合の動作をカスタマイズする方法を示します。
次の例は、UCM_CQActBeforeChact Visual Basic スクリプトの修正バージョンで、「作業変更前に ClearQuest アクションを実行する」ポリシーを実装します。このポリシーが設定された場合、開発者がアクティビティの終了操作を開始するときに、GUI または cleartool chactivity -cqact コマンドを入力して、統合でスクリプトを実行します。
修正されたスクリプトでは、CAL メソッドを使用して開発者が単一ストリーム プロジェクトで作業しているか、またはマルチストリーム プロジェクトで作業しているかどうかを判別します。開発者が単一ストリーム プロジェクトで作業している場合、スクリプトによって、アクティビティの終了操作を行うことができます。そうでない場合、スクリプトによりエラー メッセージが戻され、アクティビティの終了操作がキャンセルされます。
REM Start of Global Script UCM_CQActBeforeChact Function UCM_CQActBeforeChact (entity_type, entity_id, project_info, stream_info) ' This is the script that implements the "Perform Action Before ' Changing Activity" policy. When initially installed, it invokes a ' default script. If users want to customize this policy, they should ' edit this script to use their code rather than invoking the default ' script. The default script code can be used as an example. ' ' INPUT: ' - entity_type: name of the type of entity on which action ' will be executed (for example, "defect") ' - entity_id: id (e.g. "SAMPL0000001") of entity on which action will ' be executed ' OUTPUT: ' - If the action was successfully executed, this must return an empty ' string ' - If the action was not successfully executed, this must return a ' string to be displayed as an error message. ' Allow chact only if activity is in a single stream project proj_model = "DEFAULT" ' Get hook's session context Set session = GetSession() ' Get the entity Set entity = session.GetEntity(entity_type, entity_id) ' Get the entity's ucm_vob_object field value. This value is a string ' that includes the UCM project's object ID and the PVOB's UUID. ucm_vob_object = entity.GetFieldValue("ucm_vob_object").GetValue() Dim pvob_uuid ' Strip the project's object ID from the string and return the PVOB's ' UUID. pvob_uuid = Right(ucm_vob_object, 40) ' Initialize ClearCase.Application COM object ' Create a ClearCase application object. A ClearCase application ' object must exist before you can use CAL methods. The remaining ' steps in the script use CAL methods. On Error Resume Next Set CC = CreateObject("ClearCase.Application") If Err.Number <> 0 Then MsgBox "ClearCase.Application Error 1:" & Err.Description End if On Error Resume Next ' Using the PVOB's UUID, get a ClearCase PVOB object of the activity. Set PVOB = CC.ProjectVOB(pvob_uuid) If Err.Number <> 0 Then MsgBox "ClearCase.Application Error 2:" & Err.Description End if On Error Resume Next ' Create a ClearCase activity object (CCActivity) based on the PVOB and ' entity ID (equals UCM activity name). Set Act = PVOB.Activity(entity_id) If Err.Number <> 0 Then MsgBox "ClearCase.Application Error 3:" & Err.Description End if On Error Resume Next ' Return the stream in which the activity was created. set stream = Act.Stream If Err.Number <> 0 Then MsgBox "ClearCase.Application Error 4:" & Err.Description End if On Error Resume Next ' Return the project that contains the stream. set project = stream.Project If Err.Number <> 0 Then MsgBox "ClearCase.Application Error 5:" & Err.Description End if On Error Resume Next ' Return the project model. proj_model = project.Model If Err.Number <> 0 Then MsgBox "ClearCase.Application Error 6:" & Err.Description End if ' Test the value of the project model. ' model = SIMPLE: single stream project ' If it is SIMPLE, meaning single-stream, the script returns an ' empty string and the developer is allowed to complete the Finish ' Activity operation. ' model = DEFAULT: hierarchical project ' If it is DEFAULT, meaning multiple-stream, the script returns an ' error message and cancels the Finish Activity operation. If proj_model = "SIMPLE" Then ' single stream model, allow change act UCM_CQActBeforeChact = "" Else ' hierarchical project, fail UCM_CQActBeforeChact = "Must be in a single stream project." End if End Function REM End of Global Script UCM_CQActBeforeChact