如何通过程序从IWorkItem项中获得ChangeSet(所有文件更改)



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

我想要一个列表包含所有的文件,得到了一个RTC的变化。我怎样才能做到这一点?

你可以看看这个线程是否有帮助:(从客户端)

  • repositoryITeamRepository
  • mgrIItemManager (repository.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的每个更改集中的文件。

你有一些想法列出文件:

  • "如何从IChangeSet中获得IConfiguration ?"
  • "如何使用API从变更集获得文件的完整路径?"

其他来源:

  • "为API开发建立Rational团队音乐会"
  • " RTC工作项客户端链接API -链接到工作项和其他元素"
              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

相关内容

  • 没有找到相关文章

最新更新