Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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


1

0 votes

Comments

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

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

That is right

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



2 answers

Permanent link
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).

0 votes


Permanent link
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;
    }

0 votes

Your answer

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

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,932
× 1,202
× 562
× 369
× 169
× 74

Question asked: Nov 08 '13, 9:54 a.m.

Question was seen: 7,308 times

Last updated: Dec 16 '13, 4:16 p.m.

Related questions
Confirmation Cancel Confirm