Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

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
   


0 votes



One answer

Permanent link
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().

1 vote

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937

Question asked: Mar 01 '13, 3:17 p.m.

Question was seen: 4,883 times

Last updated: Mar 01 '13, 5:19 p.m.

Confirmation Cancel Confirm