gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:30:22 25 4
gpt4 key购买 nike

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

例如,如果有一个名为“test.txt”的文件,它位于:项目1-->文件夹1-->文件夹2-->test.txt

到目前为止,我已经设法搜索到了这个文件。现在我需要获取完整的目录并在我的电脑上创建一个类似的目录:结果在我的电脑上:文件夹1-->文件夹2-->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

提前致谢。

最佳答案

我有以下 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;

}

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

关于java - 获取更改集文件的完整路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14990572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com