如何查找是否新添加或修改了工作项更改集文件项?

时间:2018-04-11 07:16:50

标签: java api rtc

我有一些更改集对象,我需要查看更改集中的文件是否是新添加或修改的。下面是我用来获取更改集的代码:

    IChangeSetHandle changeSets = convertToChangeSetHandles(extracted);

                        changeSet = (IChangeSet) repoApac.itemManager().fetchCompleteItem(changeSets,
                                    IItemManager.DEFAULT, monitor);

public static List<IFileItem> changeSetFileName(IChangeSet changeSet) throws TeamRepositoryException{
        IVersionableManager vm = SCMPlatform.getWorkspaceManager(repoApac).versionableManager(); 
        List changes = changeSet.changes(); 
        List<IFileItem> changeSetFileNames = new ArrayList<>();
        for(int i=0;i<changes.size();i++) { 
            Change change = (Change) changes.get(i); 
            IVersionableHandle after = change.afterState();
            if( after != null && after instanceof IFileItemHandle) { 
                IFileItem fileItem = (IFileItem) vm.fetchCompleteState(after, null); 
                changeSetFileNames.add(fileItem);
            } 
        } 
        return changeSetFileNames;
    }

        if(changeSet.isNewItem()){
                return "ADDED"; 
            }else{
                return "MODIFIED";
            }

1 个答案:

答案 0 :(得分:1)

这是工作代码:

for (IChange change : (List<IChange>) changeSet.changes()) {
                if (change.kind() == IChange.MODIFY) {
                    return "MODIFIED";
                }
                if (change.kind() == IChange.ADD) {
                    return "ADDED";
                }
            }