Utilización de métodos CAL en scripts de enganche de Rational ClearQuest

En esta sección se muestra cómo incluir métodos CAL (ClearCase Automation Library) en los scripts de enganche para personalizar el comportamiento de la integración de Rational ClearQuest con UCM.

Este ejemplo es una versión modificada del script UCM_CQActBeforeChact de Visual Basic script, que implementa la política Realizar acción de ClearQuest antes de cambiar actividad. Cuando se establece esta política, la integración ejecuta el script cuando un desarrollador inicia una operación de Finalizar actividad, desde la GUI o entrando el mandato cleartool chactivity -cqact.

El script modificado utiliza métodos CAL para determinar si el desarrollador trabaja en un proyecto de corriente de datos única, o bien, en un proyecto de varias corrientes de datos. Si el desarrollador trabaja en un proyecto de una sola corriente de datos, el script permite la operación de Finalizar actividad. Si no es así, el script devuelve un mensaje de error y cancela la operación de Finalizar actividad.

VBScript

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: proyecto jerárquico

' 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 Fin de Global Script UCM_CQActBeforeChact 

Comentarios