获取更改集的文件的完整路径

时间:2013-02-20 21:47:36

标签: java rtc jazz

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

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

直到现在我已设法搜索此文件。 现在我需要获取完整目录并在我的电脑上创建类似的目录: 在我的电脑上的结果: 文件夹1 - > 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 赢:XP

提前致谢。

1 个答案:

答案 0 :(得分: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; 

} 

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