How to get relative path of an SCM file from a change set
![]()
All,
I am trying to write an Eclipse plugin that will be run against a Work Item which should contain Change Sets and also Links to our internal peer review software. The objective is to compare the files being delivered to a stream with the files which were peer reviewed and provide the approver with a report of the differences.
For this effort I start with the work item in the Eclipse Work Item editor and invoke the process with a menu item. From there, I pull the list of Change sets from the work item and loop through them with the following code (Thanks Ralph :) ). I extract the files to a temporary working area so that I can compare them with what was uploaded to the peer review software. Right now, the below code will extract all the files, but will not put them in the relative path the change set would show them in.
for (IReference iReference : references) {
if (iReference.isItemReference() ) {
Object resItem = iReference.resolve();
if (resItem instanceof IChangeSetHandle) {
IChangeSetHandle csHandle = (IChangeSetHandle) resItem;
IChangeSet cs = (IChangeSet) this.itemManager.fetchCompleteItem(csHandle, IItemManager.DEFAULT, null);
cs.getOriginalSourceId();
for (Object change : cs.changes()) {
IChange aChange = (IChange) change;
if (aChange.item() instanceof IFileItemHandle) {
IFileItemHandle fiHandle = (IFileItemHandle) aChange.afterState();
IFileItem fItem = (IFileItem) verManager.fetchCompleteState(fiHandle, null);
IFileContent fContent = fItem.getContent();
IFolderHandle foldHand = fItem.getParent();
IFolder fold = (IFolder) verManager.fetchCompleteState(foldHand, null);
System.out.println(fold);
System.out.println(fold.getOrigin());
System.out.println(fold.getParent());
File newFile = new File(destDir.getAbsolutePath() + '\\' + fItem.getName());
OutputStream out = new FileOutputStream(newFile);
vcm.retrieveContent(fItem, fContent, out, null);
out.close();
}
}
}
}
}
The above code gets an error on the fetchCompleteState for the Folder because it does not have a state. Obviously that isn't the right way to extract the relative path. Other examples I have pulled up show using the IConfiguration to get the history or use the Resolve Path method. My problem is that the IConfiguration seems to want a work space as a point of reference. As I am coming from a work item, I don't have a specific work space.
I know that when I am working in the Eclipse system and highlight all the changes sets and select Open that RTC aggregates all the change sets for me and normally provides a relative path in the change summary view. What work space does the system use for this, or is there some magical internal call that I don't know about they are using?
Alternatively, what approach would be the best for pulling the path of the files when I don't have a specific work space?
It may be that this is already answered and I just don't understand how the answer applies. If so, please let me know where and I will try to understand the answer better.
Thanks in advance for any advice and please ask questions if I have not provided enough information to make the question clear.
|
One answer
![]()
Geoffrey Clemm (30.1k●3●30●35)
| answered Dec 30 '14, 11:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
To get a pathname for a file/folder, you have to have a configuration (workspace, stream, baseline) context, because the pathname for a file/folder depends on what parent folder versions for that file/folder are selected by the configuration. When a link is created between a work item and a change set, some of the GUI's will store a property on that link that references the "current" workspace when that association was made, so you can try to see if that property exists, and if so, whether the referenced workspace still exists.
Comments Ok, I see where that fits into what I was seeing. Since I need a configuration for a workspace in order to get the relative file path, I started looking at how I could go about discovering where the change set lives. I was looking at the findWorkspacesContainingChangeset on the WorkspaceManager object, and passing in a wildcard so I could get a list of all the workspaces or streams that the changeset lived in. I would then write an algorithm to choose the best option. My problem now is that the method takes a good long while (> 60 seconds) to return and many times longer. Is there a better way to do that, or is there information somewhere in the change set, or component that could help me give more information in the search criteria and make that search faster? |
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.