how do I get the workitems fixed between build results snapshots? using java api
I use the following code to create a build result, the question is how do I get the workitems fixed between build results snapshots?
// Add snapshot to build result
IBuildResultContribution contribution = BuildItemFactory.createBuildResultContribution();
contribution.setExtendedContributionTypeId(ScmConstants.EXTENDED_DATA_TYPE_ID_BUILD_SNAPSHOT);
contribution.setImpactsPrimaryResult(false);
contribution.setExtendedContribution(baselineSet);
result = buildClient.addBuildResultContribution(result, contribution,IBuildResult.PROPERTIES_COMPLETE, null);
// Add workspace to build result
contribution = BuildItemFactory.createBuildResultContribution();
contribution.setExtendedContributionTypeId(ScmConstants.EXTENDED_DATA_TYPE_ID_BUILD_WORKSPACE);
contribution.setImpactsPrimaryResult(false);
contribution.setExtendedContribution(baselineSet.getOwner());
result = buildClient.addBuildResultContribution(result, contribution,IBuildResult.PROPERTIES_COMPLETE, null);
contribution = BuildItemFactory.createBuildResultContribution();
contribution.setExtendedContributionTypeId(WorkItemConstants.EXTENDED_DATA_TYPE_ID);
contribution.setImpactsPrimaryResult(false);
//contribution.setExtendedContributionData(ContentUtil.stringArrayToContent(repo, handleIds,'\n'); //EXTENDED_DATA_DELIMITER));
result = buildClient.addBuildResultContribution(result, contribution,IBuildResult.PROPERTIES_COMPLETE, null);
// Add snapshot to build result
IBuildResultContribution contribution = BuildItemFactory.createBuildResultContribution();
contribution.setExtendedContributionTypeId(ScmConstants.EXTENDED_DATA_TYPE_ID_BUILD_SNAPSHOT);
contribution.setImpactsPrimaryResult(false);
contribution.setExtendedContribution(baselineSet);
result = buildClient.addBuildResultContribution(result, contribution,IBuildResult.PROPERTIES_COMPLETE, null);
// Add workspace to build result
contribution = BuildItemFactory.createBuildResultContribution();
contribution.setExtendedContributionTypeId(ScmConstants.EXTENDED_DATA_TYPE_ID_BUILD_WORKSPACE);
contribution.setImpactsPrimaryResult(false);
contribution.setExtendedContribution(baselineSet.getOwner());
result = buildClient.addBuildResultContribution(result, contribution,IBuildResult.PROPERTIES_COMPLETE, null);
contribution = BuildItemFactory.createBuildResultContribution();
contribution.setExtendedContributionTypeId(WorkItemConstants.EXTENDED_DATA_TYPE_ID);
contribution.setImpactsPrimaryResult(false);
//contribution.setExtendedContributionData(ContentUtil.stringArrayToContent(repo, handleIds,'\n'); //EXTENDED_DATA_DELIMITER));
result = buildClient.addBuildResultContribution(result, contribution,IBuildResult.PROPERTIES_COMPLETE, null);
2 answers
The generateChangeLog Ant task can do this. Its source is in the SDK, in .../plugins/com.ibm.team.build.toolkit.rtc.feature.source_3.0.700.v20131019_0328/src/com.ibm.team.build.toolkit_3.0.700.v20131015_0229/ant_tasks/build-antsrc.zip
It uses an internal SCM operation to do this, though (com.ibm.team.filesystem.rcp.core.internal.changelog.GenerateChangeLogOperation).
This seems to work
public String[] compareSnapshots(IBuildResult result,IBaselineSetHandle new_baselineSetHandle) throws TeamRepositoryException {
ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(repo);
IItemManager itemManager = repo.itemManager();
List workItemUUIDs = new ArrayList();
List<IChangeSet> changesets = new ArrayList();
IBaselineSetHandle last_snapshot_handle = null;
// Get Last Result snapshot
IBuildResultContribution[] last_contribution = buildClient.getBuildResultContributions(result,ScmConstants.EXTENDED_DATA_TYPE_ID_BUILD_SNAPSHOT,MONITOR);
for (int i = 0; i < last_contribution.length; i++) {
last_snapshot_handle = (IBaselineSetHandle) last_contribution[i].getExtendedContribution();
}
// Compare snapshots
IChangeHistorySyncReport report = wm.compareBaselineSets(last_snapshot_handle,new_baselineSetHandle,Collections.EMPTY_LIST,MONITOR);
// Get Outgoing changesets
if (report.outgoingChangeSets().size() > 0) {
changesets.addAll(itemManager.fetchCompleteItems(report.outgoingChangeSets(), IItemManager.DEFAULT, null));
}
// Get Incomming changsets
if (report.incomingChangeSets().size() > 0) {
changesets.addAll(itemManager.fetchCompleteItems(report.incomingChangeSets(), IItemManager.DEFAULT, null));
}
// Check Changeset for workitems
if (changesets.size() != 0) {
// Get summary of chageset links
List<IChangeSetLinkSummary> links = wm.getChangeSetLinkSummary(changesets,MONITOR);
for (Iterator it = links.iterator(); it.hasNext();) {
IChangeSetLinkSummary link = (IChangeSetLinkSummary) it.next();
// Get Link handles
List<ILinkHandle> links_handles = link.getLinks();
for (Iterator it1 = links_handles.iterator(); it1.hasNext();) {
ILinkHandle links_handle = (ILinkHandle) it1.next();
ILink links_item = (ILink)repo.itemManager().fetchCompleteItem(links_handle, IItemManager.DEFAULT, MONITOR);
// Get Work Item from link handle
IReference targetRef = links_item.getTargetRef();
if (targetRef.isItemReference() && ((IItemReference) targetRef).getReferencedItem() instanceof IWorkItemHandle) {
IWorkItemHandle workItemHandle = (IWorkItemHandle) ((IItemReference) targetRef).getReferencedItem();
workItemUUIDs.add(workItemHandle.getItemId().getUuidValue());
}
}
}
}
// Convert Work Item list to array
String[] handleIds = new String[workItemUUIDs.size()];
int i = 0;
for (Iterator it = workItemUUIDs.iterator(); it.hasNext();) {
handleIds[i] = (String) it.next();
i++;
}
return handleIds;
}
public String[] compareSnapshots(IBuildResult result,IBaselineSetHandle new_baselineSetHandle) throws TeamRepositoryException {
ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(repo);
IItemManager itemManager = repo.itemManager();
List workItemUUIDs = new ArrayList();
List<IChangeSet> changesets = new ArrayList();
IBaselineSetHandle last_snapshot_handle = null;
// Get Last Result snapshot
IBuildResultContribution[] last_contribution = buildClient.getBuildResultContributions(result,ScmConstants.EXTENDED_DATA_TYPE_ID_BUILD_SNAPSHOT,MONITOR);
for (int i = 0; i < last_contribution.length; i++) {
last_snapshot_handle = (IBaselineSetHandle) last_contribution[i].getExtendedContribution();
}
// Compare snapshots
IChangeHistorySyncReport report = wm.compareBaselineSets(last_snapshot_handle,new_baselineSetHandle,Collections.EMPTY_LIST,MONITOR);
// Get Outgoing changesets
if (report.outgoingChangeSets().size() > 0) {
changesets.addAll(itemManager.fetchCompleteItems(report.outgoingChangeSets(), IItemManager.DEFAULT, null));
}
// Get Incomming changsets
if (report.incomingChangeSets().size() > 0) {
changesets.addAll(itemManager.fetchCompleteItems(report.incomingChangeSets(), IItemManager.DEFAULT, null));
}
// Check Changeset for workitems
if (changesets.size() != 0) {
// Get summary of chageset links
List<IChangeSetLinkSummary> links = wm.getChangeSetLinkSummary(changesets,MONITOR);
for (Iterator it = links.iterator(); it.hasNext();) {
IChangeSetLinkSummary link = (IChangeSetLinkSummary) it.next();
// Get Link handles
List<ILinkHandle> links_handles = link.getLinks();
for (Iterator it1 = links_handles.iterator(); it1.hasNext();) {
ILinkHandle links_handle = (ILinkHandle) it1.next();
ILink links_item = (ILink)repo.itemManager().fetchCompleteItem(links_handle, IItemManager.DEFAULT, MONITOR);
// Get Work Item from link handle
IReference targetRef = links_item.getTargetRef();
if (targetRef.isItemReference() && ((IItemReference) targetRef).getReferencedItem() instanceof IWorkItemHandle) {
IWorkItemHandle workItemHandle = (IWorkItemHandle) ((IItemReference) targetRef).getReferencedItem();
workItemUUIDs.add(workItemHandle.getItemId().getUuidValue());
}
}
}
}
// Convert Work Item list to array
String[] handleIds = new String[workItemUUIDs.size()];
int i = 0;
for (Iterator it = workItemUUIDs.iterator(); it.hasNext();) {
handleIds[i] = (String) it.next();
i++;
}
return handleIds;
}
Comments
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Nov 10 '13, 11:20 a.m.What does "fixed" mean in this context? What do you want to do?
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Nov 10 '13, 11:21 a.m.Oh, you mean how can you compare two snap shots, get the work items contributing code that are closed?
K M
Nov 11 '13, 11:21 a.m.That is right
Tim Mok
JAZZ DEVELOPER Nov 11 '13, 11:22 a.m.I've converted your answer into a comment so that others do not mistake this question as answered.