It's all about the answers!

Ask a question

Exception when programmatically promoting a snapshot from a workspace to a stream


Dave Sinclair (21179) | asked Mar 01 '13, 3:17 p.m.
I'm trying to write some plainJava API code to promote a snapshot from a workspace to a stream.  Here is my code:

public static void promoteSnapshot(ITeamRepository repository,
                                       String workspaceName,
                                       String snapshotName,
                                       IProgressMonitor monitor) throws TeamRepositoryException {
   
   
    IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(repository);
   
    // find work space
    IWorkspaceSearchCriteria wsSearch = IWorkspaceSearchCriteria.FACTORY.newInstance();
    wsSearch.setKind(IWorkspaceSearchCriteria.WORKSPACES);
    wsSearch.setExactName(workspaceName);
    List<IWorkspaceHandle> handlesWS = workspaceManager.findWorkspaces(wsSearch, Integer.MAX_VALUE, null);
   
    // get a connection to the workspace that has the name workspaceName
    IWorkspaceConnection workspaceConnection = null;
    if (handlesWS != null && handlesWS.size() > 0) {
        workspaceConnection = workspaceManager.getWorkspaceConnection(handlesWS.get(0), null);
    } else {
        System.out.println("no workspaceConnection to workspace: " + workspaceName);
    }
   
    IFlowTable flowTable = workspaceConnection.getFlowTable();
    IFlowEntry flowEntry = flowTable.getCurrentDeliverFlow();

    IWorkspace flowWorkspace = (IWorkspace)repository.itemManager().fetchCompleteItem(flowEntry.getFlowNode(), IItemManager.REFRESH, monitor);
    IWorkspaceConnection flowConnection = workspaceManager.getWorkspaceConnection(flowWorkspace, monitor);               

    List<IBaselineSet> snapshots = workspaceConnection.getBaselineSets(null);
   
  
    for (IBaselineSet set : snapshots) {     /** FAILS WITH EXCEPTION HERE

        if(set.getName().equals(snapshotName)){

            flowConnection.addBaselineSet(set, monitor);
           
            System.out.println("Promoted basline " + set.getName() + " from " + workspaceName);

            break;

        }

    }
    }

but this fails with the following exception:

java.lang.ClassCastException: com.ibm.team.scm.common.internal.impl.BaselineSetHandleImpl incompatible with com.ibm.team.scm.common.IBaselineSet

Can anyone spot what I'm doing wrong?  many thanks
   


One answer



permanent link
John Riendeau (46626) | answered Mar 01 '13, 5:19 p.m.
JAZZ DEVELOPER
From the JavaDoc of IFlowNodeConnection#getBaselineSets():

Returns:
the list (possibly empty) of baseline sets captured from this workspace or stream (element type: IBaselineSetHandle ); the list is immutable; never null


So, snapshots is really a list of IBaselineSetHandles, not a list of IBaselineSets as you have declared it.  If you need the actual IBaselineSets, you should be able to use the IItemManager to get them using the handles, similarly to how you're getting the actual IWorkspace from the handle returned by IFlowEntry#getFlowNode().

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.