It's all about the answers!

Ask a question

How to programmatically add components to workspace


0
1
SEC Servizi (97123559) | asked Sep 09 '13, 7:19 a.m.
edited Sep 09 '13, 7:22 a.m.
We would programmatically add existing components to new workspace:
IScmService scmService = ...
IContributorHandle contributorH = ...
IWorkspaceHandle stream = ...
IWorkspace wks = scmService.createWorkspace(contributorH, wksName, wksDescription, stream, null, stream, null, null, IRepositoryProgressMonitor.ITEM_FACTORY.createItem(monitor)).getWorkspace();
IComponentHandle componentH = ...
IWorkspaceHandle targetH = ...
scmService.addComponentFromWorkspace(wks, componentH, targetH, false, IScmService.DELTA_PER_INVOCATION, null, IRepositoryProgressMonitor.ITEM_FACTORY.createItem(monitor));
While the createWorkspace operation creates the new repository workspace, the addComponentFromWorkspace operation does not add the component... We have to call any save/refresh operation?
The code above is called by a save work-item follow up action.
Thanks in advance.

Comments
SEC Servizi commented Sep 09 '13, 10:00 a.m. | edited Sep 09 '13, 10:33 a.m.

During further investigation, it appears that added components are dropped by the save transaction. Any advice?

4 answers



permanent link
SEC Servizi (97123559) | answered Sep 12 '13, 10:54 a.m.
Ok, we found what was the problem! :D
The repository worskpace is created as well as components are added, but when that workspace is used as a build workspace (and this is our case!), components are dropped by the build request process if the flow targets table does not contain streams where components belong.
By the way, this behavior seems quite strange for us...


permanent link
SEC Servizi (97123559) | answered Sep 11 '13, 7:10 a.m.
edited Sep 12 '13, 10:36 a.m.
We tried to use IScmService#updateComponents (instead of IScmService#updateComponents2 beacuse we are still on RTC v2.0.0.2) but nothing changed:
IWorkspace wks = scmService.createWorkspace(contributorH, wksName, wksDescription, stream, null, stream, null, null, IRepositoryProgressMonitor.ITEM_FACTORY.createItem(monitor)).getWorkspace();
IComponentHandle componentH = ...
IWorkspaceHandle seedH = ...
IComponentOpDescriptor op = IComponentOpDescriptor.FACTORY.addComponent(componentH, seedH, false);
scmService.updateComponents(wksH, null, new IComponentOpDescriptor[]{ op }, false, IScmService.DELTA_PER_INVOCATION, null, IRepositoryProgressMonitor.ITEM_FACTORY.createItem(monitor));
Any advice? (To solve this problem is really important for us!)
Thanks in advance.

Comments
Tim Mok commented Sep 11 '13, 9:31 a.m.
JAZZ DEVELOPER

I don't know what you mean by nothing changed. Can you post what you did to check if the component was added to the workspace?


SEC Servizi commented Sep 11 '13, 9:48 a.m. | edited Sep 11 '13, 9:49 a.m.

We mean "nothing changed despite to use a IComponentOpDescriptor operation".
We run the code above by a save work-item post-operation, we searched for workspace created in to repository, then we opened it.

This workspace lists components added by IScmService.createWorkspace(), but components added by IComponentOpDescriptor operations were missing.


permanent link
SEC Servizi (97123559) | answered Sep 10 '13, 4:18 a.m.
edited Sep 10 '13, 4:28 a.m.
We tried a different approach adding an existing flow target to the new workspace:
IWorkspace wks = ...
List<FlowEntry> flows = ((Workspace) wks).getFlows();
List<FlowEntry> acceptFlows = new ArrayList<FlowEntry>();
List<FlowEntry> deliverFlows = new ArrayList<FlowEntry>();
for (FlowEntry flow : flows) {
if ((flow.getFlags() & FlowFlags.ACCEPT ) != 0) {
acceptFlows.add((FlowEntry) EcoreUtil.copy((EObject) flow));
} else if ((flow.getFlags() & FlowFlags.DELIVER) != 0) {
deliverFlows.add((FlowEntry) EcoreUtil.copy((EObject) flow));
}
}
FlowEntry flow = ScmFactory.eINSTANCE.createFlowEntry();
flow.setTargetWorkspace(target);
flow.setFlags(FlowFlags.DELIVER);
deliverFlows.add(flow);
CurrentFlows currentFlows = (CurrentFlows) EcoreUtil.copy((EObject) ((Workspace) wks).getCurrentFlows());
IComponentHandle[] components = ...
CurrentFlows[] currentComponentFlows = ...
scmService.setWorkspaceFlows(wks, acceptFlows.toArray(new FlowEntry[0]), deliverFlows.toArray(new FlowEntry[0]), currentFlows, components, currentComponentFlows, null, IRepositoryProgressMonitor.ITEM_FACTORY.createItem(monitor));
We have to use EcoreUtil.copy() due to ImmutablePropertyException throwned.
We don't undertand how to set components and currentComponentFlows values... Looking at SCMHelper.addDeliverFlow(), we see empty arrays were passed, but in our case we need to add components, too... Any advice?
In fact, we would obtain this client behavior: adding a flow target to build workspace leads to add all components to workspace when a build is request.
Thanks in advance.

Comments
SEC Servizi commented Sep 13 '13, 8:52 a.m. | edited Sep 13 '13, 8:53 a.m.
Adding a deliver flow is not enough, we have to add an accept flow, too.
FlowEntry acceptFlow = ScmFactory.eINSTANCE.createFlowEntry();
acceptFlow.setTargetWorkspace(targetH);
acceptFlow.setFlags(FlowFlags.ACCEPT);
acceptFlows.add(acceptFlow);
Now all works like a sharme!

permanent link
Ralph Schoon (63.1k33645) | answered Sep 09 '13, 10:12 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I worked from Snippet 2 from the plain Java Client Libraries. I am not sure where you have your code. On a client I was able to add components this way:

// Add new components
Collection components = extComponents.values();
for (Object comp : components) {
	IComponentHandle cHandle = (IComponentHandle) comp;
	workspaceConnection.applyComponentOperations(Collections
			.singletonList(workspaceConnection.componentOpFactory()
					.addComponent(cHandle, false)), true, monitor);
}



Comments
Tim Mok commented Sep 09 '13, 10:38 a.m.
JAZZ DEVELOPER

The snippet is the correct way to do it. Using the service is a different layer, not recommended, and is also the deprecated call.


1
Ralph Schoon commented Sep 09 '13, 10:44 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Tim, I think the snippets should be reworked, there are several deprecated methods in usage and I actually had to dig into the deprecated call to figure out the ones not deprecated.


SEC Servizi commented Sep 09 '13, 10:49 a.m. | edited Sep 09 '13, 11:06 a.m.

We are using the IScmService service beacuse we are on a server extension, not on a client...


Tim Mok commented Sep 10 '13, 8:26 a.m.
JAZZ DEVELOPER

IScmService#updateComponents2(...) is the current call to add a component to a workspace.

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.