Replace components with active change-sets
We are trying to programmatically create a new repository workspace even with components having active change-sets.
We use a stream as base seed workspace and a repository workspace to obtain the updated components (with active change-sets).
Our first code was:
IWorkspace newWks = scmService.createWorkspace(user, newWksName, newWksDescription, stream, null, stream, null, null, null).getWorkspace(); IComponentHandle[] components = scmService.getComponentsForWorkspace(stream, null);
final int n = components.length;
IComponentOpDescriptor[] ops = new IComponentOpDescriptor[n];
for (int i=0; i<n; i++) {
ops[i] = IComponentOpDescriptor.FACTORY.replaceComponent(components[i], wks, false);
}
scmService.updateComponents(newWks, null, ops, true, IScmService.DELTA_PER_INVOCATION, null, null);
but it throws an exception:
com.ibm.team.repository.common.TeamRepositoryException: Source change history era must not have active change sets
So, instead of replace components, we change our code to use drop & add components:
IComponentOpDescriptor[] dropOps = new IComponentOpDescriptor[n]; IComponentOpDescriptor[] addOps = new IComponentOpDescriptor[n];
for (int i=0; i<n; i++) {
dropOps[i] = IComponentOpDescriptor.FACTORY.dropComponent(components[i], false);
addOps[i] = IComponentOpDescriptor.FACTORY.addComponent(components[i], wks, false);
} scmService.updateComponents(newWks, null, dropOps, true, IScmService.DELTA_PER_INVOCATION, null, null); scmService.updateComponents(newWks, null, addOps, true, IScmService.DELTA_PER_INVOCATION, null, null);
It seems odd, but now it works... :)
We cannot use only one array of ops because an exeception is throwned:
com.ibm.team.repository.common.TeamRepositoryException: Cannot have 2 operations on 1 component
In the new repository workspace, the active change-sets appear to belong to ADMIN instead of the original owner... Any advice?
Thanks in advance.
Comments
Sonia Dimitrov
JAZZ DEVELOPER Apr 02 '13, 10:06 a.m.Could you provide more information around this use case? Why are components being replaced from the workspace once created? Why are the change sets active?