Questa sezione illustra come includere i metodi CAL (ClearCase Automation Library) negli script di hook per personalizzare il funzionamento dell'integrazione di Rational ClearQuest con UCM.
Questo esempio è una versione modificata dello script Visual Basic UCM_CQActBeforeChact che implementa la politica Perform ClearQuest Action Before Changing Activity. Quando viene impostata questa politica, l'integrazione esegue lo script se uno sviluppatore avvia un'operazione di fine attività dalla GUI o immettendo il comando cleartool chactivity -cqact.
Lo script modificato utilizza i metodi CAL per determinare se lo sviluppatore opera in un progetto a flusso singolo o a più flussi. Se lo sviluppatore lavora su un progetto a flusso singolo, lo script consente l'operazione di fine attività. In caso contrario, lo script restituisce un massaggio di errore e annulla l'operazione di fine attività.
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