以编程方式将存储库工作区组件加载到本地工

时间:2016-02-08 11:56:15

标签: java rtc

我正在使用此代码段重新检索我的存储库工作区以编程方式

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);

我如何以编程方式从存储库工作区中获取/加载组件到我的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

1 个答案:

答案 0 :(得分:0)

好的,加载适用于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();
    }
}