It's all about the answers!

Ask a question

how do I get the workitems fixed between build results snapshots? using java api


0
1
K M (38325151) | asked Nov 08 '13, 9:54 a.m.
retagged Dec 16 '13, 4:16 p.m. by David Lafreniere (4.8k7)
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);       



Comments
Ralph Schoon commented Nov 10 '13, 11:20 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

What does "fixed" mean in this context? What do you want to do?


Ralph Schoon commented Nov 10 '13, 11:21 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Oh, you mean how can you compare two snap shots, get the work items contributing code that are closed?


K M commented Nov 11 '13, 8:05 a.m. | edited Nov 11 '13, 11:21 a.m.

That is right


Tim Mok commented Nov 11 '13, 11:22 a.m.
JAZZ DEVELOPER

I've converted your answer into a comment so that others do not mistake this question as answered.

2 answers



permanent link
Nick Edgar (6.5k711) | answered Nov 11 '13, 4:33 p.m.
JAZZ DEVELOPER
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).

permanent link
K M (38325151) | answered Nov 12 '13, 3:09 p.m.
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;
    }

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.