It's all about the answers!

Ask a question

How to List all outgoing ChangeSets using plain Java API

Liora Milbaum (513284117) | asked Oct 15 '12, 5:05 p.m.
edited Sep 07 '16, 7:18 p.m. by David Lafreniere (4.8k7)

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();
  IProgressMonitor monitor;
  List<IChangeSetHandle> changeSets = 
  SCMPlatform.getWorkspaceManager(teamRepository).findChangeSets(criteria, Integer.MAX_VALUE, monitor);

Your assistance will be greatly appreciated.


Accepted answer

permanent link
Tim Mok (6.6k38) | answered Oct 16 '12, 2:13 p.m.
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

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

Tim Mok commented Oct 16 '12, 4:23 p.m.

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.

The call will return a list of IWorkspaceHandle, which you can use to get the IWorkspaceConnection.

5 other answers

permanent link
Liora Milbaum (513284117) | answered Oct 20 '12, 2:30 a.m.
 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 );
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, 
Collections.EMPTY_LIST, monitor);
List<IChangeSetHandle> outgoingChangeSets = changeHistorySyncReport.outgoingChangeSets();
for (IChangeSetHandle changeSet : outgoingChangeSets) {
workspaceConnection.deliver(workspaceConnection1,changeHistorySyncReport ,Collections.EMPTY_LIST,Collections.singletonList(changeSet), monitor);

praveen patidar commented Nov 07 '12, 9:47 p.m.

Is there way to list all the files associated with these change set handlers ?

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 ,
Sorry for miscommunication. What I want is to have ChangeSet from ChangeSethandle to print the comments, owner  and work item ID for that.What API combination should I use for the Same ?

permanent link
Liora Milbaum (513284117) | answered Oct 16 '12, 4:47 p.m.
  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.

Tim Mok commented Oct 17 '12, 10:19 a.m.

IWorkspaceSearchCriteria allows you to set the partial or exact owner name.

For stream, you can do another search with a new IWorkspaceSearchCriteria and use #setKind to specify streams instead of workspaces.

Or, you can use the workspace IWorkspaceConnection to get the flow table and access the current accept flow. It will return the IFlowEntry, which has a IFlowHandle (it's the parent interface for IWorkspaceHandle).

The second method would be more reliable to find the stream since it checks the workspace's current flow target. However, the flow table may be a little confusing so feel free to ask questions about it. I only suggest the first method if you want to run a comparison between the workspace and a few different streams.

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

permanent link
Liora Milbaum (513284117) | answered Oct 18 '12, 1:35 a.m.
 Tried also the second suggestions. This is what I have come up to.
IFlowTable flowTable = workspaceConnection.getFlowTable(); 
IFlowEntry flowEntry = flowTable.getCurrentDeliverFlow();
IChangeHistorySyncReport changeHistorySyncReport = workspaceConnection.compareTo(???, 
Collections.EMPTY_LIST, monitor);

Tim Mok commented Oct 18 '12, 9:58 a.m.

Looks good.

Then IFlowEntry#getFlowNode() will get you the stream's handle. You can get the IWorkspaceConnection for that the same way as the workspace and use it for the first argument for IWorkspaceConnection#compareTo(..)

permanent link
Liora Milbaum (513284117) | answered Oct 20 '12, 2:58 a.m.
The deliver method is working. There was an issue with the preconditions. 

Tim, thanks for the personal attention.


permanent link
Chethan Kumar (11) | answered Sep 07 '16, 2:03 a.m.
Hi Liora,

Could you please post the actual code of working Deliver method.


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.

Your answer

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