It's all about the answers!

Ask a question

How to read repository files from stream ?

Kivanc Ahat (1122) | asked Jul 13 '11, 4:20 a.m.
edited Oct 12 '17, 1:21 p.m. by David Lafreniere (4.8k7)

I am writing a client side plug-in for RTC and I have IPRoject in my hand.
My scenario is:
I have many streams in my project area. I want to get one of the streams, that contains "integration_stream" in name. Then in that stream I want to read pom.xml file in folder "x".

I have project area name in my hand and to read pom.xml, I think I need

1. get uuid of the stream in project area that has "integration_stream" in name
2. read X\pom.xml in repository files of the stream


Accepted answer

permanent link
Michael Valenta (3.7k3) | answered Jul 19 '11, 11:42 a.m.
When you say you have an IProject, do you mean that you have a project that is shared with an RTC server. Is there a relationship between this IProject and folder X that contains the file, pom.xml, that you are interested in?

I ask because you do not have everything that is needed to find the file in the repository. You have a project area and a stream (assuming the stream name is unique) but what is missing is the component (i.e. a stream is a collection of components that then contain files and folders). What's also not a given is whether folder X is a top level folder in the target component.

Here is a code snippet that illustrates how you could get at the file assuming that you already had the component. I haven;t tried this out myself so there may be typos etc. but it should give you the general idea.

ITeamRepository repo = ???;
String namePattern = "integration_stream";
IAuditableHandle projectArea = ???;
IComponentHandle component = ???;

IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(repo);

IWorkspaceSearchCriteria wcrit = IWorkspaceSearchCriteria.FACTORY.newInstance();

List<IWorkspaceHandle> workspaces = wm.findWorkspaces(wcrit, 10, monitor);
if (!workspaces.size() ==1) {
// Unexpected condition. throw exception?

IWorkspaceHandle handle= workspaces.get(0);
IWorkspaceConnection ws = wm.getWorkspaceConnection(handle, monitor);
IConfiguration config = ws.configuration(component);
IVersionable Handle file = config.resolvePath(config.rootFolderHandle(monitor), new String[] { "X", "pom.xml" }, monitor);
David Lafreniere selected this answer as the correct answer

Your answer

Register or to post your answer.