이 절에서는 CAL(ClearCase® Automation Library) 메소드를 후크 스크립트에 포함시켜 UCM과 Rational® ClearQuest®를 통합하는 동작을 사용자 정의하는 방법에 대해 설명합니다.
다음 예제는 Perform ClearQuest Action Before Changing Activity 정책을 구현하는 UCM_CQActBeforeChact Visual Basic 스크립트의 수정된 버전입니다. 이 정책이 설정되면 개발자가 Finish Activity 오퍼레이션을 GUI에서 시작하거나 cleartool chactivity -cqact 명령을 입력하는 경우 통합에서 스크립트가 수행됩니다.
수정된 스크립트는 CAL 메소드를 사용하여 개발자가 단일 스트림 프로젝트로 작업 중인지 다중 스트림 프로젝트로 작업 중인지 판별합니다. 개발자가 단일 스트림으로 작업 중인 경우 스크립트는 Finish Activity 오퍼레이션을 허용합니다. 그렇지 않은 경우 스크립트는 오류 메시지를 리턴하고 Finish Activity 오퍼레이션을 취소합니다.
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