如何通过Program从IWorkItem项获取ChangeSet(所有文件更改)

时间:2014-07-08 09:45:37

标签: rtc jazz ibm-jazz

如何通过程序从IWorkItem项目获取ChangeSet(所有文件更改)。

我想要一个包含RTC更改的所有文件的列表。我怎么能实现这个目标呢?

2 个答案:

答案 0 :(得分:3)

您可以查看this thread helps :(来自客户端)

  • repositoryITeamRepository
  • mgrIItemManagerrepository.itemManager()
  • workItem是我们想要更改的IWorkItem
  • items包含workitem
  • 的相关变更集链接集

代码:

IClientLibraryContext ctx = (IClientLibraryContext)repository;
IQueryService svc = (IQueryService)ctx.getServiceInterface(IQueryService.class);
AuditableLinkQueryModel alqr = AuditableLinkQueryModel.ROOT;
IItemQuery iq = IItemQuery.FACTORY.newInstance(alqr);

iq.filter(alqr.name()._eq("com.ibm.team.filesystem.workitems.change_set").
  _and( alqr.targetRef().referencedItem().itemId()._eq(iq.newUUIDArg())));

IItemQueryPage itemQueryPage = svc.queryItems(
  iq,
  new Object[] { workItem.getItemId() }, 
  IQueryService.ITEM_QUERY_MAX_PAGE_SIZE);

List<IChangeSet> items = mgr.fetchCompleteItems(itemQueryPage.getItemHandles(), 
                                    mgr.DEFAULT, null);
Set<String> changedFilesAndFolders = new TreeSet<String>();
for (IChangeSet cs: changeSets) {
   ...
}

您仍需要在items的每个更改集中列出文件。

您有一些想法列出文件:

其他来源:

答案 1 :(得分:0)

              private String getChangeSetFiles(IWorkItem workItem, ProjectContext ctx) throws TeamRepositoryException {
    ILinkManager linkManager = (ILinkManager) ctx.repository.getClientLibrary(ILinkManager.class);
    IWorkspaceManager workspaceManager = (IWorkspaceManager)ctx.repository.getClientLibrary(IWorkspaceManager.class);
    IItemReference workItemReference = linkManager.referenceFactory().createReferenceToItem(workItem);
    ILinkCollection linkCollection = linkManager.findLinksByTarget(ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID, workItemReference, new SysoutProgressMonitor()).getAllLinksFromHereOn();

    if (linkCollection.isEmpty()) {
        System.out.println("Work item has no change sets.");
        System.exit(0);
    }

    List<IChangeSetHandle> changeSetHandles = new ArrayList<IChangeSetHandle>();

    for (ILink link: linkCollection) {
        // Change set links should be item references
        IChangeSetHandle changeSetHandle = (IChangeSetHandle) link.getSourceRef().resolve();

        changeSetHandles.add(changeSetHandle);
    }

    @SuppressWarnings("unchecked")
    List<IChangeSet> changeSets = ctx.repository.itemManager().fetchCompleteItems(changeSetHandles, IItemManager.DEFAULT, new SysoutProgressMonitor());
    Set<String> changedFilesAndFolders = new TreeSet<String>();
    for (IChangeSet cs: changeSets) {
        for (Object o: cs.changes()) {
            IChange change = (IChange)o;

            if (change.kind() != IChange.DELETE) {
                IVersionableHandle after = change.afterState();

                // Although versionable handles are item handles you cannot use the item
                //  manager to fetch the versionable from the handle. Instead, you use the
                //  versionable manager to do this.
                IVersionable afterVersionable = workspaceManager.versionableManager().fetchCompleteState(after, new SysoutProgressMonitor());

                changedFilesAndFolders.add(afterVersionable.getName());
            }

            // If there was a rename then include the old name in the list as well
            if (change.kind() == IChange.RENAME
                    || change.kind() == IChange.DELETE) {
                IVersionableHandle before = change.beforeState();

                IVersionable beforeVersionable = workspaceManager.versionableManager().fetchCompleteState(before, new SysoutProgressMonitor());

                changedFilesAndFolders.add(beforeVersionable.getName());
            }
        }
    }
    StringBuffer sb= new StringBuffer();
    for (String fileOrFilderName: changedFilesAndFolders) {
        sb.append(fileOrFilderName+"\n");
        System.out.println("\t"+fileOrFilderName);
    }       
    return sb.toString();
}

得到的回答: https://jazz.net/library/article/1229