How to get the file path of a changed file in RTC with JAVA?
Hello everyone,
public void getConnectedFiles(IWorkspaceManager workspaceManager, IWorkItemClient workItemClient, ILinkManager linkManager, IItemManager itemManager, int workItemID){ try{ IWorkItem workItem = workItemClient.findWorkItemById(workItemID, IWorkItem.FULL_PROFILE, new SysoutProgressMonitor()); logInfo("[" + workItem.getId() + "] " + workItem.getHTMLSummary().getPlainText()); // Find all of the change sets using the link manager to find a // special kind of // link that crosses between work items and source control change // sets using its ID. IItemReference workItemReference = linkManager.referenceFactory().createReferenceToItem(workItem); ILinkCollection linkCollection = linkManager .findLinksByTarget(ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID, workItemReference, new SysoutProgressMonitor()) .getAllLinksFromHereOn(); logInfo("LinkCollection received ...");
logInfo("Work item has no change sets."); } else {
List<IChangeSetHandle> changeSetHandles = new ArrayList<IChangeSetHandle>();
// Change set links should be item references IChangeSetHandle changeSetHandle = (IChangeSetHandle) link.getSourceRef().resolve(); changeSetHandles.add(changeSetHandle);
List<IChangeSet> changeSets = itemManager.fetchCompleteItems(changeSetHandles, IItemManager.DEFAULT, new SysoutProgressMonitor()); Set<String> changedFilesAndFolders = new TreeSet<String>(); // Set<String> changedFilesAndFoldersPath = new TreeSet<String>(); for (IChangeSet cs : changeSets) { for (Object o : cs.changes()) { IChange change = (IChange) o;
IVersionableHandle after = change.afterState();
// handles, you cannot use the item // manager to fetch the versionable from the // handle. Instead, you use the // versionable manager to do this. IVersionable afterVersionable = workspaceManager.versionableManager() .fetchCompleteState(after, new SysoutProgressMonitor());
changedFilesAndFolders.add(afterVersionable.getName()); // changedFilesAndFoldersPath.add(afterVersionable.getParent().toString());
|
Accepted answer
String filePath = ""; for (IWorkspaceHandle wHandle : wHandles) { IWorkspace workspace = (IWorkspace) repo.itemManager().fetchCompleteItem(wHandle, IItemManager.DEFAULT, null); IWorkspaceConnection wsConn = wm.getWorkspaceConnection(workspace, null); // previously I had retrieved the component associated to the versionable IComponent component = rawFilesHash.get(versionableHandle); IConfiguration configuration = wsConn.configuration(component); List<IVersionableHandle> versionableHandleList = new ArrayList<IVersionableHandle>(); versionableHandleList.add(versionableHandle); List<?> ancestorReports = configuration.locateAncestors(versionableHandleList, monitor); IAncestorReport iAncestorReport = (IAncestorReport) ancestorReports.get(0); List<INameItemPair> reportList = iAncestorReport.getNameItemPairs(); for (INameItemPair iNameItemPair : reportList){ String temp = iNameItemPair.getName(); if (temp != null) { filePath += "/" + temp ; } } if (!filePath.isEmpty()) { break; } } Benjamin Maier selected this answer as the correct answer
Comments
Benjamin Maier
commented Mar 06 '17, 5:30 a.m.
Hi Luca,
This means the file does not exist in that stream/component.
Luca Martinucci
commented Mar 07 '17, 5:21 a.m.
Yes, actually, in my code snippet, I am cycling over the list of workspaces in the Project Area.
Benjamin Maier
commented Mar 14 '17, 4:15 a.m.
Luca, please see my other answer on how to solve this problem more easily.
|
4 other answers
Benjamin Maier (33●3●9)
| answered Mar 14 '17, 4:14 a.m.
edited Mar 14 '17, 8:49 a.m. by Ralph Schoon (63.4k●3●36●46) Hello,
public static String pathFinder(ITeamRepository repo, IWorkspaceManager wm, IChangeSet cs, IVersionableHandle vh) throws TeamRepositoryException { String filePath = ""; IWorkspaceConnection wsc = workspaceConnectionFinder(repo, wm, cs); IComponentHandle component = cs.getComponent(); IConfiguration config = wsc.configuration(component); List<iversionablehandle> versionableHandleList = new ArrayList<iversionablehandle>(); |
Luca Martinucci (1.0k●3●97●112)
| answered Feb 27 '17, 10:59 a.m.
edited Mar 14 '17, 8:51 a.m. by Ralph Schoon (63.4k●3●36●46) Hi Benjamin,
List changes = (List)changeSet.changes(); for (Iterator changesIterator = changes.iterator(); changesIterator.hasNext();) { boolean modifiedElement = false; boolean addedElement = false; boolean deletedElement = false; IChange change = (IChange)changesIterator.next(); IVersionableHandle changeObj = null; Integer changeKind = change.kind(); Comments
Ralph Schoon
commented Feb 27 '17, 11:10 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Thanks for sharing Luca!
Benjamin Maier
commented Feb 28 '17, 5:21 a.m.
Hi Luca,
To get the ISCMService see https://rsjazz.wordpress.com/2016/02/04/setting-custom-attributes-for-scm-versionables/ Getting the IScmService
Most of the API should work on clients and Luca already hinted you to what is needed.
|
Ralph Schoon (63.4k●3●36●46)
| answered Feb 14 '17, 5:15 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER As far as I know, the path information RTC stores in SCM is only relative to the component. It is impossible to get an absolute path, unless the file is loaded onto disc somewhere.
Getting your stuff – using the RTC SDK to zip a repository workspace and Committing content to RTC SCM with the SDK show basic operations related to this. Extracting an Archive Into Jazz SCM Using the Plain Java Client Libraries is an example I created.
Comments
Benjamin Maier
commented Feb 20 '17, 6:55 a.m.
Hi Ralph,
Ralph Schoon
commented Feb 20 '17, 8:01 a.m.
| edited Feb 20 '17, 8:03 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Since there is few information in what context and why you want to do all this, there is almost nothing one can answer. This is a call you might or might not be able to use. com.ibm.team.scm.common.IScmService.getComponentsContainingVersionable(IWorkspaceHandle, IVersionableHandle, ISynchronizationTimes[], IRepositoryProgressMonitorHandle)
How to get the IScmService is in my blog. And I am aware of the fact that it is really hard to find stuff in the API
Benjamin Maier
commented Feb 27 '17, 5:10 a.m.
Hi Ralph,
|
Benjamin,
|
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.
Comments
If you work with client-side API, once you have retrieved the versionable, you need a workspace to resolve the file path.
Then, you retrieve the component associated to the versionable and can calculate the file path.
See the code snippet in my second answer.
Benjamin, did you manage to achieve your scope?
If so, please accept my answer, so other people can leverage it.