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

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 和 Windows XP。
提前感谢。

那么......正如Tim Mok在https://jazz.net/forum/questions/103355/java-get-the-full-path-of-a-file-at-change-set中问你的那样,你仍然不愿意“在这里提供尝试失败的原因”吗?没有错误信息?没有任何东西吗?(更不用说RTC、Java、操作系统的版本等基础知识了:这些也可以帮助我们帮助你) - VonC
这是带有Win.XP的RTC 4。 - Echo
抱歉,我一直在寻找能帮助像我这样的新手进入RTC的任何东西。我已经在那里更新了我的问题。 - Echo
有任何提示可以使用吗! - Echo
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; 

} 

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


1
感谢VonC的帮助。如果您有任何可以帮助我使用RTC-SDK的材料,请分享。 - Echo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接