It's all about the answers!

Ask a question

Get latest component baseline within Stream via RTC API

Marko Tomljenovic (31646109) | asked Aug 07 '15, 12:27 p.m.
edited May 25 '16, 11:23 p.m. by David Lafreniere (4.8k7)

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 =
                    new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN,

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

permanent link
David Lafreniere (4.8k7) | answered May 25 '16, 11:31 p.m.
edited Jun 12 '16, 5:47 p.m. by Geoffrey Clemm (30.1k33035)
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

permanent link
Stefano Antoniazzi (1701711) | answered May 24 '16, 9:11 a.m.
edited May 25 '16, 10:59 a.m.
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(
		numBasisInHistory , 
progressMonitor); for (IComponentInfo componentInfo : componentInfos) { IBaselineHandle baselineHandle = componentInfo.basis(); IBaseline baseline = (IBaseline) itemManager.fetchCompleteItem(baselineHandle, IItemManager.DEFAULT, progressMonitor); log.trace("Baseline UUID =>" + baseline.getItemId() + "<="); log.trace(" Baseline id =>" + baseline.getId() + "<="); log.trace(" Baseline name =>" + baseline.getName() + "<="); }

permanent link
Marko Tomljenovic (31646109) | answered Aug 07 '15, 3:23 p.m.
Found the solution by looking at the RTC plugin code in class BaselinesInWorkspaceQuery.


          // Get component for component handle
          IComponentHandle compHandle = (IComponentHandle) compObj;
          IItem item =
                  new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN,
          if (monitor.isCanceled()) {
            return Status.OK_STATUS;
          IComponent component = (IComponent) item;

          // Get current baseline of component in workspace
          ICurrentComponentInfo currCompInfo = wsConn.getComponentInfo(compHandle);
          long numBasisInHistory = currCompInfo.numBasisInHistory();
          List<IComponentInfo> componentInfos =
              wsConn.getComponentAuditTrail(compHandle, numBasisInHistory - 1, 1, new NullProgressMonitor());
          for (IComponentInfo compInfo : componentInfos) {
            ItemId<IBaseline> itemId = new ItemId<IBaseline>(compInfo.basis());
            IItemHandle baseLineHandle = itemId.toHandle();
            IItem itemBaseline =
                    new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN,
            if (monitor.isCanceled()) {
              return Status.OK_STATUS;
            IBaseline baseline = (IBaseline) itemBaseline;

PS. The API is really really NOT intuitive to use.

Your answer

Register or to post 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.