How to List all outgoing ChangeSets using plain Java API
Liora Milbaum (513●2●89●118)
| asked Oct 15 '12, 5:05 p.m.
edited Sep 07 '16, 7:18 p.m. by David Lafreniere (4.8k●7)
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. Liora Milbaum selected this answer as the correct answer
Comments
Liora Milbaum
commented Oct 16 '12, 4:15 p.m.
Thanks Tim. I have started coding according to your suggestion. Now, I am stuck at initializing the workspaceHandle..
IWorkspaceManager wm = (IWorkspaceManager)teamRepository.getClientLibrary(IWorkspaceManager.class);
IWorkspaceHandle wh = ???.; (I have the name of the workspace)
IWorkspaceConnection workspaceConnection = wm.getWorkspaceConnection(wh, monitor);
You can use IWorkspaceManager#findWorkspaces(IWorkspaceCriteria, int, IProgressMonitor) to find the workspace that you want. The criteria allows for searching by workspace name. You may want to add the owner to the criteria as well in case another user has the same workspace name.
|
5 other answers
Hi Liora,
Could you please post the actual code of working Deliver method. Regards, Chethan Comments
Liora Milbaum
commented Sep 07 '16, 2:38 a.m.
Few years passed :-) The code is no longer available to me.
Chethan Kumar
commented Sep 07 '16, 2:50 a.m.
:-) Bad luck to me.
|
The deliver method is working. There was an issue with the preconditions.
Tim, thanks for the personal attention.
Liora
|
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 IWorkspaceSearchCriteria allows you to set the partial or exact owner name.
Liora Milbaum
commented Oct 18 '12, 12:21 a.m.
Found how to set the exact owner name.
For the stream, I am still stuck. The output is WorkspaceHandle and not streamConnection. I am not sure, which method to use to find the streamConnection.
IWorkspaceSearchCriteria criteria2 = IWorkspaceSearchCriteria.FACTORY.newInstance();
criteria2.setKind( IWorkspaceSearchCriteria.STREAMS );
criteria2.setExactName( INTEGRATION_STREAM );
workspaceHandles = ((IItemQueryPage) wm.findWorkspaces(criteria2, Integer.MAX_VALUE, monitor)).getItemHandles();
|
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
praveen patidar
commented Nov 07 '12, 9:47 p.m.
Hello
Liora Milbaum
commented Nov 08 '12, 12:51 a.m.
Follow the instructions in How to access change set file information.
praveen patidar
commented Nov 08 '12, 1:22 a.m.
Hello ,
|
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.