Accessing File info from a ChangeSet/History Entry
Given a change set or a history entry, how can we retrieve it's corresponding version number, associated file (IFile) and predecessor file?
|
One answer
I figured out how to retrieve the associated file for a selected file version from a history entry. Listed below are the steps for the same -
1. Get a handle to the selected file version (or the IHistoryEntry item), lets call it "entry". 2. Get the Path of the file from the IHistoryEntry item - IPath path = new Path(entry.getTargetItem().getFQName()); 3. Get the File itself from the Resource Plugin and the Path obtained in step 2 - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); 4. Get the contents of the selected file version from the IHistoryEntry item - InputStream input = entry.getTargetItem().getContents(mon).getInputStream(); 5. Set the contents of the file with the inputStream obtained in Step 4 - file.setContents(input, true, true, mon)); (First check it the file exits, if it doesn't, then create the project/folder and file first) With this the file will now have the contents of the selected file version. Obtaining the predecessor files is also simple. One can do that by first getting the previous entry of the selected file version - prevEntry = entry.getPrevious(mon); and then following the same steps listed above to get the associated file version. Regards, Swathi |
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.