Get latest component baseline within Stream via RTC API
Marko Tomljenovic (316●50●109)
| asked Aug 07 '15, 12:27 p.m.
edited May 25 '16, 11:23 p.m. by David Lafreniere (4.8k●7)
Hi
I am using following code to retrieve the latest baseline of a component within a stream:
// Get baselines for component
IComponent component = (IComponent) item;
IHistoricBaselineIterator baselineIterator =
workspaceConn.getBaselinesInHistory(component, 1, new NullProgressMonitor());
List<? extends IBaselineHandle> baselines = baselineIterator.getBaselines();
for (IBaselineHandle iBaselineHandle : baselines) {
IItem itemBaseline =
this.repository.itemManager().fetchCompleteItem(
iBaselineHandle,
IItemManager.UNSHARED,
new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN,
SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
For some streams it works (I think) but I have a few streams where the resulting baseline is the overall newest baseline and not the newest baseline (is the "Initial baseline") in the stream context. (like it is shown in the Eclipse client UI in the Team Artifacts" view).
If this code is wrong can you point me to a source with the right piece of code?
Thank you
|
Accepted answer
David Lafreniere (4.8k●7)
| answered May 25 '16, 11:31 p.m.
FORUM MODERATOR / JAZZ DEVELOPER edited Jun 12 '16, 5:47 p.m. by Geoffrey Clemm (30.1k●3●30●35)
If you only want to get the latest baseline (i.e. the basis) of a component, then it's simply:
// Fetch a handle to the last baseline (basis) ITeamRepository repo = <repo_of_the_workspace> IWorkspaceManager manager = SCMPlatform.getWorkspaceManager(repo); IWorkspaceHandle workspaceHandle = <this_is_the_handle_for_the_stream> IWorkspaceConnection wc = manager.getWorkspaceConnection(workspaceHandle , monitor); IComponentHandle componentHandle = <this_is_the_component_you_care_about> IBaselineHandle basisHandle = wc.getComponentInfo(componentHandle ).basis(); // Fetch the full baseline IFetchResult fetchResult = repo.itemManager().fetchCompleteItemsPermissionAware(Collections.singletonList(basisHandle), ItemManager.DEFAULT, monitor); IBaseline fetchedBaseline; if (fetchResult.getRetrievedItems().size() == 1) { fetchedBaseline = fetchResult.getRetrievedItems().get(0); } Geoffrey Clemm selected this answer as the correct answer
|
2 other answers
Found the solution by looking at the RTC plugin code in class BaselinesInWorkspaceQuery.
Solution:
// Get component for component handle
PS. The API is really really NOT intuitive to use.
|
For getting all the baselines as seen from ui right clicking on the component of a specific repository workspace or stream(Show > Baselines) and getting IBaseline from IComponentInfo in a more concise way...:
currentComponentInfo = workspaceConnection.getComponentInfo(componentHandle); // the number of past basis long numBasisInHistory = currentComponentInfo.numBasisInHistory(); log.trace(" numBasisInHistory :" + numBasisInHistory); //BE CAREFUL: from oldest to newest... componentInfos = workspaceConnection.getComponentAuditTrail( componentHandle, 0, numBasisInHistory , |
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.