It's all about the answers!

Ask a question

How to download files from a specific baseline

vicky wang (131) | asked May 10 '17, 11:02 p.m.

Now we have the requirement that download all compoent files that included in a specific baseline,  if anyone know how to do it by java?

Accepted answer

permanent link
Ralph Schoon (56.8k23642) | answered May 11 '17, 2:09 a.m.

 The posts in this series show how to create repository workspaces, add components, rebase components. The blog post Getting your stuff – using the RTC SDK to zip a repository workspace explains how to download data.  

vicky wang selected this answer as the correct answer

One other answer

permanent link
vicky wang (131) | answered May 11 '17, 10:17 p.m.

Thanks Ralph, attached the code I used based on the code  from the website;

List<IWorkspaceHandle> workspaces = manager.findWorkspaces(criteria,Integer.MAX_VALUE, null);
IWorkspaceConnection workspace = manager.getWorkspaceConnection(workspaces.get(0), null);

List<IComponentHandle> components = workspace.getComponents();
IComponentHandle requiredComponent = null;
for(IComponentHandle component : components)
                IComponent tmp = (IComponent)repo.itemManager().fetchCompleteItem(component, IItemManager.DEFAULT, null);
                System.out.println("compoent:" + tmp.getName());
                requiredComponent = component;

IBaselineSearchCriteria  baselineQuery = IBaselineSearchCriteria.FACTORY.newInstance();
List<IBaselineHandle> baselines = manager.findBaselines(baselineQuery, Integer.MAX_VALUE, null);

IBaselineConnection baselineConn = manager.getBaselineConnection(baselines.get(0), null);
IConfiguration config = baselineConn.changeHistory().configuration();
IFolderHandle rootFolder = config.rootFolderHandle(null);

 Map<String,IVersionableHandle> kids = config.childEntries(rootFolder , null);
        for (java.util.Map.Entry<String, IVersionableHandle> folderEntry : kids.entrySet()) {
            path = path + "/" + folderEntry.getKey();
            IVersionableHandle child = folderEntry.getValue();
            if (child instanceof IFolderHandle) {
                printFolder(path, (IFolderHandle) child, config, monitor);
            } else if(item instanceof IFileItemHandle){
               IFileItem fileItem = (IFileItem)SCMPlatform.getWorkspaceManager(repo).versionableManager().fetchCompleteState(item, null);
IFileContent fileContent = fileItem.getContent();
File outputFile = new File(subIndent);
System.out.println("outputFile:" + outputFile);
OutputStream output = new FileOutputStream(outputFile.getAbsolutePath());
SCMPlatform.getContentManager(repo).retrieveContent(item, fileContent, output, null);

Your answer

Register or to post your answer.