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