3

我正在搜索位于变更集的 .txt 文件。然后我需要在我的电脑上本地创建这个文件的完整路径目录。

例如,如果有一个名为“test.txt”的文件位于:Project1-->Folder1-->Folder2-->test.txt

直到现在我已经设法搜索到这个文件。现在我需要获取完整目录并在我的电脑上创建类似的目录:我的电脑上的结果:Folder1-->Folder2-->test.txt

这就是我在变更集中搜索文件并检索它的方法:

public IFileItem getTextFileFile(IChangeSet changeSet, ITeamRepository repository) throws TeamRepositoryException{
    IVersionableManager vm = SCMPlatform.getWorkspaceManager(repository).versionableManager();
    List changes = changeSet.changes();
    IFileItem toReturn = null;
    for(int i=0;i<changes.size();i++) {="" <br="">             Change change = (Change) changes.get(i);
        IVersionableHandle after = change.afterState();
        if( after != null && after instanceof IFileItemHandle) {
            IFileItem fileItem = (IFileItem) vm.fetchCompleteState(after, null);
            if(fileItem.getName().contains(".txt")) {
                   toReturn = fileItem;
                   break;
            } else {
               continue;
            }
        }
    }
    if(toReturn == null){
        throw new TeamRepositoryException("Could not find the file");
    }
    return toReturn;
}

我使用 RTC:4 Win:XP

提前致谢。

4

1 回答 1

2

我有以下通过以下内容获取的 IConfiguration:

IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(repository); 

IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance(); 


wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS); 


wsSearchCriteria.setPartialOwnerNameIgnoreCase(projectAreaName); 


List <iworkspacehandle> workspaceHandles = workspaceManager.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, Application.getMonitor());  

IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(workspaceHandles.get(0),Application.getMonitor()); 

IComponentHandle component = changeSet.getComponent(); 


IConfiguration configuration = workspaceConnection.configuration(component); 

List lst = new ArrayList<string>(); 

lst=configuration.locateAncestors(lst,Application.getMonitor()); 

==========================================

现在要获取文件项的完整路径,我使用了以下方法:

https://jazz.net/forum/questions/94927/how-do-i-find-moved-from-location-for-a-movedreparented-item-using-rtc-4-java-api

==========================================

private String getFullPath(List ancestor, ITeamRepository repository) 

throws TeamRepositoryException { 

String directoryPath = ""; 


for (Object ancestorObj : ancestor) { 


IAncestorReport ancestorImpl = (IAncestorReport) ancestorObj; 


for (Object nameItemPairObj : ancestorImpl.getNameItemPairs()) { 


NameItemPairImpl nameItemPair = (NameItemPairImpl) nameItemPairObj; 


Object item = SCMPlatform.getWorkspaceManager(repository) 

.versionableManager() 

.fetchCompleteState(nameItemPair.getItem(), null); 


String pathName = ""; 


if (item instanceof IFolder) { 

pathName = ((IFolder) item).getName(); 

} 


else if (item instanceof IFileItem) { 

pathName = ((IFileItem) item).getName(); 

} 


if (!pathName.equals("")) 

directoryPath = directoryPath + "\\" + pathName; 

} 

} 

return directoryPath; 

} 

==========================================

于 2013-02-22T22:28:50.193 回答