It's all about the answers!

Ask a question

Find all baselines for a given stream


rougier philippe (1123) | asked Sep 16 '15, 10:17 a.m.
edited May 24 '16, 9:24 p.m. by David Lafreniere (4.8k7)
 Hi,

 I try to get list of baseline for one stream with the api client RTC.
 I have one component with two stream.

 First solution : 
IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance();
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);
wsSearchCriteria.setExactName("stream1");

List<IWorkspaceHandle> workspaceHandles = workspaceManager.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, monitor);
workspaceConnection = workspaceManager.getWorkspaceConnection(workspaceHandles.get(0), monitor);
IHistoricBaselineIterator ith = workspaceConnection.getBaselinesInHistory(composant, Integer.MAX_VALUE, monitor);

baselines.addAll(ith.getBaselines());
while (ith.hasPrevious()) {
  ith = ith.getPrevious(50, monitor);
  baselines.addAll(ith.getBaselines());
}
 
With this first solution, i don't retrieve all baseline and my list contains baseline from two stream.



Second solution : 

IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance();
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);
wsSearchCriteria.setExactName("stream1");
List<IWorkspaceHandle> workspaceHandles = workspaceManager.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, monitor);
IBaselineSetSearchCriteria crit = BaselineSetSearchCriteria.FACTORY.newInstance();
crit.setOwnerWorkspaceOptional(getWorkspaceHandle(workspaceHandles.get(0));

List<IBaselineHandle> baselines = new ArrayList<IBaselineHandle>();

List<IBaselineSetHandle> baselinesSet = workspaceManager.findBaselineSets(crit, Integer.MAX_VALUE, monitor);
IBaselineSet ibs;
for (IBaselineSetHandle iBaselineSetHandle : baselinesSet) {
ibs = (IBaselineSet) teamRepository.itemManager().fetchCompleteItem(iBaselineSetHandle, IItemManager.DEFAULT, monitor);
baselines.addAll(ibs.getBaselines());
}
 
this seems correct, but is this the best method ?
Why  the first solution does not work ?


Thanks.

Philippe

Accepted answer


permanent link
Chris McGee (50511117) | answered Oct 01 '15, 11:33 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
edited Oct 20 '15, 10:03 a.m.
Hi Philippe,

Before I go into more details I should elaborate on how baselines and baseline sets work. Baselines are associated with a single component. They are not owned by a single repository workspace/stream. They can be delivered/accepted much like change sets. The same baseline can be present in many different workspaces/streams where the component is added. I believe that the reason that you see the baselines from both stream 1 and stream 2 in your first solution is because the baseline is in fact present in both. You can verify this using the Eclipse client by selecting the component in the stream (in the team artifacts view), right-click and choose Show->Baselines. Try it on the component in both stream 1 and stream 2.

Baseline sets are actually called "snapshots" in the eclipse client and other places in the RTC UI, but retain an older name in the API. You can create a snapshot on a repository workspace or stream and it will create baselines in all of the components at that point in time. The snapshot has a list of all of the baselines that were created at the time the snapshot was created. In fact, the snapshot will often have the same name as all of the baselines created making it easy to confuse the two! Unlike baselines, snapshots are owned by one particular repository workspace/stream. You can move them around but they will only ever be present in one at a time. RTC builds will often create snapshots; this is how they allow you to compare two builds for source code changes; sometimes the snapshots are owned by the repository workspace (not the stream) in the build definition unless you configure it move the snapshots to the stream.

Now, if you want to get the baselines (not the snapshots) for a particular component in a stream then your solution 1 seems to be correct. It may in fact contain baselines that are also present in other streams as I mentioned above. However, if you are looking for snapshots owned by a stream then your solution 2 appears to be correct except that it adds all of the baselines (maybe from other components) into the "baselines" collection.

I hope that this is helpful,
Chris
David Lafreniere selected this answer as the correct answer

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.