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
4 other answers
![]()
Benjamin Maier (33●1●9)
| answered Mar 14 '17, 4:14 a.m.
edited Mar 14 '17, 8:49 a.m. by Ralph Schoon (62.3k●3●36●43) 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●2●91●110)
| answered Feb 27 '17, 10:59 a.m.
edited Mar 14 '17, 8:51 a.m. by Ralph Schoon (62.3k●3●36●43) 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 ![]() FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Thanks for sharing Luca! 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 (62.3k●3●36●43)
| 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 Hi Ralph,
![]() 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
Hi Ralph,
|
![]() Benjamin,
|
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.