以编程方式将存储库工作区组件加载到本地工作区
programmatically load repository workspace components into local workspace
我正在使用以下代码段以编程方式检索我的存储库工作区:
IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(teamRepository);
IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance();
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.WORKSPACES);
wsSearchCriteria.setExactOwnerName("ownerName"); //replaced with real parameter
List<IWorkspaceHandle> workspaceHandles = workspaceManager.findWorkspaces(wsSearchCriteria,Integer.MAX_VALUE, monitor);
//so, here i got my repWorkSpace:
IRepositoryWorkspace myDesiredRepositoryWorkspace = workspaceHandles.get(0);
我如何以编程方式fetch/load 组件从存储库工作区到我的 eclipse 工作区?
您可以通过此代码段获取您的组件:
List<IComponent> componentList = new ArrayList<IComponent>();
for(Object componentHandle: myDesiredRepositoryWorkspace.getComponents() ){
IItemHandle handle = (IItemHandle) componentHandle;
IItemManager itemManager = teamRepository.itemManager();
IComponent component = (IComponent) itemManager.fetchCompleteItem(handle, IItemManager.DEFAULT, monitor );
componentList.add(component);
}
在那之后我有了我的存储库工作区,我有了每个工作区的所有组件,但我无法将存储库工作区加载到本地工作区。
我正在开发一个 eclipse 插件,因此您需要以下插件(或直接从 plain-java-api 导入):
- com.ibm.team.rtc.common
- com.ibm.team.repository.client
- com.ibm.team.scm.client
- com.ibm.team.scm.common
- com.ibm.team.process.common
好的,加载与 ILoadRule2
一起工作,我找到了一种方法,但遗憾的是它涉及通过 xml 文件的绕过。它需要访问沙箱,但下面都有描述^_^
假设我们有工作区和组件(如问题中所述),我们可以使用以下代码片段加载工作区:
ISharingManager sharingManager = FileSystemCore.getSharingManager();
File workspaceRoot = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
PathLocation pathlocation = new PathLocation(workspaceRoot.getAbsolutePath());
ILocation sandBoxLocation = pathlocation.getCanonicalForm();
ISandbox sandbox = sharingManager.getSandbox(sandBoxLocation, false);
LoadDilemmaHandler p = LoadDilemmaHandler.getDefault();
monitor.subTask("searching for load rules file");
File f = LoadRuleUtility.createLoadRules(componentList);
InputStream ins = new FileInputStream(f);
Reader xmlReader = new InputStreamReader(ins);
ILoadRule2 rule = ILoadRuleFactory.loadRuleFactory.getLoadRule(con, xmlReader, monitor);
ILoadOperation loadoperator = rule.getLoadOp(sandbox, p, monitor);
monitor.subTask("loading files from RTC server...");
loadoperator.run(monitor);
好的,LoadRuleUtility.createLoadRules()
的神奇之处在于它创建了一个 xml 文件来描述工作区的组件。 (我正在使用 DOM)。
它必须看起来像这样:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<scm:sourceControlLoadRule eclipseProjectOptions="import" version="1" xmlns:scm="http://com.ibm.team.scm">
<!-- for each component in your repository workspace -->
<parentLoadRule>
<component name="component_name"/>
<parentFolder repositoryPath="/"/>
</parentLoadRule>
</scm:sourceControlLoadRule>
到卸载您只需删除它们的组件:
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for(IProject project: projects){
try {
project.delete(true, true, monitor);
} catch (CoreException e) {
e.printStackTrace();
}
}
我正在使用以下代码段以编程方式检索我的存储库工作区:
IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(teamRepository);
IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance();
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.WORKSPACES);
wsSearchCriteria.setExactOwnerName("ownerName"); //replaced with real parameter
List<IWorkspaceHandle> workspaceHandles = workspaceManager.findWorkspaces(wsSearchCriteria,Integer.MAX_VALUE, monitor);
//so, here i got my repWorkSpace:
IRepositoryWorkspace myDesiredRepositoryWorkspace = workspaceHandles.get(0);
我如何以编程方式fetch/load 组件从存储库工作区到我的 eclipse 工作区?
您可以通过此代码段获取您的组件:
List<IComponent> componentList = new ArrayList<IComponent>();
for(Object componentHandle: myDesiredRepositoryWorkspace.getComponents() ){
IItemHandle handle = (IItemHandle) componentHandle;
IItemManager itemManager = teamRepository.itemManager();
IComponent component = (IComponent) itemManager.fetchCompleteItem(handle, IItemManager.DEFAULT, monitor );
componentList.add(component);
}
在那之后我有了我的存储库工作区,我有了每个工作区的所有组件,但我无法将存储库工作区加载到本地工作区。
我正在开发一个 eclipse 插件,因此您需要以下插件(或直接从 plain-java-api 导入):
- com.ibm.team.rtc.common
- com.ibm.team.repository.client
- com.ibm.team.scm.client
- com.ibm.team.scm.common
- com.ibm.team.process.common
好的,加载与 ILoadRule2
一起工作,我找到了一种方法,但遗憾的是它涉及通过 xml 文件的绕过。它需要访问沙箱,但下面都有描述^_^
假设我们有工作区和组件(如问题中所述),我们可以使用以下代码片段加载工作区:
ISharingManager sharingManager = FileSystemCore.getSharingManager();
File workspaceRoot = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
PathLocation pathlocation = new PathLocation(workspaceRoot.getAbsolutePath());
ILocation sandBoxLocation = pathlocation.getCanonicalForm();
ISandbox sandbox = sharingManager.getSandbox(sandBoxLocation, false);
LoadDilemmaHandler p = LoadDilemmaHandler.getDefault();
monitor.subTask("searching for load rules file");
File f = LoadRuleUtility.createLoadRules(componentList);
InputStream ins = new FileInputStream(f);
Reader xmlReader = new InputStreamReader(ins);
ILoadRule2 rule = ILoadRuleFactory.loadRuleFactory.getLoadRule(con, xmlReader, monitor);
ILoadOperation loadoperator = rule.getLoadOp(sandbox, p, monitor);
monitor.subTask("loading files from RTC server...");
loadoperator.run(monitor);
好的,LoadRuleUtility.createLoadRules()
的神奇之处在于它创建了一个 xml 文件来描述工作区的组件。 (我正在使用 DOM)。
它必须看起来像这样:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<scm:sourceControlLoadRule eclipseProjectOptions="import" version="1" xmlns:scm="http://com.ibm.team.scm">
<!-- for each component in your repository workspace -->
<parentLoadRule>
<component name="component_name"/>
<parentFolder repositoryPath="/"/>
</parentLoadRule>
</scm:sourceControlLoadRule>
到卸载您只需删除它们的组件:
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for(IProject project: projects){
try {
project.delete(true, true, monitor);
} catch (CoreException e) {
e.printStackTrace();
}
}