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();
    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


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




but this fails with the following exception:

java.lang.ClassCastException: incompatible with

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.
From the JavaDoc of IFlowNodeConnection#getBaselineSets():

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.