How to List all outgoing ChangeSets using plain Java API
Hi,
How do I list all change sets in a given workspace which are waiting to be delivered (in the outgoing folder) using plain Java API?
This is the snippet of the code. The only issue here is the criteria. How to set it correctly?
IChangeSetSearchCriteria criteria = IChangeSetSearchCriteria.FACTORY.newInstance();
criteria.setOldestFirst(true);
IProgressMonitor monitor;
List<IChangeSetHandle> changeSets =
SCMPlatform.getWorkspaceManager(teamRepository).findChangeSets(criteria, Integer.MAX_VALUE, monitor);
Your assistance will be greatly appreciated.
Thanks,
Liora
Accepted answer
I think you want to take a look at IWorkspaceConnection#compareTo for a comparison between your workspace and the target. You can specify the kind of comparison to do with the flags in WorkspaceComparisonFlags.
The result of the call is a IChangeHistorySyncReport where you can see the incoming and outgoing changes.
The code you've posted is for searching change sets. It doesn't include a context of where you want to search so depending on your criteria, it could return change sets that have been discarded and never delivered to any stream.
The result of the call is a IChangeHistorySyncReport where you can see the incoming and outgoing changes.
The code you've posted is for searching change sets. It doesn't include a context of where you want to search so depending on your criteria, it could return change sets that have been discarded and never delivered to any stream.
Comments
5 other answers
I am on the last mile of the marathon:-)
My target is to deliver the change Sets one by one. The deliver method is not working.
IWorkspaceManager wm = (IWorkspaceManager)teamRepository.getClientLibrary(IWorkspaceManager.class);
IWorkspaceSearchCriteria criteria1 = IWorkspaceSearchCriteria.FACTORY.newInstance();
criteria1.setKind( IWorkspaceSearchCriteria.WORKSPACES );
criteria1.setExactName( INTEGRATION_WORKSPACE );
criteria1.setExactOwnerName(INTEGRATION_WORKSPACE_OWNER);
List<IWorkspaceHandle> workspaceHandles = wm.findWorkspaces(criteria1, Integer.MAX_VALUE, monitor);
IWorkspaceHandle wh = workspaceHandles.get( 0 );
IWorkspaceConnection workspaceConnection = wm.getWorkspaceConnection(wh, monitor);
IFlowTable flowTable = workspaceConnection.getFlowTable();
IFlowEntry flowEntry = flowTable.getCurrentDeliverFlow();
IFlowNodeHandle streamHandle = flowEntry.getFlowNode();
IWorkspaceConnection workspaceConnection1 = wm.getWorkspaceConnection((IWorkspaceHandle) streamHandle, monitor);
IChangeHistorySyncReport changeHistorySyncReport = workspaceConnection.compareTo(workspaceConnection1,
WorkspaceComparisonFlags.CHANGE_SET_COMPARISON_ONLY,
Collections.EMPTY_LIST, monitor);
List<IChangeSetHandle> outgoingChangeSets = changeHistorySyncReport.outgoingChangeSets();
for (IChangeSetHandle changeSet : outgoingChangeSets) {
workspaceConnection.deliver(workspaceConnection1,changeHistorySyncReport ,Collections.EMPTY_LIST,Collections.singletonList(changeSet), monitor);
}
Comments
Thanks Tim. Here is the code for the initialization part (I can't find how to add the owner criteria):-
IWorkspaceManager wm = (IWorkspaceManager)teamRepository.getClientLibrary(IWorkspaceManager.class);
IWorkspaceSearchCriteria criteria = IWorkspaceSearchCriteria.FACTORY.newInstance();
criteria.setKind( IWorkspaceSearchCriteria.WORKSPACES );
criteria.setExactName( INTEGRATION_WORKSPACE );
List<IWorkspaceHandle> workspaceHandles = ((IItemQueryPage) wm.findWorkspaces(criteria, Integer.MAX_VALUE, monitor)).getItemHandles();
IWorkspaceHandle wh = workspaceHandles.get( 0 );
IWorkspaceConnection workspaceConnection = wm.getWorkspaceConnection(wh, monitor);
My next target is the find the steamConnection required by the compareTo method.
Comments
Tried also the second suggestions. This is what I have come up to.
I
IFlowTable flowTable = workspaceConnection.getFlowTable();
IFlowEntry flowEntry = flowTable.getCurrentDeliverFlow();
IChangeHistorySyncReport changeHistorySyncReport = workspaceConnection.compareTo(???,
WorkspaceComparisonFlags.CHANGE_SET_COMPARISON_ONLY,
Collections.EMPTY_LIST, monitor);