It's all about the answers!

Ask a question

How to fetch a file path from given changeset?


Nandan Kumar Hunjunal Parameshaiah (111) | asked Mar 01 '19, 9:59 a.m.
Hello,

I am trying to fetch a filepath of a fileItem present in the changeset.

But i dont want to use workspaceConnection to get the file path instead without using the workspaceConnection.

So can you please give some ways to fetch the file path without using WorkSpaceConnection?

Thanks.

One answer



permanent link
David Lafreniere (4.8k7) | answered Mar 01 '19, 3:18 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
edited Mar 01 '19, 3:44 p.m.
You will not be able to retrieve a path given a versionable on its own. A file has a pointer to the parent folder (where the pointer is just an itemId or handle), but the name of that parent folder (along with the full path right up to the component root) can only be determined with a context/configuration (ex: a stream, workspace or baseline).

See: IConfiguration.locateAncestors(...)


For example, 'fileA.txt' may be located at '/dirA/dirA2/fileA.txt' in StreamA, and '/dirB/dirB2/dirB3/fileA.txt' in StreamB


There are plenty of similar questions on this forum, I'm surprised you didn't find the answer on one of them.


Comments
Nandan Kumar Hunjunal Parameshaiah commented Mar 02 '19, 5:42 a.m.
Hello David,

Thanks for the  hints.

I have gone through many pages about this in this forum. I tried 2 ways:
1. Using WorkspaceConnection :
    Here i created a new workspaceConnection and tried to fetch the path but didnt give any info about the path as the workspace that i had created had no baselines compare to the original one i had used for my operation.
 So can you please suggest me to create a worspaceconnection in this case?

2. Using Stream:
    I couldn't fetch a Stream information from the changeset.  Is there a way?

Many thanks.


David Lafreniere commented Mar 04 '19, 4:11 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

Nandan Kumar Hunjunal Parameshaiah commented Mar 05 '19, 4:25 a.m.
Thanks David.

The below method from Benjamin Maier helped me in workspaceConnection problem that i was facing

public static IWorkspaceConnection workspaceConnectionFinder(ITeamRepository repo, IWorkspaceManager wm, IChangeSet cs)

        throws TeamRepositoryException {
    IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance();
    wsSearchCriteria.setKind(IWorkspaceSearchCriteria.ALL);
    List<IWorkspaceHandle> workspaceHandles = wm.findWorkspacesContainingChangeset(cs, wsSearchCriteria,
            Integer.MAX_VALUE, new SysoutProgressMonitor());
    IWorkspaceConnection wsc = wm.getWorkspaceConnection(workspaceHandles.get(0), new SysoutProgressMonitor());
    return wsc;
}
    

David Lafreniere commented Mar 05 '19, 10:42 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
Can I make a suggestion... if you are running RTC 6.0.4 or later, you might want to use the code shown below, BEFORE running the code snippet that you have.. with this code you have a better chance at getting a more accurate stream (if there was a code review created on the work item.)

Use:
ICodeReviewClient codeReviewClientAPI = (ICodeReviewClient) repo.getClientLibrary(ICodeReviewClient.class);

IWorkspaceHandle targetStream = codeReviewClientAPI.getTargetStream(workItem, loopProgress.newChild(1));
if (currentTargetStream != null) {
   IWorkspaceManager wsManager = SCMPlatform.getWorkspaceManager(repo);
   IWorkspaceConnection wc = wsManager.getWorkspaceConnection(targetStream, monitor);
return wc;
} else {
// call: workspaceConnectionFinder();
}

David Lafreniere commented Mar 05 '19, 10:43 a.m.
FORUM MODERATOR / JAZZ DEVELOPER

Also, just be aware that it's possible to NOT find a stream or workspace that contains a given change set (ex: the containing workspaces/streams were deleted)... so make sure to always null guard.


Nandan Kumar Hunjunal Parameshaiah commented Mar 06 '19, 5:41 a.m.
Hello David,

The above solution doesn't help me as i am not dealing with workitem :(

In my case I select a Stream and then fetch Baselines(2 or more) to get the changes in the files for further process and here i wanted the file path.

But unfortunately, I am not getting how to get the stream from a baseline or changeset. Is there any way? Please help me in finding out the stream from baselines or changesets.



Nandan Kumar Hunjunal Parameshaiah commented Mar 06 '19, 5:51 a.m.
Hello David,

The above solution doesn't help me as i am not dealing with workitem :(

In my case I select a Stream and then fetch Baselines(2 or more) to get the changes in the files for further process and here i wanted the file path.

But unfortunately, I am not getting how to get the stream from a baseline or changeset. Is there any way? Please help me in finding out the stream from baselines or changesets.



Nandan Kumar Hunjunal Parameshaiah commented Mar 06 '19, 6:16 a.m.
I have one small concern in the solution from Benjamin Maier in: https://jazz.net/forum/questions/235177/how-to-get-the-file-path-of-a-changed-file-in-rtc-with-java.

Here in my case I wont be having my own workspace created instead I will be accessing someone else workspace. So is there any other way to get the workspace connection?

I tried creating a new workspace connection object but it didn't have the component information and also baselines information and see more deprecated methods if i start creating the components in the workspace.  Will that work for me if I create my own workspace for the use case where i m concerned about the baselines changes of a Stream ?

Thanks.

David Lafreniere commented Mar 06 '19, 11:32 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
Q:"But unfortunately, I am not getting how to get the stream from a baseline or changeset. Is there any way? Please help me in finding out the stream from baselines or changesets."
A: There is no link between a change set and a stream or baseline. A change set may exist in 0, 1, or many streams or baselines. You would have to use some API to find it.

You will need an IConfiguration to get the path. An IWorkspaceConnection (ex: a stream) and an IBaselineConnection both extend IConfiguration.
IConfiguration.locateAncestors(...) is the API to give you the file path.


In the code example you wrote above, instead of finding repository workspaces that contain the change set you could find only streams by using this line:
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS); // STREAMS instead of ALL

    


David Lafreniere commented Mar 06 '19, 11:37 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
Given a stream handle you can use:
IWorkspaceConnection wc = wsManager.getWorkspaceConnection(streamHandle, monitor);

Given a baseline handle you can use:
IBaselineConnection bc = wsManager.getBaselineConnection(baselineHandle, monitor);

The code you wrote in a previous comment will find the streams which have the change set.

Given a set of change sets, you can find out which set of IBaselineHandles have those change sets using IWorkspacemanager.locateChangeSets(ILocateChangeSetsSearchCriteria scope, IProgressMonitor monitor) // Note: This API also lets you search in workspaces/streams/snapshots



Nandan Kumar Hunjunal Parameshaiah commented Mar 08 '19, 8:42 a.m.
Thanks David for the hint of  using IWorkspaceSearchCriteria.STREAMS

So finally I am only searching the changeset in the Streams instead of repository workspaces. :-)
showing 5 of 11 show 6 more comments

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.